Skip to content

fix: honour flex-separator in powerline render path#411

Open
ssoriche wants to merge 1 commit into
sirmalloc:mainfrom
ssoriche:fix/powerline-flex-separator
Open

fix: honour flex-separator in powerline render path#411
ssoriche wants to merge 1 commit into
sirmalloc:mainfrom
ssoriche:fix/powerline-flex-separator

Conversation

@ssoriche
Copy link
Copy Markdown

@ssoriche ssoriche commented Jun 2, 2026

Summary

renderPowerlineStatusLine filters out flex-separator widgets at the top of the function and never restores their layout effect, so a configured flex-separator silently has no effect when powerline mode is enabled. The non-powerline render path correctly distributes terminal-width minus content-width across each flex-separator position; this PR teaches the powerline path to do the same.

Repro

In an existing config, enable powerline.enabled: true and place a flex-separator widget between two regular widgets. Render against a known terminal width and observe the visible width of the result is content-width, not terminal-width — the flex space is missing.

Fix

In src/utils/renderer.ts, inside renderPowerlineStatusLine:

  1. Track flex positions before filtering. Build a Set<number> of filteredWidgets indices that are immediately followed by a flex-separator in the original widgets array. The widget itself stays filtered (powerline can't render it as a triangle), but the layout intent is preserved.
  2. Emit a sentinel + section cap during the render loop. When a flex position is reached, emit a closing powerline cap — a triangle in the previous widget's bg colour with no bg of its own, so it terminates the left section visually — followed by a �FLEX_SEP� sentinel. Skip the regular between-widgets separator at that boundary.
  3. Post-process after the loop. If any flex positions were marked, split the result on the sentinel, measure each part's visible width, distribute terminalWidth − totalContentWidth evenly across the flex positions as spaces, and reassemble. When the terminal width is unknown the sentinels are stripped so they can't leak into the output.

The non-powerline path is unchanged.

Test plan

Four new tests in src/utils/__tests__/renderer-flex-width.test.ts:

  • distributes remaining width across a flex-separator in powerline mode — single flex, asserts visible width equals the effective render width (terminalWidth − 6 for flexMode: 'full').

  • distributes space across multiple flex-separators in powerline mode — three sections separated by two flex-separators, total visible width still matches effective width.

  • strips flex-separator markers when terminal width is unknown — sentinel never leaks into output when no width is detected.

  • still works in non-powerline mode (no regression) — sanity check on the existing path.

  • All 585 tests pass (bun test) — 581 existing + 4 new

  • TypeScript checks clean (bun tsc --noEmit)

  • ESLint clean (bun run lint)

  • Manually verified in a real Claude Code session (visible width fills to terminalWidth − 6 as expected)

renderPowerlineStatusLine filters out flex-separator widgets at the
start of the function and never restores their layout effect, so a
configured flex-separator silently has no effect when powerline mode
is enabled. The non-powerline render path correctly distributes
terminal-width minus content-width across each flex-separator
position; this commit teaches the powerline path to do the same.

How:

- Before filtering, compute a Set of filteredWidgets indices that are
  immediately followed by a flex-separator in the original widget
  array.
- During the render loop, when one of those indices is reached, emit
  a closing powerline cap (a triangle in the previous widget's bg
  colour with no bg of its own) followed by a sentinel string, and
  skip the regular between-widgets separator.
- After the render loop, if any flex positions were marked, split the
  result string on the sentinel, measure the visible width of each
  part, distribute the remaining terminal width evenly across the
  flex positions as spaces, and reassemble. When the terminal width
  is unknown the sentinels are stripped so they cannot leak.

Tests:

Four new tests in renderer-flex-width.test.ts cover
- single flex-separator in powerline mode
- multiple flex-separators in powerline mode
- sentinel cleanup when terminal width is unknown
- non-powerline path regression check

All 585 tests pass (581 existing + 4 new). Lint and tsc are clean.
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