Phosphor Gets Polished: Live Widths, Themes That Answer, and the CP437 Wire
November 13, 2026
One board, one GUI session — and a long tail of small paper cuts. This post is a factual walkthrough of a single day of Phosphor TUI work: what changed, why each change happened, and what it buys. Four commits shipped to production today (b5748ec9, 27d4d3ba, 404fa60 in the jterm library, 8d372b11 on the server), every one deployed behind a zero-active-session gate, and every one pinned so it can’t quietly regress.
First, the frame
Phosphor’s web and door screens are painted by a declarative layout system (.phos scripts rendered by the jterm screen stack). The big layout-tier arc — the label/graphic/statusbar/tab system that the doors and screens now share — landed earlier; today was hardening under real usage: a crash found live, a justification bug users could see, a preferences dead spot users could feel, and an end-to-end harness that kept lying to us until we learned what the wire actually says.
Doors now justify across the terminal you actually have
What was wrong. The blackjack door’s statusbar hint — [D]eal [H]it [S]tand [Q]uit — hugged the right edge of the screen, even on narrow terminals. Not a style choice: the statusbar renderer has exactly one centered segment mechanism, and the hint was parked in a side segment. Worse, the justification width wasn’t the terminal’s at all — content sources fell back to a hardcoded 80 columns, so a door’s layout was justified to an imaginary 80-wide screen regardless of what you actually had open.
What changed. Door feeds now declare their width as the live terminal columns: the door content source overrides width() with the current size (clamped 1..256, junk-safe — a detached or half-open door keeps the old default instead of lying), and the render cycle refreshes that width on every draw, re-rendering only when it drifts. On resize, the door re-justifies on the next paint — no reconnect, no stale layout. The hint moved into the proper center segment, so it lands dead-center at 80 columns and stays centered at any width; the right segment’s content now sits flush-right on every display.
The value: every Phosphor door — not just blackjack — inherits live-width justification, and the law that pins it (statusbarJustifiesAcrossLiveDoorColumns, exact 25/25 padding at a fixed feed) makes “justified to 80 forever” a compile-to-RED condition rather than a someday-bug.
The crash only production could find: null colors in the SGR pass
What was wrong. The first live end-to-end loop against a real door surfaced NullPointerException in jterm’s SGR diff tracker. Root cause: the screen layer treats new Label(text, fg, null) as API-legal — a null background means “transparent” — and the diff tracker unconditionally dereferenced both colors. Every headless test buffer was perfectly happy; the live render path was not. Styled unit labels in the doors constructed exactly such labels whenever the theme didn’t carry an explicit background.
What changed. Two layers, deliberately:
- Library (jterm
404fa60):SgrStateTracker.transitionTonow skips null fg/bg rather than throwing — a null color is a legitimate state, not a defect. - Server (
b5748ec9): unit-label producers carry the theme’s explicit background instead of relying on the null shorthand, because a transparent cell in that spot means “whatever the last painted color was” during partial repaints.
The value: the distinction stayed — Label(..., null) remains legal, useful API — while the live SGR diff pass can no longer NPE on it. Both behavior changes are pinned (16/16 in SgrStateTrackerTest, theme-background laws in the door suites).
The theme picker that did nothing — and why it looked fine
What was wrong. In Preferences, the theme row ignored arrows, ignored Enter, and the on-screen [Y] Change theme hint ignored its own letter. Two stacked bugs:
- The theme preference was registered as a string preference — and
PreferenceDef’s constructor normalizes non-ENUM allowed-values to an empty list. The row rendered, but it had zero choices, so arrows and Enter were legally no-ops. Proven by probe: register a fresh string def with allowed[a, b], read it back[]. - In the registered-preferences view, the key handler swallowed every letter except one — the
[Y]hint was simply false advertising.
What changed. The theme def is now a real ENUM preference whose choices are the built-in themes (default, dark, yellow_on_blue, green_on_black, white_on_green, yellow_on_red, classic_pc, cyberpunk, amber_on_black, art_deco, paper), defined in exactly one place shared by the server registration and the screen. The classic letters (Y theme, T transitions, S style, B background, C timestamps, O board sort) route and apply their own row again. And the theme now applies live — the single save-point resolves the new theme and re-pins the session’s thread theme immediately, no re-login; choosing default clears the override entirely so the session follows the global/seasonal script again.
The value: the preferences architecture itself became stricter — anything cycle-able must be an ENUM with explicit values, or the constructor will silently strip it. Three RED laws (enterCyclesThemeRow, themeLetterRoutesAndAppliesLive, board-sort row) document that; the @AfterEach hook that clears thread-theme state keeps the pin from leaking into neighbors.
The probe that kept failing, and what the wire was telling us
The end-to-end harness — scripted telnet login, walk to the door, play a deal, assert glyphs — kept failing randomly, while a dump of the same screens showed the art perfectly present. First theory: TCP chunk boundaries splitting multi-byte glyphs, fixed by switching to an incremental UTF-8 decoder. Still failing.
The real answer was more interesting: the telnet wire is CP437, not UTF-8. The door paints its box borders as 0xC9-family bytes and the card suits as raw control bytes (♥ = 0x03, ♦ = 0x04, ♣ = 0x05, ♠ = 0x06). The assertions demanded UTF-8 glyphs and were rejecting the correct render. The harness now keeps a raw byte tail alongside the decoded text, and its glyph laws accept either the UTF-8 form or the CP437 bytes — plus fail-time buffer capture so the next flake shows the screen it saw.
The value: an E2E that passes deterministically, and a documented law that Phosphor door paint reaches plain telnet as CP437 — the next harness author doesn’t spend an afternoon re-discovering it.
The ledger
- Commits today:
404fa60(jterm: SGR null-safe),b5748ec9(theme backgrounds on styled labels),27d4d3ba(live-width + centered hints),8d372b11(theme ENUM + letter routing + live apply); docs close-out in89287345. - Tests: full server gate 9,835 passing / 0 failing (one long-standing pre-existing skip); jterm gate 3,218 / 0; the phosphor module 1,313 / 0. Fix-run RED→GREEN counts quoted above in the commits.
- Deploys: four production rollouts in one day, each gated on zero active sessions, each verified by bytecode inspection of the shipped jar — not by trusting a build timestamp — and each followed by a live E2E pass.
On deck: the menu reorganization
The top-level menu’s next facelift is designed and in build: six grouped letters — Messages (mail, chat, who’s online, page sysop), Forums (boards, news, polls), Files & Media, Games, Your Account, plus the finance plugin and the sysop lane — instead of thirteen flat entries. Search and Lock leave the menus entirely and become global hotkeys (Ctrl-S and Ctrl-Z; Ctrl-L stays redraw), and the logout/detach fork collapses into one exit — Log Out detaches and leaves your session resident, so a reconnect resumes right where you were. The SysOp menu gets a hierarchy straightener: its group becomes simply Network, with AI configuration living under Server Config. It’s a clean break — old flat letters retire rather than linger as aliases — and it lands as a canonical catalog that boot reconciles into existing installs and fresh schema seeds alike.
The lesson
Every one of today’s fixes was found the same way: somebody touched the real thing — played a door, opened a picker, connected a real terminal — and the abstraction disagreed with reality. The response each time was to turn the disagreement into a named law with a failing test first. The code then had only one honest direction to go, and the law stays after the fix to keep the next refactor from quietly undoing it. Ship the law with the change; the change lasts exactly as long as the law does.