feat(theme): adapt the painted backgrounds to a light terminal - #85
Merged
Merged
Conversation
The three indexed backgrounds - the focused block and tree row, the help bar, the keyboard cursor - and the reversed selection were absolute, so a light terminal drew its own dark text on them and lost it. Collect every background we paint ourselves into one palette with a light variant, ask the terminal for its background colour once before the screen is taken, and let [ui] theme or PLANNOTATOR_TUI_THEME settle it outright. The dark palette is the shipped one, value for value. refs #58
The environment overriding the config file is what `plannotator-tui config` has to print, and only the real binary reads both. refs #58
…config Herdr answers the colour query for its panes but never the DA1 probe, so the query always ran to the deadline there; 30 ms is plenty for the answer and shrinks the window in which a keystroke can be lost. The light comment and approve tints were near-invisible against a light page. A config that fails to parse no longer stops the plain TUI from starting, as it never did before. refs #58
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The colours half of #58, for the three absolute backgrounds alesch confirmed on Solarized Light. The keymap half and a user-facing
[colors]table are still jadonwb's.What was wrong
BLOCK_BG(236),TOOLBAR_BG(238) andCURSOR_BG(240) are painted under text whose colour belongs to the terminal. On a light terminal that is the terminal's dark foreground on a#303030bar, so the focused block, the focused file-tree row, the help bar and the cursor cell all go nearly invisible. The.reversed()picker row and character selection have the same problem from the other direction: reversing dark-on-light gives a black bar that swallows the annotation tints under it.COMMENT_BG(58) andAPPROVE_BG(22) turn out to be the same bug and are fixed with them.Detection
src/theme.rsasks the terminal for its background colour once, beforeratatui::init()takes the screen, and classifies light vs dark by comparing the perceived lightness of the background against the foreground. No reply, an unreadable reply, or no tty leaves the dark palette in place, which is exactly today's behaviour.The query itself is
terminal-colorsaurus, not hand-rolled. Per the dependency rule in AGENTS.md, the reason is correctness rather than convenience:DA1behind the colour query, so a terminal that does not implement OSC 11 is recognised at round-trip speed instead of sitting on the timeout;terminal-colorsaurus,terminal-trx,xterm-color— on top oflibc/windows-sys, which are already in the tree.One honest caveat, documented at
detect()and in the README: the query holds the tty in raw mode for one round trip, and a key pressed into that window is read and discarded with the reply. Nothing pushes those bytes back —TIOCSTIneedsunsafe, which this workspace forbids, and is disabled on current Linux anyway. Setting the theme outright skips the query and the window with it. The timeout is 100 ms, and only a pty with no emulator behind it ever reaches it.Precedence
PLANNOTATOR_TUI_THEME→[ui] themeinconfig.toml→ the terminal → dark.autoin the environment overrides a configuredlight/darkback to asking. An unreadable value is an error naming it, like a badplacement.plannotator-tui configprints whichever value is in effect, so the environment override is visible there.What changed for whom
Dark terminals: nothing.
the_dark_palette_is_unchangedpins all seven roles to their shipped values, and no palette is installed in tests,--snapshot,--export,--benchor any other non-TTY run, so every existing style assertion and snapshot still reads the dark one.Light terminals get
block_bg254,toolbar_bg252,comment_bg229,approve_bg194, a cursor that sets its own white foreground over 238 so the glyph under it stays legible, aDarkGrayidle button foreground instead ofGray, and a selection that is a real background (153) rather thanREVERSED. Checked against Solarized Light (#fdf6e3/#657b83) and plain white.Validation
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspace(183 tests) are clean.Driven end to end through a pty harness standing in for the terminal: a harness answering
rgb:fdfd/f6f6/e3e3produces48;5;254/48;5;252on screen, one answeringrgb:0000/0000/0000produces48;5;236/48;5;238, and one answering nothing also produces 236/238. The app starts and quits onqin all three.Left out deliberately: a user-facing
[colors]table, keymaps, and any theming of styles that already set both a foreground and a background (the Send/Sent/Blocked buttons, the delete strikethrough), which read the same either way.