173 lines
6.0 KiB
Go
173 lines
6.0 KiB
Go
package schema
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// Ghostty itself has no option categories; these groupings exist only to
|
|
// make the editor easier to navigate.
|
|
const (
|
|
CatFonts = "Fonts"
|
|
CatFontMetrics = "Font Metrics"
|
|
CatColors = "Colors & Theme"
|
|
CatBackground = "Background"
|
|
CatCursor = "Cursor"
|
|
CatWindow = "Window"
|
|
CatTabsSplits = "Tabs & Splits"
|
|
CatMouse = "Mouse & Selection"
|
|
CatClipboard = "Clipboard"
|
|
CatKeyboard = "Keyboard"
|
|
CatShell = "Shell & Commands"
|
|
CatScrolling = "Scrolling"
|
|
CatNotifications = "Notifications & Bell"
|
|
CatQuickTerminal = "Quick Terminal"
|
|
CatShaders = "Shaders"
|
|
CatMacOS = "macOS"
|
|
CatLinux = "Linux & GTK"
|
|
CatConfigFiles = "Config Files"
|
|
CatAdvanced = "Advanced"
|
|
)
|
|
|
|
var categoryOrder = []string{
|
|
CatFonts, CatFontMetrics, CatColors, CatBackground, CatCursor, CatWindow,
|
|
CatTabsSplits, CatMouse, CatClipboard, CatKeyboard, CatShell, CatScrolling,
|
|
CatNotifications, CatQuickTerminal, CatShaders, CatMacOS, CatLinux,
|
|
CatConfigFiles, CatAdvanced,
|
|
}
|
|
|
|
// exact key assignments, checked before the prefix rules below.
|
|
var categoryByKey = map[string]string{
|
|
"keybind": CatKeyboard,
|
|
"key-remap": CatKeyboard,
|
|
"macos-option-as-alt": CatKeyboard,
|
|
"vt-kam-allowed": CatKeyboard,
|
|
"config-file": CatConfigFiles,
|
|
"config-default-files": CatConfigFiles,
|
|
"cursor-click-to-move": CatMouse,
|
|
"theme": CatColors,
|
|
"background": CatColors,
|
|
"foreground": CatColors,
|
|
"bold-color": CatColors,
|
|
"minimum-contrast": CatColors,
|
|
"faint-opacity": CatColors,
|
|
"alpha-blending": CatColors,
|
|
"osc-color-report-format": CatColors,
|
|
"window-colorspace": CatColors,
|
|
"selection-foreground": CatColors,
|
|
"selection-background": CatColors,
|
|
"window-title-font-family": CatWindow,
|
|
"freetype-load-flags": CatFonts,
|
|
"grapheme-width-method": CatFonts,
|
|
"window-new-tab-position": CatTabsSplits,
|
|
"window-show-tab-bar": CatTabsSplits,
|
|
"window-inherit-working-directory": CatShell,
|
|
"tab-inherit-working-directory": CatShell,
|
|
"split-inherit-working-directory": CatShell,
|
|
"scrollback-limit": CatScrolling,
|
|
"scrollbar": CatScrolling,
|
|
"scroll-to-bottom": CatScrolling,
|
|
"mouse-scroll-multiplier": CatScrolling,
|
|
"focus-follows-mouse": CatMouse,
|
|
"click-repeat-interval": CatMouse,
|
|
"right-click-action": CatMouse,
|
|
"copy-on-select": CatClipboard,
|
|
"command": CatShell,
|
|
"initial-command": CatShell,
|
|
"env": CatShell,
|
|
"input": CatShell,
|
|
"working-directory": CatShell,
|
|
"wait-after-command": CatShell,
|
|
"abnormal-command-exit-runtime": CatShell,
|
|
"term": CatShell,
|
|
"enquiry-response": CatShell,
|
|
"command-palette-entry": CatShell,
|
|
"app-notifications": CatNotifications,
|
|
"desktop-notifications": CatNotifications,
|
|
"progress-style": CatNotifications,
|
|
"auto-update": CatMacOS,
|
|
"auto-update-channel": CatMacOS,
|
|
"class": CatLinux,
|
|
"async-backend": CatLinux,
|
|
"language": CatLinux,
|
|
"maximize": CatWindow,
|
|
"fullscreen": CatWindow,
|
|
"title": CatWindow,
|
|
"initial-window": CatWindow,
|
|
"confirm-close-surface": CatWindow,
|
|
"undo-timeout": CatWindow,
|
|
}
|
|
|
|
var categoryPrefixes = []struct {
|
|
prefix, cat string
|
|
}{
|
|
{"quick-terminal-", CatQuickTerminal},
|
|
{"gtk-quick-terminal-", CatQuickTerminal},
|
|
{"custom-shader", CatShaders},
|
|
{"adjust-cursor-", CatCursor},
|
|
{"adjust-", CatFontMetrics},
|
|
{"font-", CatFonts},
|
|
{"cursor-", CatCursor},
|
|
{"background-", CatBackground},
|
|
{"palette", CatColors},
|
|
{"search-", CatColors},
|
|
{"split-", CatTabsSplits},
|
|
{"unfocused-split-", CatTabsSplits},
|
|
{"mouse-", CatMouse},
|
|
{"selection-", CatMouse},
|
|
{"link", CatMouse},
|
|
{"clipboard-", CatClipboard},
|
|
{"shell-integration", CatShell},
|
|
{"bell-", CatNotifications},
|
|
{"notify-on-", CatNotifications},
|
|
{"macos-", CatMacOS},
|
|
{"gtk-", CatLinux},
|
|
{"linux-", CatLinux},
|
|
{"x11-", CatLinux},
|
|
{"window-", CatWindow},
|
|
{"resize-overlay", CatWindow},
|
|
{"quit-after-", CatWindow},
|
|
}
|
|
|
|
func categorize(key string) string {
|
|
if c, ok := categoryByKey[key]; ok {
|
|
return c
|
|
}
|
|
for _, p := range categoryPrefixes {
|
|
if strings.HasPrefix(key, p.prefix) {
|
|
return p.cat
|
|
}
|
|
}
|
|
return CatAdvanced
|
|
}
|
|
|
|
// platform reports which OS an option is limited to, based on its key
|
|
// prefix and on sentences like "This is only supported on macOS." in its
|
|
// documentation. Notes about individual values (e.g. "(macOS only)" in a
|
|
// list item) or about several platforms are ignored.
|
|
func platform(o *Option) string {
|
|
switch {
|
|
case strings.HasPrefix(o.Key, "macos-"):
|
|
return "macOS"
|
|
case strings.HasPrefix(o.Key, "gtk-"), strings.HasPrefix(o.Key, "linux-"),
|
|
strings.HasPrefix(o.Key, "x11-"):
|
|
return "Linux"
|
|
}
|
|
text := strings.Join(strings.Fields(o.Doc), " ")
|
|
for _, sentence := range strings.SplitAfter(text, ". ") {
|
|
m := rePlatformNote.FindStringSubmatch(strings.ToLower(strings.TrimSpace(sentence)))
|
|
if m == nil {
|
|
continue
|
|
}
|
|
if m[1] == "macos" || m[2] == "macos" {
|
|
return "macOS"
|
|
}
|
|
return "Linux"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
var rePlatformNote = regexp.MustCompile(
|
|
`^(?:note: )?(?:(?:this|it)(?: \w+)? (?:is )?)?(?:currently )?only (?:supported|implemented|available) on (macos|linux|gtk)\b(?: \(gtk\))?[.,;]?$` +
|
|
`|^(macos|gtk|linux) only\.?$`)
|