Skip to content

💡 Background color on text (glyph cells only) #76

@natemoo-re

Description

@natemoo-re

Is your feature request related to a problem?

We can already put a background behind text by wrapping it in open({ bg }), but that paints the element's whole rectangle, not the text. For a highlighted word, a colored label, or a status chip, what we actually want is a background that hugs the glyph cells. The box approach forces a layout node per styled run and, for anything that isn't a single full-width line, colors the wrong region.

Describe the solution you'd like

A text-level bg that colors only the cells the glyphs occupy, mirroring the CSS background-color property:

text("Saved", { bg: rgba(0, 128, 0) });

Why not just wrap in open({ bg })? For a single full-width line the two are equivalent, so this is partly ergonomics. But there are cases the box genuinely can't express:

  • Ragged multi-line text. A box bg fills the full bounding rectangle; a text bg hugs each line's actual glyphs, leaving short lines' trailing cells uncolored—which is how a highlighted, wrapped paragraph should look.
  • Inline highlights. Tinting a substring mid-line (a matched search term, one token in a sentence) would need a separate box per run, and there's no inline text flow to lay those out, so it breaks wrapping.
  • Element bloat. Syntax-highlighted or richly-styled output becomes one layout node per run.

Describe alternatives you've considered

open({ bg }) per run is the workaround today. It's fine for a whole, single-line block, but bloats the tree and can't do the ragged multi-line or inline-substring cases above.

Additional context

Failing test case on nm/repro/text-background (test · diff). text() has no bg today and render_text (src/clayterm.c:269) hardcodes the glyph-cell background to the terminal default; the change is roughly one ARGB word on the text op threaded into the glyph setcell.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions