diff --git a/CLAUDE.md b/CLAUDE.md index 8e95285..e528a72 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -187,7 +187,11 @@ branch on the platform per frame, and never `from meshterm.platforms import PLAT (the promotion is the point, only `title.muted`), never silent. Rich merges a row's base style into every span, so a silent one changes colour inside a selected row. Same trap outside the theme: `MapCanvas` drops emphasis entirely where bold is brightness, - since its colours arrive quantized and it can't know which bank they landed in. + since its colours arrive quantized and it can't know which bank they landed in, and the + fold's quantizer (`theme._nearest_slot_sgr`) states intent for it — a dim slot leaves as + `22;3N`, never a bare `3N`, because `9N` is *how* the console spells bright and adjacent + art spans (the wordmark's bevels, a raster's neighbouring cells) reset nothing between + them, so a bare one inherits the intensity bit and lands a bank too high mid-row. - On picocalc, the node hue and the heat gradient **quantize** — same rule, coarser resolution: `node_style` snaps the key's hue to its sixth of the wheel (`theme._NODE_SLOT_HEXES`, the six chromatic bright slots) and heat to the `heat.*` diff --git a/meshterm/ui/theme.py b/meshterm/ui/theme.py index da8b55e..07176ba 100644 --- a/meshterm/ui/theme.py +++ b/meshterm/ui/theme.py @@ -664,6 +664,15 @@ def _nearest_slot_sgr(background: bool, r: int, g: int, b: int) -> str: Foregrounds may land on any slot (30–37 / 90–97); backgrounds only on 0–7 (the VT has no bright backgrounds), so a bright colour used as a fill picks its dim-bank cousin. + + A **dim-bank foreground states its intent** (``22;3N``, normal intensity) rather than + emitting a bare ``3N``. Bold is brightness on the VT, and ``9N`` *is* how the console + spells bright — so a bare ``31`` immediately after a ``90`` inherits the intensity bit + and silently renders as ``91``. Quantized art is a run of adjacent colour spans with + no style boundaries to reset between them (the wordmark's every-other-span slate + bevel; a map raster's neighbouring cells), so the promotion lands mid-row and colours + half a row wrong: the narrow wordmark's fourth row — its only dim-slot row — came out + part red, part light red, split at each span that happened to follow the bevel. """ key = (background, r, g, b) cached = _SLOT_CACHE.get(key) @@ -678,10 +687,12 @@ def _nearest_slot_sgr(background: bool, r: int, g: int, b: int) -> str: ), ) if background: - code = 40 + slot + sgr = f"\x1b[{40 + slot}m" + elif slot < 8: + sgr = f"\x1b[22;{30 + slot}m" else: - code = 30 + slot if slot < 8 else 90 + slot - 8 - cached = _SLOT_CACHE[key] = f"\x1b[{code}m" + sgr = f"\x1b[{90 + slot - 8}m" + cached = _SLOT_CACHE[key] = sgr return cached diff --git a/tests/test_theme16.py b/tests/test_theme16.py index b0ef24e..b0e78cb 100644 --- a/tests/test_theme16.py +++ b/tests/test_theme16.py @@ -200,7 +200,8 @@ def test_fold_quantizes_embedded_truecolor_to_the_slots() -> None: set_platform(PICOCALC) folded = fold_text("\x1b[38;2;148;163;184m○\x1b[0m") assert "38;2;" not in folded - assert "\x1b[37m" in folded # #94a3b8 → nearest stock slot is 7 (#aaaaaa) + # #94a3b8 → nearest stock slot is 7 (#aaaaaa); a dim-bank slot states its intensity. + assert "\x1b[22;37m" in folded background = fold_text("\x1b[48;2;94;234;212mX\x1b[0m") assert "48;2;" not in background assert re.search(r"\x1b\[4[0-7]m", background), background # bg clamps to the dim bank @@ -312,7 +313,9 @@ def test_canvas_drops_emphasis_where_bold_means_brightness() -> None: canvas.marker(0, 0, "x", (148, 163, 184)) # markers always draw emboldened rendered = "".join(canvas.to_ansi_lines()) assert ("\x1b[1m" in rendered) is expect_bold, (platform.name, repr(rendered)) - assert "\x1b[37m" in rendered # and the colour it was given survives intact + # And the colour it was given survives intact — a dim-bank slot with its intensity + # stated, so the span can't inherit brightness from the raster cell before it. + assert "\x1b[22;37m" in rendered # -- the font build script stays mirrored --------------------------------------------- @@ -372,6 +375,29 @@ def test_specimen_renders_clean_on_picocalc() -> None: assert ord(ch) in FONT_CODEPOINTS, f"line {i} char {ch!r} outside the font" +def test_narrow_wordmark_keeps_its_dim_row_off_the_bright_bank() -> None: + """Every span of the wordmark's dim-slot row states its intensity. + + The mark alternates letter blocks with slate bevels, so a row painted on the dim bank + is a run of ``3N`` spans each following a ``90``. Bare, they inherit the console's + intensity bit and half the row renders a bank too bright — the narrow mark's fourth + row came out part red (slot 1), part light red (slot 9), split at every span that + followed a bevel. + """ + from meshterm.ui.logo import load_logo + from meshterm.ui.tui.frame import _banner_lines + + set_platform(PICOCALC) + rows = _banner_lines(load_logo(53), 53) + assert rows, "the 53-column mark should fit a 53-column console" + for i, row in enumerate(rows): + for sgr in re.findall(r"\x1b\[([0-9;]*)m", row): + assert not re.fullmatch(r"3[0-7]", sgr), f"bare dim-bank SGR on row {i}: {row!r}" + # The fourth row is the mark's only dim-slot row, and it is one colour throughout. + reds = set(re.findall(r"\x1b\[([0-9;]+)m(?=█)", rows[3])) + assert reds == {"22;31"}, reds + + # -- relocated marks stay importable from their old homes -----------------------------