settings

package
v1.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package settings owns the unified d9c configuration file (d9c-config.yaml): the single place every persistent setting lives — UI theme and color overrides, normal-mode keybindings, resource-alert thresholds, and the list of saved hosts. Plugins are intentionally NOT here; they stay in their own d9c-plugins.yaml.

This package is the only reader/writer of the file. It delegates validation of each section to the owning package's pure resolver (theme.Resolve, keymap.Resolve, alerts.Resolve), so those packages keep their domain logic without each opening the file independently. Saving rewrites the whole file from the in-memory model, so a host edit can never clobber the theme section and vice versa.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the config file location next to the running binary, falling back to the current directory if the executable path is unavailable.

Types

type AlertsSection

type AlertsSection struct {
	CPU float64 `yaml:"cpu"`
	Mem float64 `yaml:"mem"`
}

AlertsSection mirrors the "alerts:" block (CPU/MEM thresholds, percent).

type File

type File struct {
	Lang   string            `yaml:"lang,omitempty"`
	Theme  string            `yaml:"theme,omitempty"`
	Colors map[string]string `yaml:"colors,omitempty"`
	Keys   map[string]string `yaml:"keys,omitempty"`
	Alerts *AlertsSection    `yaml:"alerts,omitempty"`
	Hosts  []hosts.Host      `yaml:"hosts,omitempty"`
}

File is the on-disk shape of d9c-config.yaml. Every section is optional; omitempty keeps a freshly written file free of empty noise.

type Store

type Store struct {
	File File
	// contains filtered or unexported fields
}

Store is the loaded config bound to its file path.

func Load

func Load(path string) (*Store, error)

Load reads the config file at path. A missing file yields an empty store bound to that path (so a later Save creates it); malformed YAML is an error. The individual sections are validated lazily by Palette/Keymap/Alerts so a single bad section is reported in context.

func (*Store) Alerts

func (s *Store) Alerts() (alerts.Thresholds, error)

Alerts resolves the alert thresholds (disabled when the section is absent).

func (*Store) HasHosts

func (s *Store) HasHosts() bool

HasHosts reports whether the config already carries saved hosts.

func (*Store) Hosts

func (s *Store) Hosts() *hosts.Store

Hosts returns a host store backed by this config file: its CRUD persists by rewriting the unified file (preserving the other sections).

func (*Store) Keymap

func (s *Store) Keymap() (keymap.Map, error)

Keymap resolves the keys section on top of the defaults.

func (*Store) Lang

func (s *Store) Lang() (i18n.Lang, error)

Lang resolves the configured UI language (default EN when the section is empty or invalid handling is delegated to i18n.Resolve).

func (*Store) Palette

func (s *Store) Palette() (styles.Palette, error)

Palette resolves the theme/colors section into a concrete palette (default palette when the section is empty).

func (*Store) Path

func (s *Store) Path() string

Path returns the file the store is bound to.

func (*Store) Save

func (s *Store) Save() error

Save writes the whole config back to its file, preserving every section.

func (*Store) SetHosts

func (s *Store) SetHosts(list []hosts.Host)

SetHosts replaces the host list in-memory without saving. Used by migration before the first explicit Save.

func (*Store) SetLang

func (s *Store) SetLang(name string) error

SetLang records the UI language code and persists the file.

func (*Store) SetTheme

func (s *Store) SetTheme(name string) error

SetTheme records a built-in theme name as the active theme and persists the file. Selecting a complete built-in palette clears any stale per-color overrides so the saved theme renders exactly as previewed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL