settingsconfig

package
v0.6.11 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package settingsconfig loads, validates, and saves the user's menu-configured preferences -- theme, font, font zoom, display scale, and whether the menu bar is pinned shown -- to settings.json. Unlike machineconfig (read-only, embedded default with an optional disk override), this package's file is written to as well as read: every time one of these preferences changes via a menu, the current state is saved back to disk so the next launch picks up where the last one left off.

Deliberately not persisted here: the running -model (an explicit CLI flag, or the emulator's own hardcoded default, should always win over a stale persisted model rather than silently booting into whatever was last used), and FPS/border visibility (session-level diagnostic toggles, not the kind of thing most applications persist across restarts).

Index

Constants

View Source
const MaxDisplayScale = 5

MaxDisplayScale mirrors the display package's own MaxMultiplier -- duplicated as a constant here rather than imported, since this package deliberately has no dependency on the GUI display layer (see the package doc comment for Theme/Font's own reasoning). Kept in sync by the two call sites that matter both being covered by tests: TestSchemaMaxDisplayScaleMatchesDisplayPackage in this package, and the display package's own MaxMultiplier tests.

Variables

This section is empty.

Functions

func Save

func Save(diskPath string, s *Settings) error

Save writes s to diskPath as JSON, atomically (write to a temp file in the same directory, then rename over the target) so a crash or power loss mid-write can never leave a half-written, corrupt settings.json behind -- the previous file (or none) is what's on disk right up until the rename, which is a single filesystem operation.

func Schema

func Schema(validThemes, validFonts []string) qf.Schema

Schema builds the schema for settings.json, given the closed sets of valid theme and font names a "theme"/"font" field's own value must be one of.

Types

type Result

type Result struct {
	Settings *Settings
	FromDisk bool
	DiskPath string
	Warning  string
}

Result is what Load returns: the resolved settings, which source they actually came from, and (if a disk file was present but rejected) a human-readable reason -- the same shape machineconfig.Result uses, for the same reason: this package doesn't write to stderr itself, leaving that to the caller.

func Load

func Load(diskPath string, embedded []byte, validThemes, validFonts []string) (*Result, error)

Load resolves settings.json: diskPath if it exists and is valid, otherwise embedded (also validated, as a safety net against this package's own built-in default ever drifting out of sync with validThemes/validFonts -- a bug in the embedded default should fail loudly, not silently serve broken settings).

diskPath may be empty (no override configured), in which case only embedded is tried.

type Settings

type Settings struct {
	Version int `json:"version"`
	// Theme is a zenui.ThemeName's own string value (Dark, Light, or
	// Spectrum, matching zenui.ThemeSpectrum's own constant) -- kept
	// as a plain string here rather than importing zenui, so this
	// package has no GUI-layer dependency of its own.
	Theme string `json:"theme"`
	// Font is a fonts.Name's own string value (Sinclair, TomThumb,
	// Spleen, Cozette, Creep, or HaxorMedium) -- same reasoning as
	// Theme above.
	Font string `json:"font"`
	// FontZoom is the dropdown text's own magnification (1-3),
	// distinct from DisplayScale below.
	FontZoom int `json:"fontZoom"`
	// DisplayScale is the emulated Spectrum display's own window
	// multiplier.
	DisplayScale int `json:"displayScale"`
	// FixedMenuBar mirrors appMenuBar.fixed -- whether the bar is
	// pinned permanently shown.
	FixedMenuBar bool `json:"fixedMenuBar"`
}

Settings is the top-level shape of settings.json.

Jump to

Keyboard shortcuts

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