Skip to content

fix(powerline): keep separator inversion list dense when editing - #673

Open
eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/separator-invert-background-holes
Open

eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/separator-invert-background-holes

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Editing a Powerline separator no longer saves a settings file that fails to load. Toggling inversion (t) or cycling the glyph (←/→) on a separator now always saves one true/false per separator.

Why

separatorInvertBackground is often shorter than separators: its schema default is [false], and hand-edited or imported configs usually add separators without extending it. The separator editor wrote the selected index straight into a copy of that list, so editing any separator past its end left a hole, which JSON saves as null.

With three separators and the default list: Powerline Setup → Separator, ↓ ↓, t (or →), ctrl+s. The file then holds

"separatorInvertBackground": [false, null, true]

and the next load fails validation (powerline.separatorInvertBackground.1: Invalid input: expected boolean, received null). Both the TUI and the status line fall back to the default settings, and the status line starts with ⚠ invalid config. The file is left as is, so it stays broken until edited by hand.

How

The editor pads the list to one entry per separator, filling missing entries with false, before any edit. Every edit path (toggle, cycle, add, insert, delete) then works on aligned entries, and the saved list always matches the separators in length.

A missing entry already rendered as not inverted (the renderer reads invertBgs[i] ?? false and only for indexes below the separator count), so nothing changes on screen. Start and end cap editing doesn't touch the list. Entries beyond the last separator, which the renderer never reads, are dropped on the next edit, as the hex-input path already did.

Demo

Three separators with the default one-entry inversion list: toggle inversion on the third separator, save, then render the status line from the saved file (sample data). Powerline only: the separator editor is disabled in plain mode, so plain mode can't reach this.

Powerline: before

Toggling separator inversion saves a null and the status line shows invalid config, before the fix

Powerline: after

Toggling separator inversion saves a full list and the status line renders the saved config, after the fix

Testing

  • New test in PowerlineSetup.test.ts: three separators with separatorInvertBackground: [false], ↓ ↓, then t and → as separate cases. Each expects [false, false, true], and that the saved JSON passes the settings schema. Both failed on main ([false, undefined, true]); looped 10 times, no failures.
  • bun test: 2784 pass, 0 fail. bun run lint passes.
  • The changed test file under Node 26.10.0 (Vitest): 8 pass (6 existing and 2 new); main passes its 6.
  • Built CLI under Node 26.10.0 in tmux with a scratch HOME, same steps: main saves [false, null, true], and the relaunched TUI and the piped render both print the parse error and fall back to defaults. This branch saves [false, false, true], still [false, false, true] after a following → turns the third separator into Triangle Left, and both load it cleanly.
  • Bun 1.4.2.

The separator editor wrote `separatorInvertBackground[i]` straight into a
copy of the saved list. That list is often shorter than the separators: its
schema default is `[false]`, and hand-edited or imported configs commonly
add separators without extending it. Toggling (t) or cycling (left/right) a
separator past the end of the list left holes in the array, which JSON saves
as `null`. With three separators and the default list, selecting the third
and pressing `t` saved `[false, null, true]`; the next load failed
validation, so both the TUI and the status line fell back to defaults with
the invalid-config warning.

Pad the list to one entry per separator, defaulting to false, before any
edit. Missing entries already rendered as not inverted, so nothing changes
visually; add, insert and delete now also work on aligned entries.
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