settings

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 9 Imported by: ? 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 keeps mdsh-gui's app-wide settings in a JSON file in the user's config folder.

Index

Constants

View Source
const MaxFileViews = 100

MaxFileViews is how many files' views are remembered.

View Source
const MaxPlaces = 100

MaxPlaces is how many files' window places are remembered.

View Source
const MaxRecent = 10

MaxRecent is how many files Open Recent remembers.

View Source
const SecretShowDefault = 60 * time.Second

SecretShowDefault is how long a secret stays shown, or on the clipboard, unless the settings say otherwise.

Variables

This section is empty.

Functions

func CleanTypes

func CleanTypes(list []string) []string

CleanTypes is list as OpenTypes keeps it: lower case, without dots or spaces, each once, and none empty.

func DefaultPath

func DefaultPath() (string, error)

DefaultPath is where the settings live: mdsh/gui.json in the user's config folder.

Types

type FileView

type FileView struct {
	File    string `json:"file"`
	View    string `json:"view"`
	History bool   `json:"history,omitempty"`
}

FileView is how a file was last shown: View is "rendered", "source" or "both", and History is whether the History pane was open.

type Place

type Place struct {
	File   string `json:"file"`
	X      int    `json:"x"`
	Y      int    `json:"y"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Place is where a file's window was and how big, in the screen's points. X and Y are its top left corner.

type Settings

type Settings struct {
	// Autosave saves the file after each run.
	Autosave bool `json:"autosave"`
	// Vim turns on Vim key bindings in the code editors.
	Vim bool `json:"vim"`
	// NoSpellCheck turns off spell checking of the prose in the code
	// editor, which is on by default.
	NoSpellCheck bool `json:"noSpellCheck"`
	// Neovim makes the source pane an embedded Neovim, when Vim is on
	// and a new enough nvim is found. Experimental.
	Neovim bool `json:"neovim"`
	// NeovimPath is the nvim to run; empty finds one.
	NeovimPath string `json:"neovimPath"`
	// NeovimClean starts Neovim without the user's config.
	NeovimClean bool `json:"neovimClean"`
	// NeovimOwnColors keeps the colorscheme from the user's Neovim
	// config, rather than the app's theme, which is the default.
	NeovimOwnColors bool `json:"neovimOwnColors"`
	// Serve lets mdsh-gui serve notebooks: to a web browser on this
	// machine, from File › Serve in Browser, and to the program that
	// started it with --serve=stdio. Experimental, and off by default.
	Serve bool `json:"serve"`
	// Theme is "light" or "dark"; empty follows the system.
	Theme string `json:"theme"`
	// Look is a look's id from its look.css in web/looks, such as
	// "tty" for Teletype; empty is the plain look.
	Look string `json:"look"`
	// TextSize is the text's size in percent, 80 to 150; 0 is the
	// look's own (100 for plain, 115 for Teletype).
	TextSize int `json:"textSize"`
	// UIFont and CodeFont are font families for the interface and for
	// code; empty is the look's own.
	UIFont   string `json:"uiFont"`
	CodeFont string `json:"codeFont"`
	// LineSpacing is "compact" or "relaxed"; empty is normal.
	LineSpacing string `json:"lineSpacing"`
	// NoSprockets, NoRules and NoShadows take the Teletype paper's
	// sprocket strips, its line rules and the shadows under cards off.
	NoSprockets bool `json:"noSprockets"`
	NoRules     bool `json:"noRules"`
	NoShadows   bool `json:"noShadows"`
	// Accent is a #rrggbb color for links, run buttons and selection;
	// empty is the look's own.
	Accent string `json:"accent"`
	// HistoryPane is the History pane's colors: "match" the window,
	// "invert" them (light under a dark window, dark under a light one)
	// or "dark" always. Empty is the look's own: dark for plain, match
	// for Teletype.
	HistoryPane string `json:"historyPane"`
	// HistoryFocus is how the History pane's prompt shows it has the
	// keyboard: "cursor" for a blinking block cursor where you type,
	// in place of the outline around the field. Empty is the outline.
	HistoryFocus string `json:"historyFocus"`
	// SecretShowSeconds is how long a block's secret stays shown after
	// its eye button shows it, and on the clipboard after it is copied.
	// 0 is SecretShowDefault.
	SecretShowSeconds int `json:"secretShowSeconds"`
	// Shell, if set, overrides the front matter's shell for every file.
	Shell string `json:"shell"`
	// HistoryRC is a file, such as ~/.zshrc, the shells read while the
	// History pane is on. Empty reads none.
	HistoryRC string `json:"historyRC"`
	// HistoryReuse has a command typed in the History pane that was
	// typed before, and so has a #history-N block, run that block again,
	// keeping its last output as an earlier run, rather than add another
	// block. Off adds a block for every command.
	HistoryReuse bool `json:"historyReuse"`
	// View is how a file opens: "rendered", "source" or "both".
	// Empty opens a file as it was last shown (see FileViews), and a
	// file not shown before in the rendered view.
	View string `json:"view"`
	// StartFolder is the folder the start screen lists when the app
	// isn't started from a terminal. Empty means the last folder used.
	StartFolder string `json:"startFolder"`
	// TemplateFolder holds the markdown files New File… offers to start
	// from. Empty offers only a blank file.
	TemplateFolder string `json:"templateFolder"`
	// SessionFolder is where New Session makes a file for the day and
	// Last Session finds the latest. Empty is ~/.mdsh/sessions.
	SessionFolder string `json:"sessionFolder"`
	// SessionTemplate is a markdown file a new session starts as a copy
	// of. Empty starts it with a heading for the date.
	SessionTemplate string `json:"sessionTemplate"`
	// OpenTypes are the file extensions, such as "pdf", that a link in
	// a document opens with the system's app for them. A link to any
	// other file the app doesn't show itself is shown in the file
	// manager instead, so one click on a link can't run something.
	OpenTypes []string `json:"openTypes,omitempty"`
	// LastFolder is the folder of the file opened last.
	LastFolder string `json:"lastFolder"`
	// Recent are the files opened last, newest first.
	Recent []string `json:"recent"`
	// Pinned are the files pinned to the top of the start screen, in
	// the order they were pinned.
	Pinned []string `json:"pinned,omitempty"`
	// Places are where the windows of the files last shown alone in a
	// new window were, newest first.
	Places []Place `json:"places,omitempty"`
	// FileViews are how the files shown last were left, newest first:
	// the view and whether the History pane was open.
	FileViews []FileView `json:"fileViews,omitempty"`
}

Settings are the app-wide settings. The zero value is the default.

func (Settings) FileView

func (s Settings) FileView(file string) (FileView, bool)

FileView is how file was last shown, if that is remembered.

func (*Settings) OpenType

func (s *Settings) OpenType(path string) bool

OpenType reports whether a link to path opens with the system's app, as OpenTypes says for its extension.

func (*Settings) Opened

func (s *Settings) Opened(file string)

Opened notes that file was opened: it goes to the top of Recent and its folder becomes LastFolder.

func (*Settings) Pin

func (s *Settings) Pin(file string, pin bool) bool

Pin pins file to the start screen, after the files pinned before it, or unpins it. It reports whether that changed anything.

func (Settings) Place

func (s Settings) Place(file string) (Place, bool)

Place is where file's window was last, if that is remembered.

func (*Settings) Placed

func (s *Settings) Placed(p Place) bool

Placed remembers where p.File's window is: p goes to the top of Places, and the oldest are forgotten past MaxPlaces. It reports whether that changed anything.

func (Settings) SecretShow

func (s Settings) SecretShow() time.Duration

SecretShow is how long a secret stays shown, or on the clipboard.

func (Settings) StartDir

func (s Settings) StartDir(cwd, home, documents string) string

StartDir is the folder the start screen lists. Started from a terminal, that is the current folder cwd. Started from Finder or the Dock the current folder is /, so it is StartFolder, else LastFolder, else documents (~/Documents on macOS), else home. Folders that no longer exist are passed over.

func (*Settings) Viewed

func (s *Settings) Viewed(v FileView) bool

Viewed remembers how v.File is shown: v goes to the top of FileViews, and the oldest are forgotten past MaxFileViews. It reports whether that changed anything.

type Store

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

Store reads and writes Settings.

func Open

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

Open reads the settings in path. A missing file gives the defaults.

func (*Store) Get

func (st *Store) Get() Settings

Get returns a copy of the settings.

func (*Store) OnChange

func (st *Store) OnChange(fn func(Settings))

OnChange has fn called with the settings after each Update, such as for a menu that follows one.

func (*Store) Path

func (st *Store) Path() string

Path is the file the settings live in.

func (*Store) Update

func (st *Store) Update(f func(*Settings)) error

Update changes the settings with f and writes them out, then calls the functions OnChange was given.

Jump to

Keyboard shortcuts

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