forked from davidroman0O/vtable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyling.go
More file actions
300 lines (273 loc) · 8.85 KB
/
styling.go
File metadata and controls
300 lines (273 loc) · 8.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package vtable
import (
"github.com/charmbracelet/lipgloss"
)
// Theme defines a complete color and style theme for the table
type Theme struct {
Name string
// Basic colors
Primary string
Secondary string
Accent string
Background string
Foreground string
// State colors
Selected string
Hover string
Active string
Disabled string
Error string
Warning string
Success string
Info string
// Border styles
BorderStyle lipgloss.Border
BorderColor string
HeaderBorder lipgloss.Border
HeaderBorderColor string
BorderChars BorderCharacters
// Text styles
HeaderStyle lipgloss.Style
CellStyle lipgloss.Style
SelectedStyle lipgloss.Style
CursorStyle lipgloss.Style
DisabledStyle lipgloss.Style
// Table-specific styles
SelectedRowStyle lipgloss.Style
RowStyle lipgloss.Style
RowEvenStyle lipgloss.Style
RowOddStyle lipgloss.Style
HeaderBorderStyle lipgloss.Style
// Status indicator styles
LoadingStyle lipgloss.Style
ErrorStyle lipgloss.Style
// Animation preferences
AnimationDuration string
ReducedMotion bool
}
// BorderCharacters defines the characters used for table borders
type BorderCharacters struct {
Horizontal string // ─
Vertical string // │
TopLeft string // ┌
TopRight string // ┐
BottomLeft string // └
BottomRight string // ┘
LeftT string // ├
RightT string // ┤
TopT string // ┬
BottomT string // ┴
Cross string // ┼
}
// DefaultBorderCharacters returns standard box drawing characters for borders
func DefaultBorderCharacters() BorderCharacters {
return BorderCharacters{
Horizontal: "─",
Vertical: "│",
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "└",
BottomRight: "┘",
LeftT: "├",
RightT: "┤",
TopT: "┬",
BottomT: "┴",
Cross: "┼",
}
}
// RoundedBorderCharacters returns rounded box drawing characters for borders
func RoundedBorderCharacters() BorderCharacters {
return BorderCharacters{
Horizontal: "─",
Vertical: "│",
TopLeft: "╭",
TopRight: "╮",
BottomLeft: "╰",
BottomRight: "╯",
LeftT: "├",
RightT: "┤",
TopT: "┬",
BottomT: "┴",
Cross: "┼",
}
}
// ThickBorderCharacters returns thick box drawing characters for borders
func ThickBorderCharacters() BorderCharacters {
return BorderCharacters{
Horizontal: "━",
Vertical: "┃",
TopLeft: "┏",
TopRight: "┓",
BottomLeft: "┗",
BottomRight: "┛",
LeftT: "┣",
RightT: "┫",
TopT: "┳",
BottomT: "┻",
Cross: "╋",
}
}
// DoubleBorderCharacters returns double line box drawing characters for borders
func DoubleBorderCharacters() BorderCharacters {
return BorderCharacters{
Horizontal: "═",
Vertical: "║",
TopLeft: "╔",
TopRight: "╗",
BottomLeft: "╚",
BottomRight: "╝",
LeftT: "╠",
RightT: "╣",
TopT: "╦",
BottomT: "╩",
Cross: "╬",
}
}
// AsciiBoxCharacters returns ASCII characters for borders, useful for terminals that don't support Unicode
func AsciiBoxCharacters() BorderCharacters {
return BorderCharacters{
Horizontal: "-",
Vertical: "|",
TopLeft: "+",
TopRight: "+",
BottomLeft: "+",
BottomRight: "+",
LeftT: "+",
RightT: "+",
TopT: "+",
BottomT: "+",
Cross: "+",
}
}
// DefaultTheme returns a sensible default theme
func DefaultTheme() *Theme {
return &Theme{
Name: "default",
Primary: "#007ACC",
Secondary: "#666666",
Accent: "#FF6B35",
Background: "#FFFFFF",
Foreground: "#000000",
Selected: "#E6F3FF",
Hover: "#F0F8FF",
Active: "#B8DFFF",
Disabled: "#CCCCCC",
Error: "#FF4444",
Warning: "#FFA500",
Success: "#00AA00",
Info: "#0088CC",
BorderStyle: lipgloss.NormalBorder(),
BorderColor: "#CCCCCC",
HeaderBorder: lipgloss.NormalBorder(),
HeaderBorderColor: "#999999",
BorderChars: DefaultBorderCharacters(),
HeaderStyle: lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#333333")),
CellStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#000000")),
SelectedStyle: lipgloss.NewStyle().Background(lipgloss.Color("#E6F3FF")),
CursorStyle: lipgloss.NewStyle().Background(lipgloss.Color("#007ACC")).Foreground(lipgloss.Color("#FFFFFF")),
DisabledStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#CCCCCC")),
SelectedRowStyle: lipgloss.NewStyle().Background(lipgloss.Color("#E6F3FF")).Bold(true),
RowStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#000000")),
RowEvenStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#000000")),
RowOddStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#333333")),
HeaderBorderStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#999999")),
LoadingStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#666666")).Italic(true),
ErrorStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#FF4444")),
AnimationDuration: "200ms",
ReducedMotion: false,
}
}
// DarkTheme returns a dark theme variant
func DarkTheme() *Theme {
theme := DefaultTheme()
theme.Name = "dark"
theme.Background = "#1E1E1E"
theme.Foreground = "#FFFFFF"
theme.Primary = "#4A9EFF"
theme.Secondary = "#999999"
theme.Selected = "#2D3748"
theme.Hover = "#374151"
theme.Active = "#4A5568"
theme.BorderColor = "#4A5568"
theme.HeaderBorderColor = "#6B7280"
theme.HeaderStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#E5E5E5"))
theme.CellStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF"))
theme.SelectedStyle = lipgloss.NewStyle().Background(lipgloss.Color("#2D3748"))
theme.CursorStyle = lipgloss.NewStyle().Background(lipgloss.Color("#4A9EFF")).Foreground(lipgloss.Color("#000000"))
theme.DisabledStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#6B7280"))
return theme
}
// HighContrastTheme returns a high contrast theme for accessibility
func HighContrastTheme() *Theme {
theme := DefaultTheme()
theme.Name = "high-contrast"
theme.Background = "#FFFFFF"
theme.Foreground = "#000000"
theme.Primary = "#000000"
theme.Secondary = "#000000"
theme.Selected = "#000000"
theme.Hover = "#EEEEEE"
theme.Active = "#CCCCCC"
theme.BorderColor = "#000000"
theme.HeaderBorderColor = "#000000"
theme.HeaderStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#000000")).Background(lipgloss.Color("#FFFFFF"))
theme.CellStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#000000"))
theme.SelectedStyle = lipgloss.NewStyle().Background(lipgloss.Color("#000000")).Foreground(lipgloss.Color("#FFFFFF"))
theme.CursorStyle = lipgloss.NewStyle().Background(lipgloss.Color("#000000")).Foreground(lipgloss.Color("#FFFFFF")).Bold(true)
theme.DisabledStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#666666"))
return theme
}
// StyleState contains rendering state information for applying themes
type StyleState struct {
Selected bool
IsCursor bool
IsHeader bool
Disabled bool
Loading bool
Error error
IsHovered bool
IsActive bool
}
// ApplyTheme applies a theme to create a style for a specific state
func (t *Theme) ApplyTheme(state StyleState) lipgloss.Style {
base := t.CellStyle
switch {
case state.Error != nil:
base = base.Copy().Inherit(t.ErrorStyle)
case state.Loading:
base = base.Copy().Inherit(t.LoadingStyle)
case state.Disabled:
base = base.Copy().Inherit(t.DisabledStyle)
case state.IsCursor:
base = base.Copy().Inherit(t.CursorStyle)
case state.Selected:
base = base.Copy().Inherit(t.SelectedStyle)
case state.IsHeader:
base = base.Copy().Inherit(t.HeaderStyle)
}
return base
}
// ToStyleConfig converts a theme to a legacy StyleConfig
func (theme *Theme) ToStyleConfig() StyleConfig {
return StyleConfig{
BorderStyle: theme.BorderColor,
HeaderStyle: theme.HeaderStyle.String(),
RowStyle: theme.CellStyle.String(),
SelectedRowStyle: theme.SelectedStyle.String(),
}
}
// ThemeToStyleConfig converts a theme to a legacy StyleConfig (global function)
func ThemeToStyleConfig(theme *Theme) StyleConfig {
return theme.ToStyleConfig()
}
// FromStyleConfig creates a Theme from a legacy StyleConfig
func FromStyleConfig(style StyleConfig) *Theme {
theme := DefaultTheme()
// We'll use simple conversion since StyleConfig is limited
theme.BorderStyle = lipgloss.NormalBorder()
theme.HeaderBorder = lipgloss.NormalBorder()
theme.HeaderStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(style.HeaderStyle))
theme.CellStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(style.RowStyle))
theme.SelectedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(style.SelectedRowStyle))
return theme
}