Documentation
¶
Overview ¶
Package userconfig loads the editor's small user-level config from ~/.config/skiff/config.json. It's separate from customactions on purpose: actions.json is a list of shell-out menu entries, config.json is editor preferences. Keeping them apart means a malformed actions file can't break editor settings and vice-versa.
Schema today is intentionally tiny — a handful of flat keys — but the loader is already wrapped in a struct so we can grow new top-level fields without breaking older configs:
{"icons": "auto"} // default; auto-detect Nerd Fonts on startup
{"icons": "on"} // force-on, even if detection would say no
{"icons": "off"} // force-off, even if a Nerd Font is installed
{"theme": "tokyo-night"} // any id from internal/theme's registry
{"wrap": "off"} // long lines pan sideways; "on" (default) wraps
{"gitignore": "off"} // file tree shows ignored files; "on" (default) hides them
{"scrollcaret": "on"} // a wheel/scrollbar scroll drags the caret along; "off" (default) leaves it
The loader is best-effort the same way customactions is: missing file → defaults, malformed file → error returned for the app to flash, but the editor still starts cleanly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
func DefaultPath() string
DefaultPath returns the canonical config-file location: $XDG_CONFIG_HOME/skiff/config.json, falling back to ~/.config/skiff/config.json. Returns "" when neither resolves — callers should treat that as "use defaults".
func SetGitignore ¶ added in v0.2.4
SetGitignore persists the file tree's "hide ignored entries" preference, with the same contract as SetWrap.
func SetIcons ¶ added in v0.2.20
SetIcons persists the Nerd Font icons mode into the config file at path, with the same create-if-needed / preserve-unknown-keys contract as SetTheme. The mode is written as its string form, which is what Load parses back.
func SetScrollCaret ¶ added in v0.2.13
SetScrollCaret persists the "caret follows scroll" preference, with the same contract as SetWrap.
Types ¶
type Config ¶
type Config struct {
Icons IconsMode
// IconsSet reports whether the file carried an explicit icons key
// at all. The app uses it to decide whether the user has ever made
// the choice: an "auto" that was never written is the one case
// worth a hint when detection cannot answer (over SSH), an "auto"
// the user typed is a decision to respect silently.
IconsSet bool
// Theme is the theme id to start with ("" = default). Validated by
// the app against the theme registry, not here — the config loader
// shouldn't need to import the palette table.
Theme string
// Wrap is whether the editor soft-wraps long lines. Defaults to on —
// the editor's audience reads code over SSH, where sideways panning
// hurts the most; the menu toggle persists an "off" here.
Wrap bool
// Gitignore is whether the file tree hides entries the project's
// .gitignore files exclude. Defaults to on so the sidebar and the
// finder agree about what counts as project noise; the ≡ View row
// persists an "off" here for the times you need to see build output.
Gitignore bool
// ScrollCaret is whether a viewport-only scroll (wheel, scrollbar)
// pulls the caret along so it stays on a visible line. Defaults to
// off — scrolling has never moved the caret here (the VS Code
// behavior), so following it is an explicit opt-in via the ≡ View
// row.
ScrollCaret bool
}
Config is the resolved, validated form of config.json. Callers get a fully-populated Config back from Load — defaults are filled in for any field the file omitted, so consumers never need to nil-check.
func Defaults ¶
func Defaults() Config
Defaults returns a Config populated with the values used when no config file is present (or every field in it is blank). Centralised so tests and the loader can't drift from each other.
func Load ¶
Load reads and parses the config file at path, returning a Config with defaults filled in for any missing or blank fields.
Contract:
- path == "" → (Defaults(), nil). Treated as "no config configured".
- file doesn't exist → (Defaults(), nil). Same as above.
- file unreadable → (Defaults(), err). Caller can flash a message; editor keeps running on defaults.
- file empty / all-blank → (Defaults(), nil).
- unknown icons value → (Defaults(), err). We'd rather tell the user their config has a typo than silently fall back to defaults and hide the bug.