Skip to content

Paint radial gradients, and fade a gradient into the terminal's background - #201

Merged
brainkim merged 4 commits into
mainfrom
feat/gradients
Nov 24, 2026
Merged

brainkim merged 4 commits into
mainfrom
feat/gradients

Conversation

@brainkim

Copy link
Copy Markdown
Member

Three gradient changes asked for from dim, whose intro screen draws a glow.

A fade to transparent blends instead of cutting

linear-gradient(to bottom left, #a88400, transparent) over a box with no background of its own drew a hard staircase: each cell took the gradient's color at half opacity or more and nothing below that. A flat translucent background-color already blended with the terminal's reported background; the gradient path did not.

A gradient cell that is not opaque now carries its alpha, and the cell it lands on blends it as it does any translucent fill: with what is already painted there (the element's own background-color, or an ancestor's), or with the background the terminal reported. The under argument to renderGradient is gone, since the cell knows what is under it better than the element's style does.

A terminal that reports no background still gets the half-opacity cut. There is nothing to blend with.

Canvas resolves to the terminal's background

  • As a gradient stop, Canvas (and the other system colors that stand for the terminal's background) is the reported color. Where none was reported it is a transparent stop, which leaves the cell to the terminal. Before, it made the whole gradient invalid.
  • getComputedStyle() reads those colors as the reported background. It read black or white by the color scheme, and still does until the terminal answers. CanvasText is unchanged: the terminal's text color is not asked for.

radial-gradient() and repeating-radial-gradient()

The shape (circle, ellipse), the size (the four extent keywords, a circle's radius, an ellipse's two radii) and the center (at, in the one- and two-value forms of <position>) parse as css-images-3 §3.2 writes them. A row counts for as many columns as a cell is taller than wide, as it does for a linear gradient's angle, so a circle is round on the screen.

Not read: the three- and four-value forms of <position> (at left 2ch top 1px), which make the gradient invalid, and conic-gradient().

parseLinearGradient is renamed parseGradient. It is internal.

Tests

tests/gradients.test.ts gains 14 tests: the fade against a reported background, against none, and against an ancestor's fill; Canvas as a stop and as a computed value; the radial grammar and what it rejects; and painted radial gradients (symmetry, roundness on 1:2 cells, an ellipse sized to its sides, an off-center circle, repeating rings, a glow fading into the terminal's background). The styling guide and examples/gradients.ts cover the new functions.

The full suite passes on Node. On Bun one run failed a test in tests/memory.test.ts, which then passed three times alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig

brainkim and others added 3 commits November 24, 2026 10:11
…round

A gradient cell that is not opaque now carries its alpha to the cell it
lands on, which blends it with what is already there or with the
background the terminal reported. Before, a gradient over nothing took
its own color at half opacity or more and painted nothing below that,
which drew a fade to transparent as a hard edge.

Canvas and the other system colors that stand for the terminal's
background are stops: the reported color, or no paint where the terminal
has reported none. getComputedStyle() reads them as the reported color
too.

radial-gradient() and repeating-radial-gradient() read their shape, size
and center as css-images-3 writes them, and a circle is round on the
screen whatever shape the cells are.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
@brainkim
brainkim merged commit 24d6601 into main Nov 24, 2026
10 checks passed
@brainkim
brainkim deleted the feat/gradients branch November 24, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant