package main import ( "fmt" "io" "strings" ) const ( colorReset = "\033[0m" colorGreen = "\033[32m" colorYellow = "\033[33m" colorRed = "\033[31m" colorGray = "\033[90m" colorBold = "\033[1m" ) // DisplaySessions writes a formatted list of sessions to w. func DisplaySessions(w io.Writer, sessions []Session, noColor bool) { if len(sessions) == 0 { fmt.Fprintln(w, "No active Claude Code sessions found.") return } for i, s := range sessions { if i > 0 { fmt.Fprintln(w) } stateLabel := stateColor(s.State, noColor) + s.State.String() + resetIfColor(noColor) branch := "" if s.GitBranch != "" { branch = " (" + s.GitBranch + ")" } worktreeInfo := "" if s.Worktree != "" && s.Worktree != s.CwdPath { worktreeInfo = " [worktree: " + s.Worktree + "]" } fmt.Fprintf(w, "[%s] %s%s%s\n", stateLabel, s.CwdPath, branch, worktreeInfo) if s.Preview != "" { lines := strings.Split(s.Preview, "\n") for _, line := range lines { fmt.Fprintf(w, " %s\n", line) } } } } func stateColor(state SessionState, noColor bool) string { if noColor { return "" } switch state { case Working: return colorGreen case NeedsInput: return colorYellow case Idle: return colorGray default: return colorGray } } func resetIfColor(noColor bool) string { if noColor { return "" } return colorReset }