akiyosi.goneovim/editor/config.go

427 lines
10 KiB
Go
Raw Permalink Normal View History

2018-08-04 21:40:26 +09:00
package editor
import (
2020-01-19 15:05:10 +09:00
"fmt"
2020-12-04 23:14:06 +09:00
"os"
2018-08-04 21:40:26 +09:00
"path/filepath"
"runtime"
2021-06-10 22:54:39 +09:00
"sync"
2018-08-04 21:40:26 +09:00
"github.com/BurntSushi/toml"
)
type gonvimConfig struct {
2019-11-19 00:32:34 +09:00
Editor editorConfig
2021-12-10 21:24:04 +09:00
SideBar sideBarConfig
Workspace workspaceConfig
FileExplore fileExploreConfig
Popupmenu popupMenuConfig
2019-11-19 00:32:34 +09:00
Palette paletteConfig
2021-12-10 21:24:04 +09:00
MiniMap miniMapConfig
Cursor cursorConfig
2019-11-23 03:46:36 +09:00
Message messageConfig
2021-12-10 21:24:04 +09:00
mu sync.RWMutex
2019-11-19 00:32:34 +09:00
Tabline tabLineConfig
ScrollBar scrollBarConfig
2018-08-04 21:40:26 +09:00
}
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
2023-11-02 22:41:48 +09:00
FontWeight string
ModeEnablingIME []string
IndentGuideIgnoreFtList []string
CharsScaledLineHeight []string
Transparent float64
EnableBackgroundBlur bool
DiffDeletePattern int
DiffAddPattern int
LineToScroll int
DiffChangePattern int
CacheSize int
Linespace int
2023-11-02 22:41:48 +09:00
Letterspace int
FontSize int
2023-11-02 22:41:48 +09:00
FontStretch int
Margin int
Gap int
Height int
Width int
2022-05-27 13:49:56 +09:00
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
2023-11-02 22:41:48 +09:00
ManualFontFallback bool
WindowGeometryBasedOnFontmetrics bool
IgnoreFirstMouseClickWhenAppInactivated bool
HideTitlebar bool
HideMouseWhenTyping bool
IgnoreSaveConfirmationWithCloseButton bool
UseWSL bool
ShowDiffDialogOnDrop bool
2018-08-04 21:40:26 +09:00
}
2021-05-27 21:41:50 +09:00
type cursorConfig struct {
SmoothMove bool
2021-06-10 23:24:19 +09:00
Duration int
2021-05-27 21:41:50 +09:00
}
2019-11-23 03:46:36 +09:00
type paletteConfig struct {
AreaRatio float64
MaxNumberOfResultItems int
Transparent float64
}
type messageConfig struct {
Transparent float64
ShowMessageSeparators bool
2019-11-23 03:46:36 +09:00
}
type tabLineConfig struct {
2020-09-26 12:04:36 +09:00
Visible bool
ShowIcon bool
}
type popupMenuConfig struct {
2019-11-14 00:45:01 +09:00
Total int
MenuWidth int
InfoWidth int
2019-11-14 00:45:01 +09:00
DetailWidth int
2021-12-10 21:24:04 +09:00
ShowDetail bool
2021-01-23 14:00:23 +09:00
ShowDigit bool
}
2018-09-22 00:35:54 +09:00
type miniMapConfig struct {
Visible bool
2020-03-28 10:27:50 +09:00
Disable bool
Width int
2018-09-22 00:35:54 +09:00
}
2018-09-17 16:44:59 +09:00
type scrollBarConfig struct {
Visible bool
Width int
Color string
2018-09-17 16:44:59 +09:00
}
2018-08-04 21:40:26 +09:00
type sideBarConfig struct {
2021-12-10 21:24:04 +09:00
AccentColor string
Width int
2018-08-04 21:40:26 +09:00
Visible bool
DropShadow bool
}
type workspaceConfig struct {
2019-02-01 18:33:38 +09:00
PathStyle string
2021-12-10 21:24:04 +09:00
RestoreSession bool
}
2019-11-17 15:45:09 +09:00
type fileExploreConfig struct {
OpenCmd string
MaxDisplayItems int
2018-08-04 21:40:26 +09:00
}
func newConfig(home string, skipConfigLoading bool) (string, gonvimConfig) {
2020-12-04 23:14:06 +09:00
// init
2018-08-04 21:40:26 +09:00
var config gonvimConfig
2019-09-14 21:05:17 +09:00
config.init()
// detect configdir, configfile
configDir, configFilePath := detectConfig(home)
if !skipConfigLoading {
// load toml
_, err := toml.DecodeFile(configFilePath, &config)
if err != nil {
fmt.Println(err)
}
2020-01-19 15:05:10 +09:00
}
// 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
2019-10-27 16:59:05 +09:00
}
2019-06-30 02:55:15 +09:00
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
}
2019-09-16 11:42:28 +09:00
if config.Editor.DiffChangePattern < 1 || config.Editor.DiffChangePattern > 24 {
config.Editor.DiffChangePattern = 1
}
2019-06-30 02:55:15 +09:00
if config.Editor.Width <= 400 {
config.Editor.Width = 400
2018-10-13 22:33:01 +09:00
}
if config.Editor.Height <= 300 {
config.Editor.Height = 300
2018-10-13 22:33:01 +09:00
}
2019-05-08 17:16:18 +09:00
if config.Editor.Transparent <= 0.1 {
config.Editor.Transparent = 1.0
}
2018-10-13 22:33:01 +09:00
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
}
2018-10-13 22:33:01 +09:00
if config.Editor.Linespace < 0 {
config.Editor.Linespace = 6
}
if config.SideBar.Width == 0 {
2019-11-02 11:09:19 +09:00
config.SideBar.Width = 200
}
if config.SideBar.AccentColor == "" {
2018-10-29 23:13:47 +09:00
config.SideBar.AccentColor = "#5596ea"
}
2019-11-17 15:45:09 +09:00
if config.FileExplore.MaxDisplayItems < 1 {
config.FileExplore.MaxDisplayItems = 1
}
if config.Workspace.PathStyle == "" {
config.Workspace.PathStyle = "minimum"
}
2020-03-28 10:27:50 +09:00
if config.MiniMap.Width == 0 || config.MiniMap.Width >= 250 {
2021-02-02 21:38:41 +09:00
config.MiniMap.Width = 100
2020-03-28 10:27:50 +09:00
}
2023-01-26 01:33:47 +09:00
editor.putLog("reading config")
2020-12-04 23:14:06 +09:00
return configDir, config
2018-08-04 21:40:26 +09:00
}
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
}
2019-09-14 21:05:17 +09:00
func (c *gonvimConfig) init() {
2021-02-14 22:38:14 +09:00
// For debug
c.Editor.SkipGlobalId = false
2019-09-14 21:05:17 +09:00
// Set default value
c.Editor.BorderlessWindow = false
c.Editor.RestoreWindowGeometry = false
c.Editor.WindowGeometryBasedOnFontmetrics = false
2019-09-14 21:05:17 +09:00
2021-02-14 22:38:14 +09:00
c.Editor.Width = 800
c.Editor.Height = 600
c.Editor.Gap = 0
2019-09-14 21:05:17 +09:00
c.Editor.FileOpenCmd = ":e"
2021-02-14 22:38:14 +09:00
c.Editor.Transparent = 1.0
2019-09-14 21:05:17 +09:00
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
2023-11-02 22:41:48 +09:00
c.Editor.FontWeight = "normal"
// Horizontal stretch ratio
c.Editor.FontStretch = 100
c.Editor.FontSize = 12
c.Editor.Linespace = 6
2021-02-14 22:38:14 +09:00
c.Editor.ExtCmdline = false
c.Editor.ExtPopupmenu = false
c.Editor.ExtTabline = false
c.Editor.ExtMessages = false
c.Editor.CachedDrawing = true
2025-08-07 22:17:43 +09:00
c.Editor.CacheSize = 960
2021-02-14 22:38:14 +09:00
c.Editor.DisableLigatures = false
c.Editor.Clipboard = true
2021-08-29 16:01:00 +09:00
c.Editor.Macmeta = false
2021-02-14 22:38:14 +09:00
c.Editor.DisableImeInNormal = false
c.Editor.DrawWindowSeparator = false
c.Editor.WindowSeparatorTheme = "dark"
c.Editor.WindowSeparatorColor = "#2222ff"
c.Editor.WindowSeparatorGradient = false
2019-09-14 21:05:17 +09:00
// 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"
2019-09-14 21:05:17 +09:00
c.Editor.LineToScroll = 1
2021-02-14 22:38:14 +09:00
c.Editor.SmoothScroll = false
2024-06-02 02:22:01 +09:00
c.Editor.SmoothScrollDuration = 800
2021-10-13 22:17:13 +09:00
c.Editor.DisableHorizontalScroll = false
2021-02-14 22:38:14 +09:00
c.Editor.DrawBorderForFloatWindow = false
c.Editor.DrawShadowForFloatWindow = false
c.Editor.DesktopNotifications = false
c.Editor.ClickEffect = false
2019-09-14 21:05:17 +09:00
// replace diff color drawing pattern
2020-05-28 22:37:56 +09:00
c.Editor.DiffAddPattern = 1
c.Editor.DiffDeletePattern = 1
2021-02-09 21:31:03 +09:00
c.Editor.DiffChangePattern = 1
2019-09-14 21:05:17 +09:00
2024-03-30 10:27:12 +09:00
c.Cursor.Duration = 180
2021-05-27 21:41:50 +09:00
2021-02-14 22:38:14 +09:00
// ----
2019-09-14 21:05:17 +09:00
// palette size
c.Palette.AreaRatio = 0.5
c.Palette.MaxNumberOfResultItems = 30
2019-11-23 03:46:36 +09:00
c.Palette.Transparent = 1.0
2021-02-14 22:38:14 +09:00
// ----
2019-11-23 03:46:36 +09:00
c.Message.Transparent = 1.0
2019-11-02 11:09:19 +09:00
2021-02-14 22:38:14 +09:00
// ----
2019-11-02 11:09:19 +09:00
c.Tabline.Visible = true
2021-02-14 22:38:14 +09:00
c.Tabline.ShowIcon = true
// ----
2019-11-02 11:09:19 +09:00
2021-02-14 22:38:14 +09:00
// ----
2019-11-07 21:11:47 +09:00
c.Popupmenu.ShowDetail = true
c.Popupmenu.Total = 20
2019-11-08 23:22:32 +09:00
c.Popupmenu.MenuWidth = 400
c.Popupmenu.InfoWidth = 1
2019-11-09 09:41:58 +09:00
c.Popupmenu.DetailWidth = 250
2021-02-14 22:38:14 +09:00
// ----
2019-11-02 11:09:19 +09:00
2020-01-30 20:59:47 +09:00
c.ScrollBar.Visible = false
c.ScrollBar.Width = 10
2019-11-02 11:09:19 +09:00
2021-02-14 22:38:14 +09:00
// ----
c.MiniMap.Disable = true
2021-01-20 23:45:18 +09:00
c.MiniMap.Width = 110
2020-03-28 10:27:50 +09:00
2021-02-14 22:38:14 +09:00
// ----
c.SideBar.Visible = false
2019-11-02 11:09:19 +09:00
c.SideBar.Width = 200
c.SideBar.AccentColor = "#5596ea"
2021-02-14 22:38:14 +09:00
// ----
2019-11-17 15:45:09 +09:00
c.FileExplore.MaxDisplayItems = 30
2021-02-14 22:38:14 +09:00
// ----
2019-11-02 11:09:19 +09:00
c.Workspace.PathStyle = "minimum"
2021-02-14 22:38:14 +09:00
c.Workspace.RestoreSession = false
2019-09-14 21:05:17 +09:00
}