fix(statusline): limit max rigs displayed to prevent overflow

When many rigs are registered, the tmux statusline would truncate or
overflow. This adds a configurable maximum (default 5) with an overflow
indicator showing how many rigs are hidden (e.g., "+3").

Running rigs are prioritized (shown first) due to existing sort order.

Configure via GT_MAX_RIGS_DISPLAY env var:
- Default: 5 rigs shown
- Set to 0 for unlimited
- Set to any positive number for custom limit

Fixes: h-4wtnc

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
furiosa
2026-01-25 13:12:20 -08:00
committed by John Ogle
parent 77a01010c3
commit eaff7c3936

View File

@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/spf13/cobra"
@@ -320,6 +321,20 @@ func runMayorStatusLine(t *tmux.Tmux) error {
return rigs[i].name < rigs[j].name
})
// Truncate to max rigs if there are too many to display
// Default: 5, configurable via GT_MAX_RIGS_DISPLAY env var (0 = unlimited)
maxRigs := 5
if envMax := os.Getenv("GT_MAX_RIGS_DISPLAY"); envMax != "" {
if parsed, err := strconv.Atoi(envMax); err == nil && parsed >= 0 {
maxRigs = parsed
}
}
overflow := 0
if maxRigs > 0 && len(rigs) > maxRigs {
overflow = len(rigs) - maxRigs
rigs = rigs[:maxRigs]
}
// Build display with group separators
var rigParts []string
var lastGroup string
@@ -366,6 +381,11 @@ func runMayorStatusLine(t *tmux.Tmux) error {
rigParts = append(rigParts, led+space+rig.name)
}
// Add overflow indicator if rigs were truncated
if overflow > 0 {
rigParts = append(rigParts, fmt.Sprintf("+%d", overflow))
}
if len(rigParts) > 0 {
parts = append(parts, strings.Join(rigParts, " "))
}