Skip to content

fix: show the max width in Git Branch and Git Root Dir previews - #667

Open
eric-engberg wants to merge 3 commits into
sirmalloc:mainfrom
eric-engberg:fix/max-width-preview
Open

eric-engberg wants to merge 3 commits into
sirmalloc:mainfrom
eric-engberg:fix/max-width-preview

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

With a max width set (w), the TUI preview of Git Branch and Git Root Dir now shows the cut, e.g. ⎇ feature... at 12 columns. Before, the preview stayed ⎇ main / my-repo whatever the setting.

Why

w looked like it did nothing in the TUI. Both widgets returned their preview sample before applying the cap. Even if they had applied it, the samples (main, my-repo) were too short for any useful width to cut. The cap only showed on the real status line, with a long branch or repository name.

How

  • With a cap set, the preview uses a longer sample (feature/long-branch-name, my-long-repository-name) and cuts it with the same applyMaxWidth the status line uses on a real name. That includes the glyph prefix and the raw value form, so the preview shows what the setting does.
  • With no cap, the previews stay main and my-repo.
  • Branch link: with a cap set, the preview's sample link points at the sample branch.
  • The piped status line doesn't change.

Demo

w on Git Branch set to 12, then on Git Root Dir set to 10. The preview cuts each sample at its limit.

Powerline

Max width in the preview in Powerline mode

Plain

Max width in the preview in plain mode

Testing

  • New tests: Git Branch's preview cut at 12 columns, labeled and raw (⎇ feature..., feature/l...), and Git Root Dir's at 10 (my-long...). Both failed before the fix. The existing tests that expect ⎇ main and my-repo with no cap still pass.
  • The second commit moves Git Branch's preview into its own method, since render() had grown a preview branch with its own sample, width and link handling. compare-widgets.sh renders git-branch the same in all 14 cases on both commits.
  • On today's main (with docs: explain an empty status line in one folder (workspace trust) #606 and feat(git-is-fork): render forks as an editable glyph #617 merged in locally): bun test gives 2784 pass, 0 fail (Bun 1.4.2), and bun run lint is clean. Under Node 26 vitest, both widget test files pass (46).
  • runtime-check.sh -c max-width-preview on the built CLI: Bun 1.4.2 and Node 26.10.0 agree byte-for-byte, the piped output is the same as main (the change is preview-only), and the TUI opens and exits under both.
  • In a real tmux pane: w → 12 on Git Branch turns the preview from ⎇ main into ⎇ feature..., with (max:12) on the row.

(w) caps how wide the branch or repository name gets, but the TUI
preview returned its sample before applying the cap, and the samples
(`main`, `my-repo`) were too short to cut anyway. With a cap set, the
previews now use a longer sample and cut it the way the status line
cuts a real name, so the setting shows as you make it.
render() had grown a preview branch with its own sample, width and
link handling; it reads more easily on its own.
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