feat: use dynamic column widths in bt status output#14
Conversation
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.
There was a problem hiding this comment.
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
BRANCHandPATHcolumn widths dynamically by scanning worktree data. - Updates the
bt statusheader and row formatting to use variable-width (%-*s) fields.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 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) | ||
| } |
There was a problem hiding this comment.
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.
| if len(branchName) > maxBranchLen { | ||
| maxBranchLen = len(branchName) | ||
| } | ||
| relPath, _ := filepath.Rel(repoRoot, wt.Path) |
There was a problem hiding this comment.
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.
| 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 | |
| } |
Summary
bt statusoutput with dynamically calculated widths based on actual branch names and pathsTest plan
bt statusin a repository with short branch names and verify columns are compactbt statusin a repository with long branch names (e.g.,feat/very-long-feature-name) and verify alignment is preserved