Documentation
¶
Overview ¶
Package config reads what the desktop app writes: the runtime config (`zennotes.config.json`, where the known vaults and saved servers live) and the portable preferences (`config.toml`). It never writes the former; zn follows the app, it does not steer it.
Index ¶
- Constants
- Variables
- func ConfigTomlPath() string
- func CredentialsPath() string
- func CredentialsProblem() error
- func CustomThemesDir() string
- func DefaultServerName(baseURL string) string
- func DeleteToken(baseURL string) error
- func ExpandHome(target string) string
- func LoadToken(baseURL string) string
- func MCPInstructionsPath() string
- func PortableConfigDir() string
- func PreamblePath() string
- func RemoveViewModeRule(key string) error
- func ResolveVaultRoot(selector string) (string, error)
- func ResolveVaultSelector(selector string) (string, error)
- func SaveChanges(before, after Prefs) error
- func SaveToken(baseURL, token string) error
- func SaveWorkspaces(ws Workspaces) error
- func SetValue(section, key string, value any) error
- func SetViewModeRule(key, mode string) error
- func UpdateConfig(edit func(map[string]any) error) error
- func UserDataDir() string
- func ValidateConfig() error
- func ValidateViewModeRule(key, mode string) error
- func ValueTables(p Prefs) map[string]map[string]any
- func VaultRootFromConfig() string
- func WorkspacesPath() string
- type ActiveWorkspace
- type KnownVault
- type LocalWorkspace
- type Prefs
- type RemoteProfile
- type ServerWorkspace
- type ViewModeRule
- type ViewModeRuleEntry
- type Workspaces
- func (ws *Workspaces) AddServer(name, baseURL string) ServerWorkspace
- func (ws *Workspaces) AddVault(name, root string) LocalWorkspace
- func (ws Workspaces) FindServer(selector string) *ServerWorkspace
- func (ws Workspaces) FindVault(selector string) *LocalWorkspace
- func (ws Workspaces) Names() []string
- func (ws *Workspaces) Remove(name string) (string, bool)
- func (ws Workspaces) SortedVaults() []LocalWorkspace
- func (ws Workspaces) UniqueName(base string) string
Constants ¶
const AppConfigFile = "zennotes.config.json"
AppConfigFile is the runtime config the desktop app maintains.
const DefaultConfigTOML = `` /* 2422-byte string literal not displayed */
DefaultConfigTOML is the commented starter file `zn config` writes when no config.toml exists yet. Every key matches the desktop app's names.
Variables ¶
var ErrNoVault = errors.New("No vault is set up for zn yet. Run `zn setup` for a guided start, or one of: `zn init ~/Notes` (create a vault), `zn vault add <folder>` (use an existing one), `zn connect <server-url>` (a ZenNotes server). Opening a vault in the ZenNotes app works too.")
ErrNoVault says nothing names a vault at all.
var ErrNoWorkspace = errors.New("no saved vault or server has that name")
ErrNoWorkspace says a name matches nothing zn saved.
var ViewModeModes = []string{"edit", "split", "preview"}
ViewModeModes are the pane modes a rule can name.
Functions ¶
func CredentialsPath ¶
func CredentialsPath() string
CredentialsPath is where server tokens live (mode 0600).
func CredentialsProblem ¶ added in v0.6.1
func CredentialsProblem() error
CredentialsProblem says when the token store exists but cannot be read.
func CustomThemesDir ¶ added in v0.3.0
func CustomThemesDir() string
CustomThemesDir is where the desktop app keeps user-authored themes, one folder each, next to config.toml.
func DefaultServerName ¶
DefaultServerName names a server after its host: notes.example.com, or localhost for a local address.
func ExpandHome ¶
ExpandHome turns `~` and `~/x` into absolute paths.
func MCPInstructionsPath ¶
func MCPInstructionsPath() string
MCPInstructionsPath is where a user override of the MCP instructions lives.
func PortableConfigDir ¶
func PortableConfigDir() string
PortableConfigDir is where `config.toml` lives: an XDG-style location the user can sync. Deliberately NOT UserDataDir.
func PreamblePath ¶ added in v0.12.0
func PreamblePath() string
PreamblePath is the user-owned LaTeX preamble for math = "latex".
func RemoveViewModeRule ¶ added in v0.14.0
RemoveViewModeRule deletes the entry stored under the raw key exactly as written, so malformed keys can be removed too. Removing the last rule drops the empty table.
func ResolveVaultRoot ¶
ResolveVaultRoot picks the vault root: an explicit selector, else ZENNOTES_VAULT, else the app's active vault.
func ResolveVaultSelector ¶
ResolveVaultSelector resolves a `--vault` selector: a known vault name first (case-insensitive), then a directory path. Errors name the available vaults so a typo is self-correcting.
func SaveChanges ¶ added in v0.5.0
SaveChanges patches only settings changed by this UI interaction, retaining concurrent changes made by the desktop to unrelated preferences.
func SaveWorkspaces ¶
func SaveWorkspaces(ws Workspaces) error
SaveWorkspaces writes the list atomically. A list that stands in for a file zn could not read is never written back over it.
func SetValue ¶ added in v0.5.0
SetValue edits one portable preference while retaining every other table, including settings from newer desktop versions. nil removes a map entry.
func SetViewModeRule ¶ added in v0.14.0
SetViewModeRule adds or changes one [terminal.view_mode_rules] entry, keeping every other key and table. An entry already in the file for the same field and value, written in any case or quoting and valid or not, is changed in place instead of gaining a duplicate. Rules already in the file that are malformed never block the write.
func UpdateConfig ¶ added in v0.5.0
UpdateConfig applies a targeted edit to the latest file. A parse failure or a concurrent external edit leaves the original file untouched.
func UserDataDir ¶
func UserDataDir() string
UserDataDir mirrors Electron's `app.getPath('userData')` for the product name "ZenNotes". ZENNOTES_CONFIG_DIR overrides it, for tests and automation.
func ValidateConfig ¶ added in v0.6.0
func ValidateConfig() error
ValidateConfig checks supported values without rewriting the user's file.
func ValidateViewModeRule ¶ added in v0.14.0
ValidateViewModeRule is the check writers run before storing a rule.
func ValueTables ¶ added in v0.5.0
ValueTables contains the portable settings the terminal can edit. Keeping their file names in one place also drives the in-app settings controls.
func VaultRootFromConfig ¶
func VaultRootFromConfig() string
VaultRootFromConfig is the vault the app last opened, or "".
func WorkspacesPath ¶
func WorkspacesPath() string
WorkspacesPath is where zn's vault and server list lives.
Types ¶
type ActiveWorkspace ¶
type ActiveWorkspace struct {
// Kind is "local" or "remote".
Kind string
Root string
BaseURL string
Name string
ProfileID string
AuthToken string
}
ActiveWorkspace is what the desktop app currently has open.
func ActiveWorkspaceFromConfig ¶
func ActiveWorkspaceFromConfig() ActiveWorkspace
ActiveWorkspaceFromConfig reads the workspace the app has open. The app keeps server tokens in the OS secret store, so the token here is only a legacy plaintext one; callers layer ZENNOTES_REMOTE_TOKEN on top.
type KnownVault ¶
type KnownVault struct {
Root string `json:"root"`
Name string `json:"name"`
LastOpenedAt *int64 `json:"lastOpenedAt"`
}
KnownVault is one local vault the app knows about.
func KnownVaults ¶
func KnownVaults() []KnownVault
KnownVaults lists every local vault the app knows: its `localVaults` list plus the active `vaultRoot` when it is not listed. Most recently opened first.
type LocalWorkspace ¶
LocalWorkspace is a vault directory zn remembers.
type Prefs ¶
type Prefs struct {
VimWrappedLineMotions string
IgnoredKeys []string
VimMode bool
VimInsertEscape string
VimYankToClipboard bool
WhichKeyHints bool
WhichKeyHintMode string
WhichKeyHintTimeoutMs int
SyncTitleHeadingOnRename bool
EditorTabSize int
EditorScrollOff int
WordWrap bool
DefaultPaneMode string
LineNumberMode string
CompletedTaskStyle string
TimeFormat string
AutoPairs bool
AutoPairQuotesInProse bool
TabsEnabled bool
WrapTabs bool
RetainViewMode bool
MarkdownSnippets bool
HideBuiltinTemplates bool
TextReplacementsEnabled bool
TextReplacements map[string]string
// ThemeFamily, ThemeMode and ThemeID are the desktop's theme selection;
// ThemeTweaks its Quick tweaks (accent and syntax hues, by slug).
ThemeFamily string
ThemeMode string
ThemeID string
ThemeTweaks map[string]string
UnifiedSidebar bool
NoteSortOrder string
GroupByKind bool
NestedTags bool
QuickNoteDateTitle bool
QuickNoteTitlePrefix string
CalendarWeekStart string
CalendarShowWeekNumbers bool
TasksViewMode string
TasksListOrder string // note | priority: the desktop's Order menu above the Tasks list (#989)
ShowArchivedTasks bool
KanbanGroupBy string
KanbanFolderRoot string
SavedTaskFilters map[string]string
KanbanStatuses []string
KanbanColumnTitles map[string]string
SystemFolderLabels map[string]string
WorkflowsEnabled bool
AtlasEnabled bool
KeymapOverrides map[string]string
// Terminal-only preferences, from [terminal] in config.toml. The desktop
// app ignores the table.
TerminalMouse bool
// Autosave writes notes shortly after typing stops and when they close.
// Off, a note reaches the disk only when saved by name, such as with :w.
Autosave bool
PreviewStyle string
// TerminalImages is auto, kitty or off: whether the preview paints
// pictures with the Kitty graphics protocol.
TerminalImages string
// TerminalTheme names a theme for zn alone: a family, a theme id or a
// custom theme. Empty follows the desktop's [appearance] selection.
TerminalTheme string
// TerminalMath is typst or latex: the engine for display math. Anything
// else loads as typst; zn doctor reports it.
TerminalMath string
// TerminalViewModeField names the frontmatter field that picks a note's
// pane mode when it opens in a new tab. Empty turns the feature off.
TerminalViewModeField string
// ViewModeRules maps "<key>=<value>" to a pane mode, from
// [terminal.view_mode_rules]. Entries are raw; see ViewModeRuleEntries.
ViewModeRules map[string]string
// RenderTimeout (seconds) bounds one external render; RenderConcurrency
// caps how many run at once. Non-positive values load as the defaults.
RenderTimeout int
RenderConcurrency int
}
Prefs is the slice of the portable preferences the CLI and the terminal UI honor. Defaults match the desktop's PORTABLE_DEFAULTS; a missing file or key keeps the default.
type RemoteProfile ¶
type RemoteProfile struct {
ID string
Name string
BaseURL string
AuthToken string
LastConnectedAt *int64
}
RemoteProfile is a saved ZenNotes server.
func RemoteProfiles ¶
func RemoteProfiles() []RemoteProfile
RemoteProfiles lists every server the app has been connected to, newest first, the legacy single-server `remoteWorkspace` key folded in.
type ServerWorkspace ¶
ServerWorkspace is a ZenNotes server zn remembers; its token is stored separately, keyed by URL.
type ViewModeRule ¶ added in v0.14.0
ViewModeRule is one valid [terminal.view_mode_rules] entry in normalised form: the frontmatter key and value are lower-cased and unquoted, and the mode is edit, split or preview.
func ParseViewModeRule ¶ added in v0.14.0
func ParseViewModeRule(key, mode string) (ViewModeRule, string)
ParseViewModeRule validates one "<key>=<value>" entry and its mode. The first "=" splits key from value; both must be non-empty, and the mode must be edit, split or preview. On failure it returns a short reason.
func ValidViewModeRules ¶ added in v0.14.0
func ValidViewModeRules(raw map[string]string) []ViewModeRule
ValidViewModeRules returns the usable rules in match order: sorted by the lower-cased "key=value" in byte order. Invalid entries are left out.
type ViewModeRuleEntry ¶ added in v0.14.0
type ViewModeRuleEntry struct {
Key string
Mode string
Valid bool
Reason string
Rule ViewModeRule
}
ViewModeRuleEntry is one entry as written in the file. Key and Mode are the raw strings, so a malformed entry can still be shown and removed. A valid entry also carries its normalised Rule.
func ViewModeRuleEntries ¶ added in v0.14.0
func ViewModeRuleEntries(raw map[string]string) []ViewModeRuleEntry
ViewModeRuleEntries returns every entry, valid or not. Valid ones come first in match order, then the invalid ones sorted by raw key.
type Workspaces ¶
type Workspaces struct {
// Default names the workspace zn uses when no flag or environment
// variable picks one; empty means follow the desktop app.
Default string `toml:"default"`
Vaults []LocalWorkspace `toml:"vault"`
Servers []ServerWorkspace `toml:"server"`
// contains filtered or unexported fields
}
Workspaces is the content of workspaces.toml.
func LoadWorkspaces ¶
func LoadWorkspaces() Workspaces
LoadWorkspaces reads the list; a missing or unreadable file is an empty list. LoadWorkspacesFile also reports the latter.
func LoadWorkspacesFile ¶ added in v0.6.1
func LoadWorkspacesFile() (Workspaces, error)
LoadWorkspacesFile reads the list and says when the file exists but could not be read or parsed; a missing file is simply an empty list.
func (*Workspaces) AddServer ¶
func (ws *Workspaces) AddServer(name, baseURL string) ServerWorkspace
AddServer remembers a server; the same URL replaces its entry.
func (*Workspaces) AddVault ¶
func (ws *Workspaces) AddVault(name, root string) LocalWorkspace
AddVault remembers a vault directory; the same root replaces its entry.
func (Workspaces) FindServer ¶
func (ws Workspaces) FindServer(selector string) *ServerWorkspace
FindServer matches a saved server by name (case-insensitive) or URL.
func (Workspaces) FindVault ¶
func (ws Workspaces) FindVault(selector string) *LocalWorkspace
FindVault matches a saved vault by name (case-insensitive) or root.
func (Workspaces) Names ¶
func (ws Workspaces) Names() []string
Names lists every saved workspace name, vaults first.
func (*Workspaces) Remove ¶
func (ws *Workspaces) Remove(name string) (string, bool)
Remove forgets a workspace by name; it reports the kind removed.
func (Workspaces) SortedVaults ¶
func (ws Workspaces) SortedVaults() []LocalWorkspace
SortedVaults returns the vaults by name, for stable listings.
func (Workspaces) UniqueName ¶
func (ws Workspaces) UniqueName(base string) string
UniqueName appends 2, 3… to a name until no saved workspace carries it.