-
Notifications
You must be signed in to change notification settings - Fork 62
/
config.go
426 lines (353 loc) · 10.5 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package editor
import (
"fmt"
"os"
"path/filepath"
"runtime"
"sync"
"github.com/BurntSushi/toml"
)
type gonvimConfig struct {
Editor editorConfig
SideBar sideBarConfig
Workspace workspaceConfig
FileExplore fileExploreConfig
Popupmenu popupMenuConfig
Palette paletteConfig
MiniMap miniMapConfig
Cursor cursorConfig
Message messageConfig
mu sync.RWMutex
Tabline tabLineConfig
ScrollBar scrollBarConfig
}
type editorConfig struct {
DockmenuActions map[string]string
MouseScrollingUnit string
OptionsToUseGuideWidth string
FileOpenCmd string
WindowSeparatorColor string
FontFamily string
GinitVim string
WindowSeparatorTheme string
NvimInWsl string
WSLDist string
FontWeight string
ModeEnablingIME []string
IndentGuideIgnoreFtList []string
CharsScaledLineHeight []string
Transparent float64
EnableBackgroundBlur bool
DiffDeletePattern int
DiffAddPattern int
LineToScroll int
DiffChangePattern int
CacheSize int
Linespace int
Letterspace int
FontSize int
FontStretch int
Margin int
Gap int
Height int
Width int
SmoothScrollDuration int
DrawWindowSeparator bool
Macmeta bool
DrawBorder bool
DisableLigatures bool
StartMaximizedWindow bool
WindowSeparatorGradient bool
StartFullscreen bool
SkipGlobalId bool
IndentGuide bool
DisableImeInNormal bool
CachedDrawing bool
Clipboard bool
ReversingScrollDirection bool
SmoothScroll bool
DisableHorizontalScroll bool
DrawBorderForFloatWindow bool
DrawShadowForFloatWindow bool
DesktopNotifications bool
ExtMessages bool
ExtTabline bool
ExtPopupmenu bool
ClickEffect bool
BorderlessWindow bool
RestoreWindowGeometry bool
ExtCmdline bool
ManualFontFallback bool
WindowGeometryBasedOnFontmetrics bool
IgnoreFirstMouseClickWhenAppInactivated bool
HideTitlebar bool
HideMouseWhenTyping bool
IgnoreSaveConfirmationWithCloseButton bool
UseWSL bool
ShowDiffDialogOnDrop bool
}
type cursorConfig struct {
SmoothMove bool
Duration int
}
type paletteConfig struct {
AreaRatio float64
MaxNumberOfResultItems int
Transparent float64
}
type messageConfig struct {
Transparent float64
ShowMessageSeparators bool
}
type tabLineConfig struct {
Visible bool
ShowIcon bool
}
type popupMenuConfig struct {
Total int
MenuWidth int
InfoWidth int
DetailWidth int
ShowDetail bool
ShowDigit bool
}
type miniMapConfig struct {
Visible bool
Disable bool
Width int
}
type scrollBarConfig struct {
Visible bool
Width int
Color string
}
type sideBarConfig struct {
AccentColor string
Width int
Visible bool
DropShadow bool
}
type workspaceConfig struct {
PathStyle string
RestoreSession bool
}
type fileExploreConfig struct {
OpenCmd string
MaxDisplayItems int
}
func newConfig(home string, skipConfigLoading bool) (string, gonvimConfig) {
// init
var config gonvimConfig
config.init()
// detect configdir, configfile
configDir, configFilePath := detectConfig(home)
if !skipConfigLoading {
// load toml
_, err := toml.DecodeFile(configFilePath, &config)
if err != nil {
fmt.Println(err)
}
}
// Setting ExtMessages to true should automatically set ExtCmdLine to true as well
// Ref: https://github.com/akiyosi/goneovim/issues/162
if config.Editor.ExtMessages {
config.Editor.ExtCmdline = true
}
if config.Editor.EnableBackgroundBlur {
config.Editor.Transparent = 0.9
}
if config.Editor.Transparent < 1.0 {
config.Editor.BorderlessWindow = true
}
if config.Editor.DiffAddPattern < 1 || config.Editor.DiffAddPattern > 24 {
config.Editor.DiffAddPattern = 1
}
if config.Editor.DiffDeletePattern < 1 || config.Editor.DiffDeletePattern > 24 {
config.Editor.DiffDeletePattern = 1
}
if config.Editor.DiffChangePattern < 1 || config.Editor.DiffChangePattern > 24 {
config.Editor.DiffChangePattern = 1
}
if config.Editor.Width <= 400 {
config.Editor.Width = 400
}
if config.Editor.Height <= 300 {
config.Editor.Height = 300
}
if config.Editor.Transparent <= 0.1 {
config.Editor.Transparent = 1.0
}
if config.Editor.FontFamily == "" {
switch runtime.GOOS {
case "windows":
config.Editor.FontFamily = "Consolas"
case "darwin":
config.Editor.FontFamily = "Monaco"
default:
config.Editor.FontFamily = "Monospace"
}
}
if config.Editor.FontSize <= 3 {
config.Editor.FontSize = 12
}
if config.Editor.Linespace < 0 {
config.Editor.Linespace = 6
}
if config.SideBar.Width == 0 {
config.SideBar.Width = 200
}
if config.SideBar.AccentColor == "" {
config.SideBar.AccentColor = "#5596ea"
}
if config.FileExplore.MaxDisplayItems < 1 {
config.FileExplore.MaxDisplayItems = 1
}
if config.Workspace.PathStyle == "" {
config.Workspace.PathStyle = "minimum"
}
if config.MiniMap.Width == 0 || config.MiniMap.Width >= 250 {
config.MiniMap.Width = 100
}
editor.putLog("reading config")
return configDir, config
}
func detectConfig(home string) (configDir, configFilePath string) {
// detect config dir
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
settingsfile := "settings.toml"
if runtime.GOOS != "windows" {
if xdgConfigHome != "" {
configDir = filepath.Join(xdgConfigHome, "goneovim")
} else {
configDir = filepath.Join(home, ".config", "goneovim")
}
configFilePath = filepath.Join(configDir, settingsfile)
return
} else {
if xdgConfigHome != "" {
configDir = filepath.Join(xdgConfigHome, "goneovim")
configFilePath = filepath.Join(xdgConfigHome, "goneovim", settingsfile)
}
if isFileExist(configFilePath) {
return
}
localappdata := os.Getenv("LOCALAPPDATA")
configDir = filepath.Join(localappdata, "goneovim")
configFilePath = filepath.Join(localappdata, "goneovim", settingsfile)
if isFileExist(configFilePath) {
return
}
configDir = filepath.Join(home, ".config", "goneovim")
configFilePath = filepath.Join(home, ".config", "goneovim", settingsfile)
if isFileExist(configFilePath) {
return
}
configDir = filepath.Join(home, ".goneovim")
configFilePath = filepath.Join(home, ".goneovim", settingsfile)
if isFileExist(configFilePath) {
return
}
}
// windows
localappdata := os.Getenv("LOCALAPPDATA")
configDir = filepath.Join(localappdata, "goneovim")
configFilePath = filepath.Join(localappdata, "goneovim", settingsfile)
return
}
func (c *gonvimConfig) init() {
// For debug
c.Editor.SkipGlobalId = false
// Set default value
c.Editor.BorderlessWindow = false
c.Editor.RestoreWindowGeometry = false
c.Editor.WindowGeometryBasedOnFontmetrics = false
c.Editor.Width = 800
c.Editor.Height = 600
c.Editor.Gap = 0
c.Editor.FileOpenCmd = ":e"
c.Editor.Transparent = 1.0
switch runtime.GOOS {
case "windows":
c.Editor.FontFamily = "Consolas"
c.Editor.Margin = 2
c.Editor.MouseScrollingUnit = "line"
case "darwin":
c.Editor.FontFamily = "Monaco"
c.Editor.Margin = 2
c.Editor.MouseScrollingUnit = "smart"
default:
c.Editor.FontFamily = "Monospace"
c.Editor.Margin = 0
c.Editor.MouseScrollingUnit = "line"
}
c.Editor.FontSize = 12
c.Editor.FontWeight = "normal"
// Horizontal stretch ratio
c.Editor.FontStretch = 100
c.Editor.FontSize = 12
c.Editor.Linespace = 6
c.Editor.ExtCmdline = false
c.Editor.ExtPopupmenu = false
c.Editor.ExtTabline = false
c.Editor.ExtMessages = false
c.Editor.CachedDrawing = true
c.Editor.CacheSize = 480
c.Editor.DisableLigatures = false
c.Editor.Clipboard = true
c.Editor.Macmeta = false
c.Editor.DisableImeInNormal = false
c.Editor.DrawWindowSeparator = false
c.Editor.WindowSeparatorTheme = "dark"
c.Editor.WindowSeparatorColor = "#2222ff"
c.Editor.WindowSeparatorGradient = false
// Indent guide
c.Editor.IndentGuide = false
c.Editor.IndentGuideIgnoreFtList = []string{"markdown", "md", "txt", "text", "help", "json", "nerdtree"}
c.Editor.CharsScaledLineHeight = []string{"", "", "", "", "", "", "", "", "", "", "│", "▎"}
c.Editor.OptionsToUseGuideWidth = "tabstop"
c.Editor.LineToScroll = 1
c.Editor.SmoothScroll = false
c.Editor.SmoothScrollDuration = 800
c.Editor.DisableHorizontalScroll = false
c.Editor.DrawBorderForFloatWindow = false
c.Editor.DrawShadowForFloatWindow = false
c.Editor.DesktopNotifications = false
c.Editor.ClickEffect = false
// replace diff color drawing pattern
c.Editor.DiffAddPattern = 1
c.Editor.DiffDeletePattern = 1
c.Editor.DiffChangePattern = 1
c.Cursor.Duration = 180
// ----
// palette size
c.Palette.AreaRatio = 0.5
c.Palette.MaxNumberOfResultItems = 30
c.Palette.Transparent = 1.0
// ----
c.Message.Transparent = 1.0
// ----
c.Tabline.Visible = true
c.Tabline.ShowIcon = true
// ----
// ----
c.Popupmenu.ShowDetail = true
c.Popupmenu.Total = 20
c.Popupmenu.MenuWidth = 400
c.Popupmenu.InfoWidth = 1
c.Popupmenu.DetailWidth = 250
// ----
c.ScrollBar.Visible = false
c.ScrollBar.Width = 10
// ----
c.MiniMap.Disable = true
c.MiniMap.Width = 110
// ----
c.SideBar.Visible = false
c.SideBar.Width = 200
c.SideBar.AccentColor = "#5596ea"
// ----
c.FileExplore.MaxDisplayItems = 30
// ----
c.Workspace.PathStyle = "minimum"
c.Workspace.RestoreSession = false
}