Skip to content

feat: use dynamic column widths in bt status output#14

Closed
amaya382 wants to merge 1 commit into
mainfrom
feat/status-align
Closed

feat: use dynamic column widths in bt status output#14
amaya382 wants to merge 1 commit into
mainfrom
feat/status-align

Conversation

@amaya382

Copy link
Copy Markdown
Owner

Summary

  • Replace fixed-width columns (20/30 chars) in bt status output with dynamically calculated widths based on actual branch names and paths
  • Improves readability when branch names or worktree paths are longer or shorter than the hardcoded widths
  • Header and data rows now align consistently regardless of content length

Test plan

  • Run bt status in a repository with short branch names and verify columns are compact
  • Run bt status in a repository with long branch names (e.g., feat/very-long-feature-name) and verify alignment is preserved
  • Verify broken worktree entries still display correctly with dynamic widths

Calculate column widths based on actual branch names and paths
instead of using fixed-width columns, improving readability for
repositories with long branch names or paths.
Copilot AI review requested due to automatic review settings March 20, 2026 05:00
@amaya382 amaya382 self-assigned this Mar 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the readability of bt status by replacing fixed-width worktree table columns with widths computed from the actual branch names and worktree paths, keeping headers and rows aligned across varying content lengths.

Changes:

  • Computes BRANCH and PATH column widths dynamically by scanning worktree data.
  • Updates the bt status header and row formatting to use variable-width (%-*s) fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/bt/status.go
Comment on lines +99 to +113
// Calculate dynamic column widths
maxBranchLen := len("BRANCH")
maxPathLen := len("PATH")
for _, wt := range worktrees {
branchName := wt.Branch
if branchName == "" {
branchName = "(detached)"
}
if len(branchName) > maxBranchLen {
maxBranchLen = len(branchName)
}
relPath, _ := filepath.Rel(repoRoot, wt.Path)
if len(relPath) > maxPathLen {
maxPathLen = len(relPath)
}

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

Column widths are calculated with len(), but fmt’s %-*s padding uses rune count. If branch names or paths contain non-ASCII characters, the computed widths can be too large/small and columns will misalign. Consider using utf8.RuneCountInString (or a display-width helper) when computing maxBranchLen/maxPathLen.

Copilot uses AI. Check for mistakes.
Comment thread cmd/bt/status.go
if len(branchName) > maxBranchLen {
maxBranchLen = len(branchName)
}
relPath, _ := filepath.Rel(repoRoot, wt.Path)

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

filepath.Rel errors are ignored when computing/printing relPath. On Windows (different volumes) or other edge cases, Rel can fail and relPath will be empty, which also skews maxPathLen and produces misleading output. Handle the error and fall back to wt.Path (or another sensible default) when Rel returns an error.

Suggested change
relPath, _ := filepath.Rel(repoRoot, wt.Path)
relPath, err := filepath.Rel(repoRoot, wt.Path)
if err != nil {
// If we cannot compute a relative path (e.g., different volumes on Windows),
// fall back to the original worktree path to avoid empty/misleading output.
relPath = wt.Path
}

Copilot uses AI. Check for mistakes.
@amaya382

Copy link
Copy Markdown
Owner Author

#15

@amaya382 amaya382 closed this Mar 20, 2026
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.

2 participants