Skip to content

feat(tui): status bar cleanup — branch, battery label, drop shortcuts#25

Merged
nmelo merged 5 commits into
nmelo:mainfrom
Hypefury:feat/status-bar-cleanup
May 12, 2026
Merged

feat(tui): status bar cleanup — branch, battery label, drop shortcuts#25
nmelo merged 5 commits into
nmelo:mainfrom
Hypefury:feat/status-bar-cleanup

Conversation

@Dinduks
Copy link
Copy Markdown
Contributor

@Dinduks Dinduks commented May 12, 2026

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:

  • Show current git branch (truncated to 25 runes; non-branch HEAD ignored).
  • Regroup right-side items by category: app state (mode, pending, update) → system state (battery, branch, clock).
  • Label the battery readout Bat 100% and left-pad the percent so width is stable.
  • Drop the static keyboard-shortcut string from the right side — already reachable via ? help modal and the rotating left-side tips.

Rebased on nmelo/main (includes 3fbb532 battery mutex — battery block uses batteryStatus() helper).

Test plan

  • go test ./... — all packages pass
  • go build ./...
  • Manual: launch TUI, verify branch + battery label render, narrow terminal truncation behaves

Summary by CodeRabbit

  • New Features

    • Status bar now displays the current Git branch name alongside system information
    • Battery percentage display now includes color-coded indicators for charging status and low-battery warnings
  • Tests

    • Added comprehensive test coverage for branch detection and status bar rendering functionality

Review Change Stack

Copilot AI review requested due to automatic review settings May 12, 2026 03:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9b524b20-fc48-4c8c-8589-659dadf44d1a

📥 Commits

Reviewing files that changed from the base of the PR and between c96a9e4 and 3e6e11d.

📒 Files selected for processing (5)
  • internal/tui/branch.go
  • internal/tui/branch_test.go
  • internal/tui/render.go
  • internal/tui/render_test.go
  • internal/tui/tui.go

📝 Walkthrough

Walkthrough

This PR adds Git branch detection by reading .git/HEAD directly and displays the current branch name in the TUI status bar. The implementation includes support for Git worktrees, rate-limited polling, comprehensive test coverage for branch detection across multiple Git layouts, and updated status bar rendering with reformatted battery output and truncated branch display.

Changes

Git Branch Detection and Ambient Status Display

Layer / File(s) Summary
Branch detection utilities
internal/tui/branch.go
findGitDir walks parent directories to locate .git, readBranch reads and parses .git/HEAD to extract the current branch name with worktree support via gitdir: resolution, pollBranch rate-limits refreshes on the TUI, and truncateRunes safely truncates display strings by rune count with ellipsis suffix.
Branch detection test suite
internal/tui/branch_test.go
Comprehensive tests for readBranch covering standard repos, worktrees with absolute and relative gitdir, detached HEAD, non-branch refs, malformed .git files, and missing HEAD; truncateRunes tests validate rune-safe truncation with ellipsis, boundary cases (max 0/1), exact fits, and Unicode input.
TUI branch state tracking and polling
internal/tui/tui.go
TUI struct adds branch and branchPollAt fields to cache the current branch and last poll timestamp; the event loop invokes pollBranch() during periodic housekeeping to refresh branch state at most once per branchPollInterval.
Status bar ambient state rendering
internal/tui/render.go
renderHints right side now displays ambient system state: battery output reformatted as Bat %3d%% with charging and percentage-based color thresholds, git branch displayed as git: followed by truncated branch name, and inline documentation updated to describe the new right-side grouping.
Status bar and branch rendering tests
internal/tui/render_test.go
Renamed and simplified hints test to verify tip content; added narrow-terminal non-panic test at width 65; tightened battery assertions to match full Bat <pct>% format; added branch rendering tests verifying short branches render verbatim as git:<branch> and long branches are ellipsized as git:<prefix>….

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • nmelo/initech#25: The same PR introduces Git branch detection, TUI status bar updates, and comprehensive test coverage for the new branch detection and rendering functionality.

Poem

🐰 A rabbit hops through git repos with glee,
Reading .git/HEAD and branches to see,
Worktrees and polling, all truncated with care,
The status bar glows with branches to share! 🌿✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description lacks the required template structure with explicit checkboxes for Type, Regression test, and Reviewer checklist. Fill in the required template with proper checkbox selections and confirmation that applicable checks have been completed or marked as N/A.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: displaying the git branch, reformatting the battery label, and removing keyboard shortcuts from the status bar.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac859ac and c96a9e4.

📒 Files selected for processing (6)
  • .claude/settings.local.json
  • internal/tui/branch.go
  • internal/tui/branch_test.go
  • internal/tui/render.go
  • internal/tui/render_test.go
  • internal/tui/tui.go

Comment thread internal/tui/branch.go
Comment on lines +38 to +39
// 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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
// 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/tui/branch.go
Comment on lines +38 to +41
// 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.
Comment thread internal/tui/tui.go
branch string
branchPollAt time.Time


Comment thread .claude/settings.local.json Outdated
Comment on lines +1 to +11
{
"permissions": {
"allow": [
"Bash(git fetch *)",
"Bash(git rebase *)",
"Bash(go build *)",
"Bash(git add *)",
"Bash(go test *)"
]
}
}
@Dinduks Dinduks marked this pull request as draft May 12, 2026 03:18
Dinduks and others added 5 commits May 12, 2026 04:21
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>
@Dinduks Dinduks force-pushed the feat/status-bar-cleanup branch from c96a9e4 to 3e6e11d Compare May 12, 2026 03:22
@nmelo nmelo marked this pull request as ready for review May 12, 2026 18:31
@nmelo nmelo merged commit 18f18f0 into nmelo:main May 12, 2026
3 of 4 checks passed
@nmelo
Copy link
Copy Markdown
Owner

nmelo commented May 12, 2026

Thanks for this — really clean work.

Particularly liked the choice to parse .git/HEAD directly instead of shelling out to git. On a 2s render-tick poll the fork+exec cost adds up fast, and it keeps git from becoming a runtime dependency for what's really just reading a small text file. The hermetic test setup (no git init, no temp repos) falls out of that decision naturally and made review easy.

Also appreciate the explicit invitation in the PR body to push back on individual changes. Shipped as-is — the regroup, the Bat 100% label, and dropping the keyboard shortcuts all hold up. Help modal + cycling tips cover discoverability without the static strip on the bar.

Going out as v1.23.0 shortly.

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.

3 participants