-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
353 lines (323 loc) · 6.38 KB
/
config.go
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package main
import (
"fmt"
"os"
"strings"
"github.com/gdamore/tcell/v2"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
var strColors = []string{
"black", // 0
"maroon", // 1
"green", // 2
"olive", // 3
"navy", // 4
"purple", // 5
"teal", // 6
"silver", // 7
"gray", // 8
"red", // 9
"lime", // 10
"yellow", // 11
"blue", // 12
"fuchsia", // 13
"aqua", // 14
"white", // 15
"aliceblue",
"antiquewhite",
"aquamarine",
"azure",
"beige",
"bisque",
"blanchedalmond",
"blueviolet",
"brown",
"burlywood",
"cadetblue",
"chartreuse",
"chocolate",
"coral",
"cornflowerblue",
"cornsilk",
"crimson",
"darkblue",
"darkcyan",
"darkgoldenrod",
"darkgray",
"darkgreen",
"darkkhaki",
"darkmagenta",
"darkolivegreen",
"darkorange",
"darkorchid",
"darkred",
"darksalmon",
"darkseagreen",
"darkslateblue",
"darkslategray",
"darkturquoise",
"darkviolet",
"deeppink",
"deepskyblue",
"dimgray",
"dodgerblue",
"firebrick",
"floralwhite",
"forestgreen",
"gainsboro",
"ghostwhite",
"gold",
"goldenrod",
"greenyellow",
"honeydew",
"hotpink",
"indianred",
"indigo",
"ivory",
"khaki",
"lavender",
"lavenderblush",
"lawngreen",
"lemonchiffon",
"lightblue",
"lightcoral",
"lightcyan",
"lightgoldenrodyellow",
"lightgray",
"lightgreen",
"lightpink",
"lightsalmon",
"lightseagreen",
"lightskyblue",
"lightslategray",
"lightsteelblue",
"lightyellow",
"limegreen",
"linen",
"mediumaquamarine",
"mediumblue",
"mediumorchid",
"mediumpurple",
"mediumseagreen",
"mediumslateblue",
"mediumspringgreen",
"mediumturquoise",
"mediumvioletred",
"midnightblue",
"mintcream",
"mistyrose",
"moccasin",
"navajowhite",
"oldlace",
"olivedrab",
"orange",
"orangered",
"orchid",
"palegoldenrod",
"palegreen",
"paleturquoise",
"palevioletred",
"papayawhip",
"peachpuff",
"peru",
"pink",
"plum",
"powderblue",
"rebeccapurple",
"rosybrown",
"royalblue",
"saddlebrown",
"salmon",
"sandybrown",
"seagreen",
"seashell",
"sienna",
"skyblue",
"slateblue",
"slategray",
"snow",
"springgreen",
"steelblue",
"tan",
"thistle",
"tomato",
"turquoise",
"violet",
"wheat",
"whitesmoke",
"yellowgreen",
"grey",
"dimgrey",
"darkgrey",
"darkslategrey",
"lightgrey",
"lightslategrey",
"slategrey",
}
type Keys struct {
Breakpoint string
PageTop string
PageEnd string
LineUp string
LineDown string
PrevTab string
NextTab string
PrevSection string
NextSection string
SelectItem string
ToggleBreakpoint string
ClearBreakpoint string
}
type Colors struct {
BpFg int
BpActiveFg int
LineFg int
LineSelectedFg int
LineSelectedBg int
LineActiveFg int
LineActiveBg int
LineColumnBg int
VarTypeFg int
VarNameFg int
VarValueFg int
VarAddrFg int
ListHeaderFg int
ListExpand int
ListSelectedBg int
HeaderFg int
CodeHeaderFg int
NotifErrorFg int
NotifPromptFg int
NotifMsgFg int
MenuBg int
MenuFg int
MenuSelectedBg int
MenuSelectedFg int
}
type Icons struct {
Bp string
BpDisabled string
BpActive string
IndRunning string
IndStopped string
IndExitSuccess string
IndExitError string
}
type Config struct {
SyntaxHighlighter string
Keys Keys
Colors Colors
Icons Icons
}
var gConfig Config
func NewConfig() Config {
keyconf := Keys{
Breakpoint: "b",
PageTop: "g",
PageEnd: "G",
LineUp: "k",
LineDown: "j",
PrevTab: "h",
NextTab: "l",
PrevSection: "Backtab",
NextSection: "Tab",
SelectItem: "Enter",
ToggleBreakpoint: "d",
ClearBreakpoint: "D",
}
colorconf := Colors{
BpFg: 9,
BpActiveFg: 1,
LineFg: 15,
LineSelectedFg: 0,
LineSelectedBg: 15,
LineActiveFg: 0,
LineActiveBg: 6,
LineColumnBg: 0,
VarTypeFg: 6,
VarNameFg: 2,
VarValueFg: 15,
VarAddrFg: 8,
ListHeaderFg: 5,
ListExpand: 12,
ListSelectedBg: 0,
HeaderFg: 15,
CodeHeaderFg: 12,
NotifErrorFg: 1,
NotifPromptFg: 2,
NotifMsgFg: 15,
MenuBg: 7,
MenuFg: 0,
MenuSelectedBg: 15,
MenuSelectedFg: 0,
}
iconconf := Icons{
Bp: "●",
BpDisabled: "○",
BpActive: "◎",
IndRunning: "▶",
IndStopped: "◼",
IndExitSuccess: "⚑",
IndExitError: "⚐",
}
return Config{
SyntaxHighlighter: "",
Keys: keyconf,
Colors: colorconf,
Icons: iconconf,
}
}
func iToColorS(c int) string {
return strColors[c]
}
func iToColorTcell(c int) tcell.Color {
return tcell.ColorNames[strColors[c]]
}
// Override tree view input using custom keybindings.
func listInputCaptureC(event *tcell.EventKey) *tcell.EventKey {
if keyPressed(event, gConfig.Keys.LineDown) {
return tcell.NewEventKey(256, 'j', tcell.ModNone)
}
if keyPressed(event, gConfig.Keys.LineUp) {
return tcell.NewEventKey(256, 'k', tcell.ModNone)
}
if keyPressed(event, gConfig.Keys.SelectItem) {
return tcell.NewEventKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)
}
return nil
}
func keyPressed(event *tcell.EventKey, binding string) bool {
if tBindingName, ok := tcell.KeyNames[event.Key()]; ok {
return strings.ToLower(tBindingName) == strings.ToLower(binding)
}
return binding == string(event.Rune())
}
func getConfig() {
gConfig = NewConfig() // Initialize with default values.
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("$XDG_CONFIG_HOME/dlvtui")
viper.AddConfigPath(".") // Optionally use config in working directory.
// Ignore error wher config file was not found, print error and exit on any other errors.
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
// Config file was found but another error was produced
fmt.Println("Error parsing config file: %w", err)
os.Exit(1)
}
log.Println("No config file found, using defaults.")
}
conf_err := viper.Unmarshal(&gConfig)
if conf_err != nil {
log.Fatalf("Error reading configuration: %v", conf_err)
}
conf_keys_err := viper.UnmarshalKey("keys", &gConfig.Keys)
if conf_keys_err != nil {
log.Fatalf("Error reading key configuration: %v", conf_keys_err)
}
conf_icons_err := viper.UnmarshalKey("icons", &gConfig.Keys)
if conf_keys_err != nil {
log.Fatalf("Error reading icon configuration: %v", conf_icons_err)
}
}