feat(tmux): add per-rig color themes and dynamic status line (gt-vc1n)
Add tmux status bar theming for Gas Town sessions: - Per-rig color themes auto-assigned via consistent hashing - 10 curated dark themes (ocean, forest, rust, plum, etc.) - Special gold/dark theme for Mayor - Dynamic status line showing current issue and mail count - Mayor status shows polecat/rig counts New commands: - gt theme --list: show available themes - gt theme apply: apply to running sessions - gt issue set/clear: agents update their current issue - gt status-line: internal command for tmux refresh Status bar format: - Left: [rig/worker] role - Right: <issue> | <mail> | HH:MM 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
77
internal/tmux/theme.go
Normal file
77
internal/tmux/theme.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Package tmux provides theme support for Gas Town tmux sessions.
|
||||
package tmux
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
)
|
||||
|
||||
// Theme represents a tmux status bar color scheme.
|
||||
type Theme struct {
|
||||
Name string // Human-readable name
|
||||
BG string // Background color (hex or tmux color name)
|
||||
FG string // Foreground color (hex or tmux color name)
|
||||
}
|
||||
|
||||
// DefaultPalette is the curated set of distinct, professional color themes.
|
||||
// Each theme has good contrast and is visually distinct from others.
|
||||
var DefaultPalette = []Theme{
|
||||
{Name: "ocean", BG: "#1e3a5f", FG: "#e0e0e0"}, // Deep blue
|
||||
{Name: "forest", BG: "#2d5a3d", FG: "#e0e0e0"}, // Forest green
|
||||
{Name: "rust", BG: "#8b4513", FG: "#f5f5dc"}, // Rust/brown
|
||||
{Name: "plum", BG: "#4a3050", FG: "#e0e0e0"}, // Purple
|
||||
{Name: "slate", BG: "#4a5568", FG: "#e0e0e0"}, // Slate gray
|
||||
{Name: "ember", BG: "#b33a00", FG: "#f5f5dc"}, // Burnt orange
|
||||
{Name: "midnight", BG: "#1a1a2e", FG: "#c0c0c0"}, // Dark blue-black
|
||||
{Name: "wine", BG: "#722f37", FG: "#f5f5dc"}, // Burgundy
|
||||
{Name: "teal", BG: "#0d5c63", FG: "#e0e0e0"}, // Teal
|
||||
{Name: "copper", BG: "#6d4c41", FG: "#f5f5dc"}, // Warm brown
|
||||
}
|
||||
|
||||
// MayorTheme returns the special theme for the Mayor session.
|
||||
// Gold/dark to distinguish it from rig themes.
|
||||
func MayorTheme() Theme {
|
||||
return Theme{Name: "mayor", BG: "#3d3200", FG: "#ffd700"}
|
||||
}
|
||||
|
||||
// GetThemeByName finds a theme by name from the default palette.
|
||||
// Returns nil if not found.
|
||||
func GetThemeByName(name string) *Theme {
|
||||
for _, t := range DefaultPalette {
|
||||
if t.Name == name {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AssignTheme picks a theme for a rig based on its name.
|
||||
// Uses consistent hashing so the same rig always gets the same color.
|
||||
func AssignTheme(rigName string) Theme {
|
||||
return AssignThemeFromPalette(rigName, DefaultPalette)
|
||||
}
|
||||
|
||||
// AssignThemeFromPalette picks a theme using a custom palette.
|
||||
func AssignThemeFromPalette(rigName string, palette []Theme) Theme {
|
||||
if len(palette) == 0 {
|
||||
return DefaultPalette[0]
|
||||
}
|
||||
h := fnv.New32a()
|
||||
h.Write([]byte(rigName))
|
||||
idx := int(h.Sum32()) % len(palette)
|
||||
return palette[idx]
|
||||
}
|
||||
|
||||
// Style returns the tmux status-style string for this theme.
|
||||
func (t Theme) Style() string {
|
||||
return fmt.Sprintf("bg=%s,fg=%s", t.BG, t.FG)
|
||||
}
|
||||
|
||||
// ListThemeNames returns the names of all themes in the default palette.
|
||||
func ListThemeNames() []string {
|
||||
names := make([]string, len(DefaultPalette))
|
||||
for i, t := range DefaultPalette {
|
||||
names[i] = t.Name
|
||||
}
|
||||
return names
|
||||
}
|
||||
127
internal/tmux/theme_test.go
Normal file
127
internal/tmux/theme_test.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package tmux
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAssignTheme_Deterministic(t *testing.T) {
|
||||
// Same rig name should always get same theme
|
||||
theme1 := AssignTheme("gastown")
|
||||
theme2 := AssignTheme("gastown")
|
||||
|
||||
if theme1.Name != theme2.Name {
|
||||
t.Errorf("AssignTheme not deterministic: got %s and %s for same input", theme1.Name, theme2.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignTheme_Distribution(t *testing.T) {
|
||||
// Different rig names should (mostly) get different themes
|
||||
// With 10 themes and good hashing, collisions should be rare
|
||||
rigs := []string{"gastown", "beads", "myproject", "frontend", "backend", "api", "web", "mobile"}
|
||||
themes := make(map[string]int)
|
||||
|
||||
for _, rig := range rigs {
|
||||
theme := AssignTheme(rig)
|
||||
themes[theme.Name]++
|
||||
}
|
||||
|
||||
// We should have at least 4 different themes for 8 rigs
|
||||
if len(themes) < 4 {
|
||||
t.Errorf("Poor distribution: only %d different themes for %d rigs", len(themes), len(rigs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetThemeByName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want bool
|
||||
}{
|
||||
{"ocean", true},
|
||||
{"forest", true},
|
||||
{"nonexistent", false},
|
||||
{"", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
theme := GetThemeByName(tt.name)
|
||||
got := theme != nil
|
||||
if got != tt.want {
|
||||
t.Errorf("GetThemeByName(%q) = %v, want %v", tt.name, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestThemeStyle(t *testing.T) {
|
||||
theme := Theme{Name: "test", BG: "#1e3a5f", FG: "#e0e0e0"}
|
||||
want := "bg=#1e3a5f,fg=#e0e0e0"
|
||||
got := theme.Style()
|
||||
|
||||
if got != want {
|
||||
t.Errorf("Theme.Style() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMayorTheme(t *testing.T) {
|
||||
theme := MayorTheme()
|
||||
|
||||
if theme.Name != "mayor" {
|
||||
t.Errorf("MayorTheme().Name = %q, want %q", theme.Name, "mayor")
|
||||
}
|
||||
|
||||
// Mayor should have distinct gold/dark colors
|
||||
if theme.BG == "" || theme.FG == "" {
|
||||
t.Error("MayorTheme() has empty colors")
|
||||
}
|
||||
}
|
||||
|
||||
func TestListThemeNames(t *testing.T) {
|
||||
names := ListThemeNames()
|
||||
|
||||
if len(names) != len(DefaultPalette) {
|
||||
t.Errorf("ListThemeNames() returned %d names, want %d", len(names), len(DefaultPalette))
|
||||
}
|
||||
|
||||
// Check that known themes are in the list
|
||||
found := make(map[string]bool)
|
||||
for _, name := range names {
|
||||
found[name] = true
|
||||
}
|
||||
|
||||
for _, want := range []string{"ocean", "forest", "rust"} {
|
||||
if !found[want] {
|
||||
t.Errorf("ListThemeNames() missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultPaletteHasDistinctColors(t *testing.T) {
|
||||
// Ensure no duplicate colors in the palette
|
||||
bgColors := make(map[string]string)
|
||||
for _, theme := range DefaultPalette {
|
||||
if existing, ok := bgColors[theme.BG]; ok {
|
||||
t.Errorf("Duplicate BG color %s used by %s and %s", theme.BG, existing, theme.Name)
|
||||
}
|
||||
bgColors[theme.BG] = theme.Name
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignThemeFromPalette_EmptyPalette(t *testing.T) {
|
||||
// Empty palette should return first default theme
|
||||
theme := AssignThemeFromPalette("test", []Theme{})
|
||||
if theme.Name != DefaultPalette[0].Name {
|
||||
t.Errorf("AssignThemeFromPalette with empty palette = %q, want %q", theme.Name, DefaultPalette[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignThemeFromPalette_CustomPalette(t *testing.T) {
|
||||
custom := []Theme{
|
||||
{Name: "custom1", BG: "#111", FG: "#fff"},
|
||||
{Name: "custom2", BG: "#222", FG: "#fff"},
|
||||
}
|
||||
|
||||
// Should only return themes from custom palette
|
||||
theme := AssignThemeFromPalette("test", custom)
|
||||
if theme.Name != "custom1" && theme.Name != "custom2" {
|
||||
t.Errorf("AssignThemeFromPalette returned %q, want one of custom themes", theme.Name)
|
||||
}
|
||||
}
|
||||
@@ -269,3 +269,62 @@ func (t *Tmux) GetSessionInfo(name string) (*SessionInfo, error) {
|
||||
Attached: parts[3] == "1",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ApplyTheme sets the status bar style for a session.
|
||||
func (t *Tmux) ApplyTheme(session string, theme Theme) error {
|
||||
_, err := t.run("set-option", "-t", session, "status-style", theme.Style())
|
||||
return err
|
||||
}
|
||||
|
||||
// SetStatusFormat configures the left side of the status bar.
|
||||
// Shows: [rig/worker] role
|
||||
func (t *Tmux) SetStatusFormat(session, rig, worker, role string) error {
|
||||
// Format: [gastown/Rictus] polecat
|
||||
var left string
|
||||
if rig == "" {
|
||||
// Mayor or other top-level agent
|
||||
left = fmt.Sprintf("[%s] %s ", worker, role)
|
||||
} else {
|
||||
left = fmt.Sprintf("[%s/%s] %s ", rig, worker, role)
|
||||
}
|
||||
|
||||
// Allow enough room for the identity
|
||||
if _, err := t.run("set-option", "-t", session, "status-left-length", "40"); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := t.run("set-option", "-t", session, "status-left", left)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetDynamicStatus configures the right side with dynamic content.
|
||||
// Uses a shell command that tmux calls periodically to get current status.
|
||||
func (t *Tmux) SetDynamicStatus(session string) error {
|
||||
// tmux calls this command every status-interval seconds
|
||||
// gt status-line reads env vars and mail to build the status
|
||||
right := fmt.Sprintf(`#(gt status-line --session=%s 2>/dev/null) %%H:%%M`, session)
|
||||
|
||||
if _, err := t.run("set-option", "-t", session, "status-right-length", "50"); err != nil {
|
||||
return err
|
||||
}
|
||||
// Set faster refresh for more responsive status
|
||||
if _, err := t.run("set-option", "-t", session, "status-interval", "5"); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := t.run("set-option", "-t", session, "status-right", right)
|
||||
return err
|
||||
}
|
||||
|
||||
// ConfigureGasTownSession applies full Gas Town theming to a session.
|
||||
// This is a convenience method that applies theme, status format, and dynamic status.
|
||||
func (t *Tmux) ConfigureGasTownSession(session string, theme Theme, rig, worker, role string) error {
|
||||
if err := t.ApplyTheme(session, theme); err != nil {
|
||||
return fmt.Errorf("applying theme: %w", err)
|
||||
}
|
||||
if err := t.SetStatusFormat(session, rig, worker, role); err != nil {
|
||||
return fmt.Errorf("setting status format: %w", err)
|
||||
}
|
||||
if err := t.SetDynamicStatus(session); err != nil {
|
||||
return fmt.Errorf("setting dynamic status: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user