1package main
  2
  3// Color palette and theme used by the editor. Maps semantic color names (like
  4// ColorNormalMode) to specific terminal attributes (foreground and background).
  5
  6import "github.com/nsf/termbox-go"
  7
  8// To see available colors execute `qwe -colors`.
  9
 10// Color represents a pair of foreground and background terminal attributes.
 11type Color struct {
 12	Background termbox.Attribute
 13	Foreground termbox.Attribute
 14}
 15
 16// ColorName is an enum-like type for semantic color identifiers.
 17type ColorName int
 18
 19const (
 20	ColorDefault ColorName = iota // Default terminal colors.
 21	ColorSourceString
 22	ColorSourceKeyword
 23	ColorSourceNumber
 24	ColorSourceComment
 25	ColorSourceMacro
 26	ColorSourceOther
 27
 28	ColorAnnotationTodo  // Highlighting for TODO comments.
 29	ColorAnnotationFixme // Highlighting for FIXME comments.
 30
 31	ColorStatusBar           // Main status bar at the bottom.
 32	ColorDebugWindow         // Overlay window for logs/debug info.
 33	ColorNormalMode          // Status bar indicator for Normal mode.
 34	ColorInsertMode          // Status bar indicator for Insert mode.
 35	ColorHighlightedLine     // Background for the line where the cursor is.
 36	ColorVisualModeSelection // Selection color in all visual modes.
 37	ColorVisualMode          // Status bar indicator for Visual mode.
 38	ColorSearchMatch         // Highlighting for found search terms.
 39	ColorReplaceMatch        // Highlighting for replacement targets.
 40	ColorCursor              // The color of the cursor itself.
 41
 42	ColorGutterLineNumber   // Line numbers in the left gutter.
 43	ColorGutterSignError    // LSP error icons in the gutter.
 44	ColorGutterSignWarning  // LSP warning icons in the gutter.
 45	ColorGutterSignInfo     // LSP info icons in the gutter.
 46	ColorGutterSignHint     // LSP hint icons in the gutter.
 47	ColorFuzzyResult        // Plain text in fuzzy finder results.
 48	ColorFuzzySelected      // Highlighted item in fuzzy finder.
 49	ColorEmptyLineMarker    // The '~' marker for lines beyond EOF.
 50	ColorDebugTitle         // Header for the debug window.
 51	ColorDiagSummaryError   // Error count in the status bar.
 52	ColorDiagSummaryWarning // Warning count in the status bar.
 53	ColorFuzzyModeBuffers   // Indicator that fuzzy finder is searching buffers.
 54	ColorFuzzyModeFiles     // Indicator that fuzzy finder is searching files.
 55	ColorFuzzyModeWarnings  // Indicator that fuzzy finder is searching diagnostics.
 56
 57	// Colors for Tree-sitter syntax highlighting.
 58	ColorTSFunction
 59	ColorTSVariable
 60	ColorTSType
 61	ColorTSString
 62	ColorTSKeyword
 63	ColorTSComment
 64	ColorTSNumber
 65	ColorTSBoolean
 66	ColorTSNull
 67	ColorTSProperty
 68	ColorTSTag
 69	ColorTSAttribute
 70	ColorTSConstant
 71
 72	// External service status indicators.
 73	ColorLSPStatusConnected
 74	ColorLSPStatusDisconnected
 75	ColorOllamaStatusConnected
 76	ColorOllamaStatusDisconnected
 77
 78	ColorHoverWindow // LSP hover information popup.
 79	ColorAutocompleteWindow
 80	ColorAutocompleteSelected
 81)
 82
 83// Theme maps each ColorName to its actual visual attributes.
 84var Theme = map[ColorName]Color{
 85	ColorDefault: {Background: termbox.ColorDefault, Foreground: termbox.Attribute(254)},
 86
 87	// Annotations
 88	ColorAnnotationTodo:  {Background: termbox.Attribute(221), Foreground: termbox.Attribute(1)},
 89	ColorAnnotationFixme: {Background: termbox.Attribute(142), Foreground: termbox.Attribute(1)},
 90
 91	// Status bar
 92	ColorStatusBar: {Background: termbox.Attribute(250), Foreground: termbox.Attribute(1)},
 93
 94	// Debug window
 95	ColorDebugWindow: {Background: termbox.Attribute(19), Foreground: termbox.Attribute(16)},
 96
 97	// UI colors
 98	ColorNormalMode:          {Background: termbox.Attribute(250), Foreground: termbox.Attribute(1)},
 99	ColorInsertMode:          {Background: termbox.Attribute(58), Foreground: termbox.Attribute(255)},
100	ColorHighlightedLine:     {Background: termbox.Attribute(235), Foreground: termbox.ColorDefault},
101	ColorVisualModeSelection: {Background: termbox.Attribute(46), Foreground: termbox.Attribute(1)},
102	ColorVisualMode:          {Background: termbox.Attribute(30), Foreground: termbox.Attribute(16)},
103	ColorSearchMatch:         {Background: termbox.Attribute(166), Foreground: termbox.Attribute(1)},
104	ColorReplaceMatch:        {Background: termbox.Attribute(221), Foreground: termbox.Attribute(1)},
105	ColorCursor:              {Background: termbox.Attribute(252), Foreground: termbox.ColorWhite},
106
107	ColorGutterLineNumber:  {Background: termbox.ColorDefault, Foreground: termbox.Attribute(244)},
108	ColorGutterSignError:   {Background: termbox.Attribute(125), Foreground: termbox.Attribute(16)},
109	ColorGutterSignWarning: {Background: termbox.Attribute(221), Foreground: termbox.Attribute(1)},
110	ColorGutterSignInfo:    {Background: termbox.Attribute(221), Foreground: termbox.Attribute(1)},
111	ColorGutterSignHint:    {Background: termbox.Attribute(221), Foreground: termbox.Attribute(1)},
112
113	ColorFuzzyResult:       {Background: termbox.ColorDefault, Foreground: termbox.Attribute(254)},
114	ColorFuzzySelected:     {Background: termbox.Attribute(236), Foreground: termbox.Attribute(254)},
115	ColorFuzzyModeBuffers:  {Background: termbox.Attribute(125), Foreground: termbox.Attribute(255)},
116	ColorFuzzyModeFiles:    {Background: termbox.Attribute(125), Foreground: termbox.Attribute(255)},
117	ColorFuzzyModeWarnings: {Background: termbox.Attribute(33), Foreground: termbox.Attribute(255)},
118
119	ColorEmptyLineMarker: {Background: termbox.ColorDefault, Foreground: termbox.Attribute(244)},
120
121	ColorDebugTitle:         {Background: termbox.Attribute(19), Foreground: termbox.Attribute(215)},
122	ColorDiagSummaryError:   {Background: termbox.ColorDefault, Foreground: termbox.Attribute(166)},
123	ColorDiagSummaryWarning: {Background: termbox.ColorDefault, Foreground: termbox.Attribute(221)},
124
125	// Tree-sitter
126	ColorTSFunction:  {Background: termbox.ColorDefault, Foreground: termbox.Attribute(3)},
127	ColorTSVariable:  {Background: termbox.ColorDefault, Foreground: termbox.Attribute(255)},
128	ColorTSType:      {Background: termbox.ColorDefault, Foreground: termbox.Attribute(112)},
129	ColorTSString:    {Background: termbox.ColorDefault, Foreground: termbox.Attribute(37)},
130	ColorTSKeyword:   {Background: termbox.ColorDefault, Foreground: termbox.Attribute(178)},
131	ColorTSComment:   {Background: termbox.ColorDefault, Foreground: termbox.Attribute(244)},
132	ColorTSNumber:    {Background: termbox.ColorDefault, Foreground: termbox.Attribute(135)},
133	ColorTSBoolean:   {Background: termbox.ColorDefault, Foreground: termbox.Attribute(2)},
134	ColorTSNull:      {Background: termbox.ColorDefault, Foreground: termbox.Attribute(135)},
135	ColorTSProperty:  {Background: termbox.ColorDefault, Foreground: termbox.Attribute(230)},
136	ColorTSTag:       {Background: termbox.ColorDefault, Foreground: termbox.Attribute(118)},
137	ColorTSAttribute: {Background: termbox.ColorDefault, Foreground: termbox.Attribute(215)},
138	ColorTSConstant:  {Background: termbox.ColorDefault, Foreground: termbox.Attribute(254)},
139
140	// Status bar indicators
141	ColorLSPStatusConnected:       {Background: termbox.Attribute(29), Foreground: termbox.Attribute(255)},
142	ColorLSPStatusDisconnected:    {Background: termbox.Attribute(239), Foreground: termbox.Attribute(255)},
143	ColorOllamaStatusConnected:    {Background: termbox.Attribute(131), Foreground: termbox.Attribute(255)},
144	ColorOllamaStatusDisconnected: {Background: termbox.Attribute(239), Foreground: termbox.Attribute(255)},
145
146	ColorHoverWindow: {Background: termbox.Attribute(253), Foreground: termbox.Attribute(1)},
147
148	ColorAutocompleteWindow:   {Background: termbox.Attribute(253), Foreground: termbox.Attribute(1)},
149	ColorAutocompleteSelected: {Background: termbox.Attribute(239), Foreground: termbox.Attribute(255)},
150}
151
152// GetThemeColor returns the foreground and background attributes for a given semantic name.
153func GetThemeColor(name ColorName) (termbox.Attribute, termbox.Attribute) {
154	if c, ok := Theme[name]; ok {
155		return c.Foreground, c.Background
156	}
157	// Fallback to default if name is not found.
158	return termbox.ColorDefault, termbox.ColorDefault
159}