package main import ( "fmt" "strings" ) // I3BarBlock represents a single block in the i3bar protocol. type I3BarBlock struct { FullText string `json:"full_text"` ShortText string `json:"short_text,omitempty"` Color string `json:"color"` Name string `json:"name"` Markup string `json:"markup,omitempty"` } // formatI3BarBlocks builds the vmux status block for i3bar from session data. func formatI3BarBlocks(sessions []SessionInfo) []I3BarBlock { if len(sessions) == 0 { return []I3BarBlock{{FullText: "vmux: no sessions", Color: "#00ff00", Name: "vmux"}} } hasWaiting := false parts := make([]string, 0, len(sessions)) for _, s := range sessions { name := shortName(s) switch s.State { case "Needs Input": parts = append(parts, name+"[!]") hasWaiting = true case "Working": parts = append(parts, name+"[W]") case "Idle": parts = append(parts, name+"[I]") } } var text string if !hasWaiting { text = fmt.Sprintf("vmux: all working (%d)", len(sessions)) } else { text = "vmux: " + strings.Join(parts, " ") } color := "#00ff00" if hasWaiting { color = "#ff0000" } return []I3BarBlock{{FullText: text, Color: color, Name: "vmux"}} }