-
Notifications
You must be signed in to change notification settings - Fork 0
feat: use dynamic column widths in bt status output #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,7 +83,6 @@ func runStatus(cmd *cobra.Command, args []string) error { | |
|
|
||
| // Print worktrees | ||
| fmt.Println("Worktrees:") | ||
| fmt.Printf(" %-20s %-30s %s\n", "BRANCH", "PATH", "STATUS") | ||
| var unmanagedWorktrees []string | ||
|
|
||
| // Determine which worktree we're currently in | ||
|
|
@@ -97,6 +96,25 @@ func runStatus(cmd *cobra.Command, args []string) error { | |
| } | ||
| } | ||
|
|
||
| // 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) | ||
| } | ||
|
Comment on lines
+99
to
+113
|
||
| } | ||
|
|
||
| fmt.Printf(" %-*s %-*s %s\n", maxBranchLen, "BRANCH", maxPathLen, "PATH", "STATUS") | ||
|
|
||
| for _, wt := range worktrees { | ||
| prefix := " " | ||
| // Check if current directory is within this worktree | ||
|
|
@@ -113,10 +131,10 @@ func runStatus(cmd *cobra.Command, args []string) error { | |
| // Check if this worktree is broken (path doesn't exist) | ||
| if _, isBroken := brokenBranches[branchName]; isBroken { | ||
| relPath, _ := filepath.Rel(repoRoot, wt.Path) | ||
| fmt.Printf(" %s %-20s %-30s %s%s\n", | ||
| fmt.Printf(" %s %-*s %-*s %s%s\n", | ||
| prefix, | ||
| branchName, | ||
| relPath, | ||
| maxBranchLen, branchName, | ||
| maxPathLen, relPath, | ||
| "[Broken]", | ||
| " ⚠️", | ||
| ) | ||
|
|
@@ -136,10 +154,10 @@ func runStatus(cmd *cobra.Command, args []string) error { | |
|
|
||
| relPath, _ := filepath.Rel(repoRoot, wt.Path) | ||
|
|
||
| fmt.Printf(" %s %-20s %-30s %s%s\n", | ||
| fmt.Printf(" %s %-*s %-*s %s%s\n", | ||
| prefix, | ||
| branchName, | ||
| relPath, | ||
| maxBranchLen, branchName, | ||
| maxPathLen, relPath, | ||
| status, | ||
| statusSymbol, | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
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.