Skip to content

fix(powerline): customize a theme with the colors it showed - #677

Open
eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/theme-customize-colors
Open

eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/theme-customize-colors

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Customizing a Powerline theme (c in Powerline Setup → Themes, then Yes) now copies the colors the theme was showing. Merged widgets keep their shared color, and with Continue Theme on, lines after the first keep the colors they had.

Why

Customize numbered every widget in a line and restarted at the first theme color on each line. The renderer numbers them differently: a widget merged into the next one shares that group's color, and with Continue Theme on, each line picks up where the previous one stopped. So pressing Yes could recolor the line it was meant to freeze.

Nord Aurora at 256 colors, Model merged into Context Length on line 1, Git Changes and Version on line 2, Continue Theme on. Backgrounds in the preview:

line 1 line 2
theme, before c Model+Ctx 131, Branch 220 68, 108
main, after Yes Model 131, Ctx 220, Branch 68 131, 220
this branch, after Yes Model+Ctx 131, Branch 220 68, 108

How

powerline-theme-index.ts already holds the rule the renderer uses to carry the theme index from one line to the next: a widget merged into the previous shown widget shares its slot, and separators break merges. That loop now returns each widget's slot as well as the count (assignPowerlineThemeSlots), and countPowerlineThemeSlots is a thin wrapper over it, so the status line and the preview count exactly as before. Customize numbers each line with it and starts each line where the previous one stopped when Continue Theme is on, or at 0 when it's off.

Customize works from the settings, not from rendered output, so it treats every widget as shown. Lines without merges, with Continue Theme off, get the same colors as before, and separators are still left alone. The only widgets that render nothing in the preview are a Custom Text or Custom Symbol with no text, which still take a color in the copy, as before.

Demo

Nord Aurora with Model merged into Context Length and Continue Theme on (the preview's sample data): open Themes, press c, choose Yes. Powerline only: themes only apply in Powerline mode, and the Themes entry is disabled in plain mode.

Powerline: before

Customizing the theme recolors the merged widget and the second line, before the fix

Powerline: after

Customizing the theme keeps the colors the preview showed, after the fix

Testing

  • New tests in PowerlineThemeSelector.test.ts render each line from the theme and from the customized copy, carrying the theme index across lines as the status line does, and expect identical output: a merged group, Continue Theme on, and Continue Theme off. The first two failed on main (the merged widget got 220 instead of 131, line 2 restarted at 131); the third passes on both.
  • bun test: 2785 pass, 0 fail. bun run lint passes.
  • Under Node 26.10.0 (Vitest), the selector, theme index and renderer theme test files: 13 pass (10 existing and 3 new); main passes its 10.
  • Built CLI under Node 26.10.0 in tmux with a scratch HOME, the config from the table: on main the preview backgrounds go from 131 220 / 68 108 to 131 220 68 / 131 220 after Yes; on this branch they stay 131 220 / 68 108.
  • Bun 1.4.2.

Customizing a Powerline theme (c in the theme list) copied the theme's
colors onto the widgets by counting every widget in a line, restarting at
the first color on each line. The renderer counts differently: a widget
merged into the next one shares that group's color, and with Continue Theme
on, each line picks up where the previous one stopped. So the copy could
differ from what the theme had just shown. With Model merged into Context
Length, the pair shared one background under the theme, but the copy gave
Context Length the next color and shifted every widget after it; with
Continue Theme on, every line after the first restarted at the first color.

Number the widgets with the same slot rule the renderer uses to carry the
theme across lines, now shared from powerline-theme-index, and continue the
numbering across lines when Continue Theme is on. Lines without merges and
with Continue Theme off get the same colors as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant