-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-layout.go
More file actions
244 lines (213 loc) · 6.37 KB
/
Copy pathui-layout.go
File metadata and controls
244 lines (213 loc) · 6.37 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
package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
)
// Theme represents a set of colors and styles for the UI
type Theme struct {
Name string
Bg gocui.Attribute
Fg gocui.Attribute
HighlightBg gocui.Attribute
HighlightFg gocui.Attribute
Action gocui.Attribute
BorderBg gocui.Attribute
BorderFg gocui.Attribute
BorderFont gocui.Attribute
UseRoundedBorders bool
}
// Available themes
var (
// Dark theme with orange-yellow highlights (new theme)
darkTheme = Theme{
Name: "Dark",
Bg: gocui.NewRGBColor(0x14, 0x14, 0x14), // #141414
Fg: gocui.NewRGBColor(0xc6, 0xc6, 0xc6), // #c6c6c6
HighlightBg: gocui.NewRGBColor(0x1b, 0x1b, 0x1b), // #1b1b1b
HighlightFg: gocui.NewRGBColor(0xff, 0xff, 0xff), // #ffffff
Action: gocui.NewRGBColor(0xff, 0xaf, 0x00), // #ffaf00 - orange-yellow for highlighting actions
BorderBg: gocui.NewRGBColor(0x14, 0x14, 0x14), // #141414 - match overall bg
BorderFg: gocui.NewRGBColor(0x44, 0x44, 0x44), // #444444
BorderFont: gocui.NewRGBColor(0x66, 0x66, 0x66), // #666666
UseRoundedBorders: true,
}
// Classic blue theme (original theme)
classicTheme = Theme{
Name: "Classic",
Bg: gocui.NewRGBColor(0, 0, 200), // Blue
Fg: gocui.NewRGBColor(255, 255, 255), // White
HighlightBg: gocui.NewRGBColor(0, 110, 150), // highlight
HighlightFg: gocui.NewRGBColor(255, 255, 255), // White
Action: gocui.NewRGBColor(0, 255, 255), // Cyan
BorderBg: gocui.NewRGBColor(0, 0, 200), // Blue
BorderFg: gocui.NewRGBColor(200, 200, 200), // Light gray
BorderFont: gocui.NewRGBColor(200, 200, 200), // Light gray
UseRoundedBorders: false,
}
// Current active theme
activeTheme = classicTheme
// Custom border runes for rounded corners
customFrameRunes = []rune{'─', '│', '╭', '╮', '╰', '╯', '├', '┤', '┬', '┴', '┼'}
// UI color variables that will be set based on the active theme
uiColorBg gocui.Attribute
uiColorFg gocui.Attribute
uiColorHighlightBg gocui.Attribute
uiColorHighlightFg gocui.Attribute
uiColorAction gocui.Attribute
uiColorBorderBg gocui.Attribute
uiColorBorderFg gocui.Attribute
uiColorBorderFont gocui.Attribute
)
// applyTheme sets the UI colors based on the active theme
func applyTheme() {
uiColorBg = activeTheme.Bg
uiColorFg = activeTheme.Fg
uiColorHighlightBg = activeTheme.HighlightBg
uiColorHighlightFg = activeTheme.HighlightFg
uiColorAction = activeTheme.Action
uiColorBorderBg = activeTheme.BorderBg
uiColorBorderFg = activeTheme.BorderFg
uiColorBorderFont = activeTheme.BorderFont
}
// switchTheme toggles between dark and classic themes
func switchTheme(g *gocui.Gui) error {
// Save current state before switching themes
v2, err := g.View("v2")
if err != nil {
return err
}
_, cy := v2.Cursor()
currentView := g.CurrentView()
currentViewName := ""
if currentView != nil {
currentViewName = currentView.Name()
}
// Toggle between themes
if activeTheme.Name == darkTheme.Name {
activeTheme = classicTheme
} else {
activeTheme = darkTheme
}
// Apply the new theme
applyTheme()
// Set ASCII mode based on theme
//g.ASCII = !activeTheme.UseRoundedBorders
// Delete all views to recreate them with new theme colors
/*
viewNames := []string{"v1", "v2", "v3", "v4", "v5"}
for _, name := range viewNames {
g.DeleteView(name)
}
*/
// Refresh all views to update colors
g.Update(func(g *gocui.Gui) error {
// Recreate all views with the new theme
if err := layout(g); err != nil {
return err
}
// Refresh all views with current content
if err := refreshAllViews(g, nil); err != nil {
return err
}
// Restore cursor position in v2
v2, err := g.View("v2")
if err != nil {
return err
}
// Set cursor position
if err := v2.SetCursor(0, cy); err != nil {
// If cursor position is out of bounds, set it to the first line
v2.SetCursor(0, 0)
}
// Highlight the current line
v2.SetHighlight(cy, true)
// Restore current view
if currentViewName != "" {
g.SetCurrentView(currentViewName)
}
return nil
})
return nil
}
func layout(g *gocui.Gui) error {
// Apply the current theme colors before setting up views
applyTheme()
maxX, maxY := g.Size()
if v, err := g.SetView("v1", -1, -1, maxX, 1, 0); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Editable = false
v.Wrap = false
v.Frame = false
v.BgColor = uiColorHighlightBg // Apply line highlight bg to header
v.FgColor = uiColorFg
v.FrameRunes = customFrameRunes
fmt.Fprint(v, AppInfo)
}
if v, err := g.SetView("v2", 0, 1, maxX-20, 10, 0); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Wrap = false
v.Autoscroll = false
v.BgColor = uiColorBg
v.FgColor = uiColorFg
v.FrameColor = uiColorBorderFg
v.TitleColor = uiColorBorderFont
v.Editable = false
v.Highlight = true
v.SelBgColor = uiColorHighlightBg
v.SelFgColor = uiColorHighlightFg
v.FrameRunes = customFrameRunes
refreshV2Conversations(g, v)
g.SetCurrentView("v2")
}
if v, err := g.SetView("v3", 0, 10, maxX-20, maxY-6, 1); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Conversation"
v.Wrap = false
v.Autoscroll = true
v.BgColor = uiColorBg
v.FgColor = uiColorFg
v.FrameColor = uiColorBorderFg
v.TitleColor = uiColorBorderFont
v.FrameRunes = customFrameRunes
v.Editable = false
refreshV3(g, 0)
}
if v, err := g.SetView("v4", maxX-29, 1, maxX-1, maxY-6, 4); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Relays"
v.Editable = false
v.Wrap = false
v.Autoscroll = true
v.BgColor = uiColorBg
v.FgColor = uiColorFg
v.FrameColor = uiColorBorderFg
v.TitleColor = uiColorBorderFont
v.FrameRunes = customFrameRunes
refreshV4(g, 0)
}
if v, err := g.SetView("v5", 0, maxY-6, maxX-1, maxY-1, 1); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = "Keybinds"
v.Editable = false
v.Autoscroll = true
v.Frame = true
v.BgColor = uiColorBg
v.FgColor = uiColorFg
v.FrameColor = uiColorBorderFg
v.TitleColor = uiColorBorderFont
v.FrameRunes = customFrameRunes
// Initialize keybinds view
updateKeybindsView(g)
}
return nil
}