-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
config.v
340 lines (302 loc) · 7.75 KB
/
config.v
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
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license
// that can be found in the LICENSE file.
module main
import os
import gx
// import toml
import json
// The different kinds of cursors
enum Cursor {
block
beam
variable
}
// Config structure
// TODO: Load user config from file
struct Config {
mut:
// settings toml.Doc
dark_mode bool
cursor_style Cursor
text_size int = min_text_size
line_height int = 20
char_width int = 8
tab_size int = 4
tab int = int(`\t`) // TODO read from config file?
backspace_go_up bool
vcolor gx.Color // v selection background color
split_color gx.Color
bgcolor gx.Color // base00
errorbgcolor gx.Color // base08
title_color gx.Color // base04
cursor_color gx.Color // base05
string_color gx.Color // base0B
string_cfg gx.TextCfg
key_color gx.Color // base0E
key_cfg gx.TextCfg
lit_color gx.Color // base0E
lit_cfg gx.TextCfg
text_color gx.Color // base05
txt_cfg gx.TextCfg
comment_color gx.Color // base03
comment_cfg gx.TextCfg
file_name_color gx.Color
file_name_cfg gx.TextCfg
plus_color gx.Color
plus_cfg gx.TextCfg
minus_color gx.Color
minus_cfg gx.TextCfg
line_nr_color gx.Color // base01
line_nr_cfg gx.TextCfg
green_color gx.Color // base0B
green_cfg gx.TextCfg
red_color gx.Color // base08
red_cfg gx.TextCfg
disable_mouse bool = true
// Config.json
disable_fmt bool
}
/*
// json
struct Config2 {
disable_fmt bool
text_size int
line_height int
char_width int
}
*/
/*
fn (mut config Config) set_settings(path string) {
config.settings = toml.parse_file(path) or { toml.parse_text('') or { panic(err) } }
}
*/
// reload_config reloads the config from config.toml file
// set_default_color_values?
fn (mut config Config) set_default_values() {
config.init_colors()
config.set_cursor_style()
// config.set_text_size()
// config.set_line_height()
// config.set_char_width()
// config.set_tab()
// config.set_backspace_behaviour()
// config.set_disable_mouse()
config.set_vcolor()
config.set_split()
config.set_bgcolor()
config.set_errorbgcolor()
config.set_string()
config.set_key()
config.set_lit()
config.set_title()
config.set_cursor()
config.set_txt()
config.set_comment()
config.set_filename()
config.set_plus()
config.set_minus()
config.set_line_nr()
config.set_green()
config.set_red()
}
fn (mut config Config) init_colors() {
config.dark_mode ||= '-dark' in os.args
}
fn (mut config Config) set_cursor_style() {
/*
toml_cursor_style := config.settings.value('editor.cursor').string()
if toml_cursor_style != 'toml.Any(toml.Null{})' {
match toml_cursor_style {
'block' { config.cursor_style = .block }
'beam' { config.cursor_style = .beam }
'variable' { config.cursor_style = .variable }
else { config.cursor_style = .block }
}
return
}
*/
config.cursor_style = .block
}
// Convert a toml key color (in hex) to a gx.Color type
/*
fn (config Config) get_toml_color(base string) !gx.Color {
toml_hex := config.settings.value('colors.base${base}').string()
if toml_hex != 'toml.Any(toml.Null{})' {
toml_red := ('0x' + toml_hex[0..2]).u8()
toml_green := ('0x' + toml_hex[2..4]).u8()
toml_blue := ('0x' + toml_hex[4..6]).u8()
return gx.rgb(toml_red, toml_green, toml_blue)
}
return error('Couldn\'t read base${base} from the settings file')
}
*/
fn (mut config Config) set_vcolor() {
if !config.dark_mode {
config.vcolor = gx.rgb(226, 233, 241)
} else {
config.vcolor = gx.rgb(60, 60, 60)
}
}
fn (mut config Config) set_split() {
if !config.dark_mode {
config.split_color = gx.rgb(223, 223, 223)
} else {
config.split_color = gx.rgb(50, 50, 50)
}
}
// base 00
fn (mut config Config) set_bgcolor() {
// config.bgcolor = config.get_toml_color('00') or {
config.bgcolor = if config.dark_mode {
gx.rgb(30, 30, 30)
} else {
gx.rgb(245, 245, 245)
}
//}
}
// base 01
fn (mut config Config) set_errorbgcolor() {
// config.errorbgcolor = config.get_toml_color('01') or { gx.rgb(240, 0, 0) }
config.errorbgcolor = gx.rgb(240, 0, 0)
}
// base 0B
fn (mut config Config) set_string() {
// config.string_color = config.get_toml_color('0B') or { gx.rgb(179, 58, 44) }
config.string_color = gx.rgb(179, 58, 44)
config.string_cfg = gx.TextCfg{
size: config.text_size
color: config.string_color
}
}
// base 0E
fn (mut config Config) set_key() {
// config.key_color = config.get_toml_color('0E') or { gx.rgb(74, 103, 154) }
config.key_color = gx.rgb(74, 103, 154)
config.key_cfg = gx.TextCfg{
size: config.text_size
color: config.key_color
}
}
// base 0F
fn (mut config Config) set_lit() {
// config.lit_color = config.get_toml_color('0F') or { gx.rgb(7, 103, 154) }
config.lit_color = gx.rgb(7, 103, 154)
config.lit_cfg = gx.TextCfg{
size: config.text_size
color: config.lit_color
}
}
// base 04
fn (mut config Config) set_title() {
// config.title_color = config.get_toml_color('04') or { gx.rgb(40, 40, 40) }
config.title_color = gx.rgb(0, 0, 0)
}
// base 05
fn (mut config Config) set_cursor() {
// config.cursor_color = config.get_toml_color('05') or {
config.cursor_color = if !config.dark_mode {
gx.black
} else {
gx.white
}
//}
}
// base 05 (again)
fn (mut config Config) set_txt() {
// config.text_color = config.get_toml_color('05') or {
config.text_color = if !config.dark_mode {
gx.black
} else {
gx.rgb(212, 212, 212)
}
config.txt_cfg = gx.TextCfg{
size: config.text_size
color: config.text_color
}
}
// base 03
fn (mut config Config) set_comment() {
// config.comment_color = config.get_toml_color('03') or { gx.dark_gray }
config.comment_color = gx.dark_gray
config.comment_cfg = gx.TextCfg{
size: config.text_size
color: config.comment_color
}
}
fn (mut config Config) set_filename() {
config.file_name_color = gx.white
config.file_name_cfg = gx.TextCfg{
size: config.text_size
color: config.file_name_color
}
}
fn (mut config Config) set_plus() {
config.plus_color = gx.green
config.plus_cfg = gx.TextCfg{
size: config.text_size
color: config.plus_color
}
}
fn (mut config Config) set_minus() {
config.minus_color = gx.green
config.minus_cfg = gx.TextCfg{
size: config.text_size
color: config.minus_color
}
}
// base 01
fn (mut config Config) set_line_nr() {
// config.line_nr_color = config.get_toml_color('01') or { gx.dark_gray }
config.line_nr_color = gx.dark_gray
config.line_nr_cfg = gx.TextCfg{
size: config.text_size
color: config.line_nr_color
align: gx.align_right
}
}
// base 0B
fn (mut config Config) set_green() {
// config.green_color = config.get_toml_color('0B') or { gx.green }
config.green_color = gx.green
config.green_cfg = gx.TextCfg{
size: config.text_size
color: config.green_color
}
}
fn (mut config Config) set_red() {
// config.red_color = config.get_toml_color('08') or { gx.red }
config.red_color = gx.red
config.red_cfg = gx.TextCfg{
size: config.text_size
color: config.red_color
}
}
fn (mut ved Ved) load_config2() {
if os.exists(config_path2) {
if conf2 := json.decode(Config, os.read_file(config_path2) or { return }) {
println('AXAXAXAXA ${conf2}')
ved.cfg = conf2
/*
ved.cfg.disable_fmt = conf2.disable_fmt
ved.cfg.text_size = conf2.text_size
ved.cfg.line_height = conf2.line_height
ved.cfg.char_width = conf2.char_width
*/
// ved.cfg.disable_fmt = conf2.disable_fmt
} else {
println(err)
}
}
}
fn (mut ved Ved) save_config2() {
/*
config2 := Config2{
text_size: ved.cfg.text_size
disable_fmt: ved.cfg.disable_fmt
line_height: ved.cfg.line_height
char_width: ved.cfg.char_width
}
*/
os.write_file(config_path2, json.encode_pretty(ved.cfg)) or { panic(err) }
}