62159
Sy
symb / files
symb / internal / tui / styles.go
3.3 KB
1package tui 2 3import ( 4 "image/color" 5 6 "charm.land/lipgloss/v2" 7 "github.com/xonecas/symb/internal/highlight" 8) 9 10// palette and syntaxThemeName are computed once when the TUI is initialised. 11var ( 12 palette highlight.Palette 13 syntaxThemeName string 14) 15 16// Semantic color palette — derived from the active Chroma syntax theme. 17// Grayscale ramp is a linear interpolation from theme bg to fg. 18// Accent is the most saturated token color; error is lerped from the theme Error token. 19var ( 20 ColorHighlight color.Color 21 ColorBg color.Color 22 ColorFg color.Color 23 ColorMuted color.Color 24 ColorDim color.Color 25 ColorBorder color.Color 26 ColorSurface color.Color 27 ColorError color.Color 28 ColorWarning color.Color 29 ColorLinkBg color.Color 30) 31 32// initTheme sets the palette and color vars from the given Chroma theme name. 33// Must be called before DefaultStyles or any Color* variable is used. 34func initTheme(syntaxTheme string) { 35 syntaxThemeName = syntaxTheme 36 palette = highlight.ThemePalette(syntaxTheme) 37 ColorHighlight = lipgloss.Color(palette.Accent) 38 ColorBg = lipgloss.Color(palette.Bg) 39 ColorFg = lipgloss.Color(palette.Fg) 40 ColorMuted = lipgloss.Color(palette.Muted) 41 ColorDim = lipgloss.Color(palette.Dim) 42 ColorBorder = lipgloss.Color(palette.Border) 43 ColorSurface = lipgloss.Color(palette.Accent) 44 ColorError = lipgloss.Color(palette.Error) 45 ColorWarning = lipgloss.Color(palette.Error) // same source, context differentiates 46 ColorLinkBg = lipgloss.Color(palette.LinkBg) 47} 48 49// Styles holds all pre-built lipgloss styles used across the TUI. 50// Constructed once, stored in Model, avoids repeated allocations. 51type Styles struct { 52 // Text 53 Text lipgloss.Style // Primary text 54 Muted lipgloss.Style // Reasoning, secondary 55 Dim lipgloss.Style // Timestamps, placeholders 56 Error lipgloss.Style // Errors 57 Warning lipgloss.Style // Warnings 58 ToolCall lipgloss.Style // Tool call arrows 59 ToolArrow lipgloss.Style // Tool arrow symbol 60 61 // Layout 62 Border lipgloss.Style // Divider, separator lines 63 Selection lipgloss.Style // Mouse text selection highlight 64 BgFill lipgloss.Style // Background fill for empty areas 65 66 // Clickable 67 Clickable lipgloss.Style // Clickable text background/foreground 68 69 // Status bar 70 StatusText lipgloss.Style // Status bar text 71 StatusAdd lipgloss.Style // Statusbar added count 72 StatusMod lipgloss.Style // Statusbar modified count 73 StatusDel lipgloss.Style // Statusbar removed count 74 75} 76 77// DefaultStyles builds the complete style set. 78func DefaultStyles() Styles { 79 bg := lipgloss.NewStyle().Background(ColorBg) 80 return Styles{ 81 Text: bg.Foreground(ColorFg), 82 Muted: bg.Foreground(ColorMuted), 83 Dim: bg.Foreground(ColorDim), 84 Error: bg.Foreground(ColorError), 85 Warning: bg.Foreground(ColorWarning), 86 ToolCall: bg.Foreground(ColorDim), 87 ToolArrow: bg.Foreground(ColorMuted), 88 89 Border: bg.Foreground(ColorBorder), 90 Selection: lipgloss.NewStyle().Background(ColorSurface).Foreground(ColorBg), 91 BgFill: bg, 92 93 Clickable: lipgloss.NewStyle().Background(ColorLinkBg).Foreground(ColorHighlight), 94 95 StatusText: bg.Foreground(ColorDim), 96 StatusAdd: bg.Foreground(lipgloss.Color("2")), 97 StatusMod: bg.Foreground(lipgloss.Color("3")), 98 StatusDel: bg.Foreground(lipgloss.Color("1")), 99 } 100}