Repository navigation
fix(renderer): keep a preserve-colors widget's Powerline background after its resets - #687
Open
eric-engberg wants to merge 1 commit into
Open
eric-engberg wants to merge 1 commit into
eric-engberg wants to merge 1 commit into
Conversation
…fter its resets In Powerline mode a widget that preserves its own colors (a Custom Command with preserve colors on) gets its segment background once, before its text. Command output usually ends with \x1b[0m, and Custom Command appends one after cutting colored output to its max width; that reset cleared the background too, so the trailing padding, and any text after a reset mid-output, showed the terminal's background before the separator arrow: \x1b[48;5;26m \x1b[31mhello\x1b[0m \x1b[0m<arrow> Re-apply the segment background after each SGR sequence in the preserved text that clears it: a full reset (0 or an empty parameter, alone or combined like 0;32) or 49. The arguments of extended colors (38/48/58;5;n and ;2;r;g;b) are skipped, so a 0 or 49 among them isn't read as a reset. The command's own colors, including its own backgrounds, are kept, and the full reset after the widget is unchanged. Widgets without a background, and plain mode (which colors the padding separately), are untouched.
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
In Powerline mode, a Custom Command with preserve colors on keeps its segment background all the way to the separator arrow. Before, the command's own reset cleared the background, which left a cell of terminal background (the trailing padding) between the text and the arrow. Any text after a reset in the middle of the output lost it too.
Why
The Powerline renderer emits the segment background once, before the widget's text. Command output usually ends with
\x1b[0m, and Custom Command appends one itself after cutting colored output to its max width. That full reset clears the background as well, so everything after it is drawn on the terminal's background. Withprintf '\033[31mhello\033[0m'on a blue segment:How
After each SGR sequence in the preserved text that clears the background, the segment background is emitted again. That covers a full reset (
0, an empty parameter, alone or combined such as0;32) and49. The arguments of extended colors (38/48/58with;5;nor;2;r;g;b) are skipped, so a0or49among them isn't read as a reset.Nothing else changes:
Demo
A sample line (
scripts/payload.example.json) with a Custom Command runningprintf '\033[1;34mbuild ok\033[0m'with preserve colors, between Model and Context Length, on the Nord Aurora theme. Look at the cell before the arrow afterbuild ok. Plain mode renders the same before and after, so it has no stills.Powerline: before
Powerline: after
Testing
0;32,49and\x1b[mmid-output. The first two fail onmain; the third guards that extended colors with0/49arguments are left alone.0, empty,00,;1and39;49restore the background;1;31,38;5;0,48;2;0;49;0,58;5;49and39don't.bun test: 2787 pass, 0 fail.bun run lintpasses.mainonly by the re-applied background, and plain output is the same asmain. With the baseline line, both modes are the same asmain. The TUI opens and exits cleanly under both.