formatBranchPath formats branch and path info to fit within maxWidth. maxWidth is in display characters (runes).
(branch, path string, maxWidth int)
| 639 | // formatBranchPath formats branch and path info to fit within maxWidth. |
| 640 | // maxWidth is in display characters (runes). |
| 641 | func (p *PRDPicker) formatBranchPath(branch, path string, maxWidth int) string { |
| 642 | // Format: " <branch> <path>" |
| 643 | prefix := " " |
| 644 | separator := " " |
| 645 | prefixLen := 2 |
| 646 | sepLen := 2 |
| 647 | |
| 648 | branchRunes := []rune(branch) |
| 649 | pathRunes := []rune(path) |
| 650 | |
| 651 | fullLen := prefixLen + len(branchRunes) + sepLen + len(pathRunes) |
| 652 | if fullLen <= maxWidth { |
| 653 | return prefix + branch + separator + path |
| 654 | } |
| 655 | |
| 656 | // Try truncating path first |
| 657 | availForPath := maxWidth - prefixLen - len(branchRunes) - sepLen |
| 658 | if availForPath > 5 { |
| 659 | if len(pathRunes) > availForPath { |
| 660 | // "…" takes 1 display character |
| 661 | keep := availForPath - 1 |
| 662 | pathRunes = append([]rune("…"), pathRunes[len(pathRunes)-keep:]...) |
| 663 | } |
| 664 | return prefix + branch + separator + string(pathRunes) |
| 665 | } |
| 666 | |
| 667 | // Not enough room for path, just show branch (truncated if needed) |
| 668 | availForBranch := maxWidth - prefixLen |
| 669 | if availForBranch > 3 && len(branchRunes) > availForBranch { |
| 670 | branchRunes = append(branchRunes[:availForBranch-1], '…') |
| 671 | } |
| 672 | return prefix + string(branchRunes) |
| 673 | } |
| 674 | |
| 675 | // renderLoopStateIndicator renders a visual indicator for the loop state. |
| 676 | func (p *PRDPicker) renderLoopStateIndicator(entry PRDEntry) string { |
no outgoing calls