settings

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package settings stores ZPad's preferences in the user data directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ensure

func Ensure(dir string, s Settings) error

Ensure writes s when dir has no settings file yet, so a first launch leaves the defaults on disk for the user to inspect and edit.

func Save

func Save(dir string, s Settings) error

Save writes s atomically to dir/settings.json.

Types

type Settings

type Settings struct {
	Theme    string `json:"theme"`    // system | light | dark | a named theme id
	Language string `json:"language"` // "" follows the system, else zh-Hans | en

	FontFamily string  `json:"fontFamily"` // "" is the system's monospaced font
	FontSize   float32 `json:"fontSize"`
	LineHeight float32 `json:"lineHeight"`

	SoftWrap    bool   `json:"softWrap"`
	LineNumbers string `json:"lineNumbers"` // absolute | relative | off
	TabSize     int    `json:"tabSize"`
	UseTabs     bool   `json:"useTabs"`
	ShowGuides  bool   `json:"showGuides"`
	// Whitespace says where spaces show as dots and tabs as arrows:
	// selection | none | all | trailing.
	Whitespace string `json:"whitespace"`
	AutoClose  bool   `json:"autoClose"`
	// VimMode makes every editor modal: normal, insert and visual modes,
	// with Vim's motions and operators. It is off by default.
	VimMode bool `json:"vimMode"`

	DefaultEncoding string `json:"defaultEncoding"`   // utf-8 | utf-8-bom | utf-16le | utf-16be | gb18030
	DefaultEOL      string `json:"defaultLineEnding"` // "\n" | "\r\n" | "\r"
	LargeFileMB     int    `json:"largeFileMB"`

	SidebarOpen    bool    `json:"sidebarOpen"`
	SidebarWidth   float32 `json:"sidebarWidth"`
	ShowHidden     bool    `json:"showHidden"`
	RestoreSession bool    `json:"restoreSession"`
	ConfirmClose   bool    `json:"confirmClose"`
	// PreviewTabs opens a file clicked in the workspace tree as a preview
	// tab: the next click replaces it, and a double click, an edit or a
	// save keeps it. Turning it off opens every click for good.
	PreviewTabs bool `json:"previewTabs"`
	// KeepUnsaved keeps unsaved content, including untitled documents, in
	// the user data directory and restores it on the next launch, instead
	// of asking to save it when the window closes or the app quits.
	KeepUnsaved bool `json:"keepUnsaved"`
}

Settings is everything ZPad remembers between launches.

Fields are exported so the view can read them directly and tests can build values without a constructor. Missing fields in an older file keep the defaults of Default.

func Default

func Default() Settings

Default returns the settings of a first launch.

func Load

func Load(dir string) (Settings, error)

Load reads dir/settings.json. A missing file returns the defaults. A corrupt file is copied to settings.json.bak and the defaults are used.

Jump to

Keyboard shortcuts

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