feat(tui): status bar cleanup — branch, battery label, drop shortcuts#25
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds Git branch detection by reading ChangesGit Branch Detection and Ambient Status Display
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/tui/branch.go`:
- Around line 38-39: The doc comment for readBranch is inaccurate: it mentions
returning "a short sha for a detached HEAD" but the implementation returns ""
for detached HEAD; update the comment above the readBranch function to state
that it returns the branch name for the repo containing dir, or an empty string
if no enclosing git repo or if HEAD is detached (i.e., no branch), removing any
reference to returning a short SHA.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2375deb3-13a3-4528-a3ef-6e130ec773b1
📒 Files selected for processing (6)
.claude/settings.local.jsoninternal/tui/branch.gointernal/tui/branch_test.gointernal/tui/render.gointernal/tui/render_test.gointernal/tui/tui.go
| // readBranch returns the branch name for the repo containing dir, or a short | ||
| // sha for a detached HEAD, or "" if no enclosing git repo is found. |
There was a problem hiding this comment.
Update doc comment to match implementation.
The doc comment states the function returns "a short sha for a detached HEAD", but the implementation returns "" for detached HEAD (lines 79-80). Per the PR objectives, the SHA fallback was intentionally removed. Update the doc to reflect the actual behavior.
📝 Proposed fix
-// readBranch returns the branch name for the repo containing dir, or a short
-// sha for a detached HEAD, or "" if no enclosing git repo is found.
+// readBranch returns the branch name for the repo containing dir, or ""
+// when not on a branch or no enclosing git repo is found.
// Walks upward from dir until a .git entry is found or the filesystem root
// is reached.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // readBranch returns the branch name for the repo containing dir, or a short | |
| // sha for a detached HEAD, or "" if no enclosing git repo is found. | |
| // readBranch returns the branch name for the repo containing dir, or "" | |
| // when not on a branch or no enclosing git repo is found. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/tui/branch.go` around lines 38 - 39, The doc comment for readBranch
is inaccurate: it mentions returning "a short sha for a detached HEAD" but the
implementation returns "" for detached HEAD; update the comment above the
readBranch function to state that it returns the branch name for the repo
containing dir, or an empty string if no enclosing git repo or if HEAD is
detached (i.e., no branch), removing any reference to returning a short SHA.
There was a problem hiding this comment.
Pull request overview
Cleans up the TUI status bar rendering by removing the static keyboard-shortcut block, stabilizing the battery readout formatting, and adding a (truncated) current git-branch indicator that’s refreshed on the render tick.
Changes:
- Add periodic branch polling + render
git:<branch>on the status bar. - Update right-side status bar grouping and battery formatting (
Bat %3d%%), removing the shortcut string. - Update/add tests to reflect the new status bar content and branch truncation behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/tui/tui.go | Adds branch fields to TUI and triggers pollBranch() from the main loop tick. |
| internal/tui/render.go | Reworks status bar right-side composition; adds battery label + branch rendering. |
| internal/tui/render_test.go | Updates status bar expectations; adds branch render/truncation tests. |
| internal/tui/branch.go | Implements .git/HEAD parsing + throttled polling + rune-based truncation helper. |
| internal/tui/branch_test.go | Adds tests for repo/worktree HEAD parsing and truncation behavior. |
| .claude/settings.local.json | Adds a Claude permissions config file (currently unrelated to the PR’s stated scope). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // readBranch returns the branch name for the repo containing dir, or a short | ||
| // sha for a detached HEAD, or "" if no enclosing git repo is found. | ||
| // Walks upward from dir until a .git entry is found or the filesystem root | ||
| // is reached. |
| branch string | ||
| branchPollAt time.Time | ||
|
|
||
|
|
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(git fetch *)", | ||
| "Bash(git rebase *)", | ||
| "Bash(go build *)", | ||
| "Bash(git add *)", | ||
| "Bash(go test *)" | ||
| ] | ||
| } | ||
| } |
Reads HEAD directly from .git (handling worktree indirection) on a 2s poll, displayed as "git:<name>" between battery and keyboard shortcuts. Walks upward from projectRoot so a config root inside a subdirectory still resolves the enclosing repo. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
readBranch previously fell back to "first 7 chars of HEAD" whenever the file didn't start with "ref: refs/heads/". That meant non-branch refs (tags, remotes) and malformed HEADs leaked partial text like "ref: re" into the status bar. We only ever wanted to show *branch* names, so drop the SHA fallback entirely and return empty for anything that isn't on a branch. Also cap the rendered branch at 25 runes with an ellipsis so a long branch name can't push the rightmost status-bar items (clock) off screen. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Reorder right-side items into three contiguous groups: app state (mode, pending, update, quota), system state (battery, branch, clock), then hints (shortcuts). Previously battery and clock were split by the shortcut string, mixing ambient state with teaching aids. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Prefix the battery indicator with "Bat" so the meaning is recognizable without a glyph (no font/icon dependency), and right-pad the percent to 3 chars so " 0%", " 50%" and "100%" align as the value changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The static "\`:cmd Alt+z:zoom Alt+s:overlay ?:help Alt+q:quit" string duplicated what the rotating tips on the left already teach, and what the help modal (?) shows on demand. Removing it leaves the right side as pure ambient state and reclaims room on narrow terminals. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
c96a9e4 to
3e6e11d
Compare
|
Thanks for this — really clean work. Particularly liked the choice to parse Also appreciate the explicit invitation in the PR body to push back on individual changes. Shipped as-is — the regroup, the Going out as v1.23.0 shortly. |
Waiting for #23 to be merged so I can rebase this PR on top of
main.@nmelo if you don't agree with one of the changes here, lmk so I can remove it. Thanks.
Summary
Five-commit cleanup of the TUI status bar:
Bat 100%and left-pad the percent so width is stable.?help modal and the rotating left-side tips.Rebased on
nmelo/main(includes 3fbb532 battery mutex — battery block usesbatteryStatus()helper).Test plan
go test ./...— all packages passgo build ./...Summary by CodeRabbit
New Features
Tests