Repository navigation
fix(separators): clear colors a new Color Level can't show, and invert left glyphs entered by hex - #786
Merged
Conversation
Changing Color Level resets each widget's ansi256 or hex color that the new level can't show to the widget's default, and clears such backgrounds. A separator's foreground was skipped, because separators have no widget default to reset to, so it kept its color. A separator given a hex color at Truecolor still had it after cycling on to 256 Color, and the 256-color line printed a 24-bit escape for it (\x1b[38;2;0;255;0m) next to the widgets' 38;5 codes. The reset warning counts separator colors as well, so with only a colored separator it promised a reset, and confirming it changed nothing. Clear a separator foreground the new level can't show, as backgrounds already are. Without a color, a separator renders in the separator default, or takes the previous widget's colors when separators inherit colors.
Picking Triangle Left or Round Left with the arrow keys turns on the separator's background inversion, which a left-facing glyph needs to draw the next segment's color on the previous segment's background. Entering the same glyph with (h), as E0B2 or E0B6, kept the slot's old inversion instead. On the default separator that is off, so the arrow was drawn reversed (\x1b[31m\x1b[44m between a red and a blue segment, instead of \x1b[34m\x1b[41m), and the list showed no [Inverted] to hint that (t) was needed. Typing E0B0 over an inverted Triangle Left likewise left the right triangle inverted. When (h) enters one of the preset glyphs, set its inversion as the arrow keys do: on for the left-facing ones, off for the right-facing ones. A custom code point keeps the slot's inversion, since its direction is unknown, and (t) still toggles it.
Contributor
|
Reproduced on current Red: 6 failing / 19 total — separator colors survive a Color Level downgrade (a hex separator keeps printing a 24-bit escape at 256 Color), the "reset custom colors" warning resets nothing when only separators have custom colors, and hex-entered left glyphs (E0B2/E0B6) don't set background inversion. Matches the PR's 2+1+3 split; the guard case passes on main as stated. Green: with the full PR head checked out, 19 passing / 0 failing.
|
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.
What
Two fixes to separator colors:
[Inverted]. Typing E0B0 or E0B4 turns inversion off, as ← → does. A custom code point keeps the slot's inversion as before.Why
sanitizeLinesForColorLevelresets a widget's foreground togetDefaultColor(). Separators and flex separators have no widget implementation and so no default, andresetWidgetForegroundToDefaultreturned them unchanged. Their backgrounds were cleared, but their foregrounds were not.getColorAnsiCodeonly drops hex and ansi256 colors at Basic and No Color, so at 256 Color a hex color still prints38;2. The TUI only offers hex at Truecolor, so the level change is the one place that keeps hex off a 256-color line, and separators skipped it.Line
[Model hex:FF00AA, separator hex:00FF00, Custom Text], sanitized for each step from Truecolor round to 256 Color (No Color, Basic, 256 Color) onmain:Piping a payload with that saved line at
colorLevel: 2printed (cat -v):hasCustomWidgetColorscounts separators, so with a hex color on a separator only, it returnedtrueand the warning showed. Sanitizing for No Color then returned the line unchanged, so confirming the warning reset nothing.The hex Enter branch of
PowerlineSeparatorEditorcalledupdateSeparators(newSeparators)with no inversion list.updateSeparatorsthen kept the slot's old flag (invertBgs[i] ?? false). Only the ← → branch set the flag from the glyph's direction. Onmain, with the editor's saved settings:separatorInvertBackground: [false]. ← → saves[true]for the same glyph.[true].The renderer picks the foreground and background order from that flag alone. Between a red and a blue segment (
bgRed, thenbgBlue, Basic colors), the E0B2 separator printed^[[31m^[[44mwith the flag off: the previous segment's red arrow on the next segment's blue, pointing into the wrong segment. With the flag on it printed^[[34m^[[41m.How
resetWidgetForegroundToDefaultclears a separator's or flex separator's foreground (color: undefined), the same way backgrounds are cleared. A separator without a color renders in the separator default, or takes the previous widget's colors when separators inherit colors. The existing test that kept a separator's hex foreground at Basic now expects it cleared. One new test covers separators at 256 Color and Truecolor, and another checks that the separator colors that trigger the warning are reset.it.eachinPowerlineSetup.test.tstypes each code into the editor and checks the saved separators and inversion.Left as is:
"colorLevel": 2still prints the separator as^[[38;2;0;255;0m |. The color is cleared the next time Color Level reaches No Color, two presses away (256 Color → Truecolor → No Color). Saved at Basic or No Color, the same hex color prints no escape, and the next Color Level step clears it. A hex color set at 256 Color by editingsettings.jsonby hand behaves the same way. Mapping hex to the nearest 256 color when rendering would cover both cases, but that is a separate change. The TUI only offers hex at Truecolor.Demo
Each case only shows up in one mode, so each was recorded once.
Powerline
A separator entered by hex code. The line uses the Nord Aurora theme with one Triangle Right separator. (h),
E0B2, Enter turns it into a Triangle Left. Before, the list showsTriangle Leftand the preview draws each arrow in the previous segment's color, notched into the next one. After, it showsTriangle Left [Inverted]and the arrows are the right way round. Plain mode isn't recorded: Separator is disabled in Powerline Setup while Powerline is off.Before:
After:
Plain
Color Level from Truecolor round to 256 Color. Model, Context Length and Session Cost have hex colors, and the two
|separator items are hex00FF00. Terminal Options > Color Level warns, Yes goes to No Color, and two more presses reach 256 Color. The widgets go back to their default colors on the way. Before, the separators stay bright green in the preview. After, they are back to the separator default. The configuration is then saved, and the piped line is checked:color-codes.jslists each visible piece of it with its foreground escape. Before, both|printESC[38;2;0;255;0m(24-bit) at"colorLevel": 2. After, they print in the default color. Powerline isn't recorded: Powerline mode draws no separator items.Before:
After:
Testing
mainas of fix: use env override and settings for usable context ratio calculation #407 (71e8b42): merges cleanly,bun run lintis clean, andbun testgives 3944 pass, 0 fail. The built CLI under Bun 1.4.4 and Node 26.13.0 matchesmainin plain and Powerline mode with the baseline configs, and the TUI opens and exits cleanly. It adds no JavaScript or Node API newer than Node 14, the build's target.bun run lintis clean.bun test: 3174 pass, 0 fail across 178 files, against 3168 pass, 0 fail onmain. 6 tests are new, and one existing assertion changed.main, the 2 newcolor-sanitize.test.tstests and the changed one fail. 3 of the 4 new editor cases fail there too. The fourth checks that a custom code keeps its inversion, whichmainalready does.main.dist/under Bun 1.4.2 and Node v26.10.0: the baseline plain and Powerline renders agree across runtimes and matchmain. The TUI opens and exits cleanly under both.