wmconfig

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 20 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 wmconfig reads and edits lys-wm's config file. Edits touch only the bytes of the value they change, so comments, blank lines, key order and keys this program does not know survive, and each edit is held to what it meant by parsing the result before anything is written.

Index

Constants

View Source
const Each = "[]"

Each is the path segment naming every item of a list or every value of a mapping, as in outputs.[].scale.

Variables

This section is empty.

Functions

func ApplyEdit

func ApplyEdit(src []byte, e Edit) ([]byte, error)

ApplyEdit is src with the edit made, or an error naming the line of what it cannot safely change; src is never partly edited.

func Exec

func Exec(ctx context.Context, argv ...string) ([]byte, error)

Exec is the Runner that starts the program.

func Installed

func Installed() bool

Installed reports whether lys-wm is on the path. Without it nothing can check a change, so there is nothing to offer.

func Lookup

func Lookup(tree map[string]any, path []string) (any, bool)

Lookup is the value at path in a tree of keys.

func Merge

func Merge(base, over map[string]any) map[string]any

func Overridden

func Overridden(over map[string]any, path []string) bool

func Tree

func Tree(data []byte) (map[string]any, error)

Tree parses a config's bytes into its keys.

Types

type Action

type Action struct {
	Name    string `json:"name"`
	Args    string `json:"args"`
	Summary string `json:"summary"`
}

type Edit

type Edit struct {
	Path  []string
	Value any
	Unset bool
}

Edit changes one key: Unset removes it, otherwise it takes Value.

func ResetEdits

func ResetEdits(over map[string]any) []Edit

func (Edit) String

func (e Edit) String() string

type Field

type Field struct {
	Kind   Kind
	Format string
	// Variants are the values an Enum takes: strings and booleans, as the file
	// writes them.
	Variants []any
	Min, Max float64
	// MinItems and MaxItems bound how many items a list takes.
	MinItems, MaxItems int
	Default            any
	HasDefault         bool
	Actions            []Action
}

Field is one key of the schema.

func (Field) Normal

func (f Field) Normal(v any) any

Normal is a value as an editor of this key expects it: whole numbers as int64 and the others as float64, whichever form the file wrote, and a list or mapping as the file's decoder reads it.

type File

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

File is lys-wm's config file, the runtime overrides this program writes over it, and the programs that speak for them.

func Open

func Open(getenv func(string) string, run Runner) (*File, error)

Open names the files lys-wm reads under this environment.

func (*File) Apply

func (f *File) Apply(edits []Edit) (Reload, error)

Apply makes the edits to the override file in one write after lys-wm accepted the result, and has a running lys-wm reload it. A refused or impossible change leaves the file as it was; the config file is only read.

func (*File) BuiltIn

func (f *File) BuiltIn() ([]byte, error)

BuiltIn is the config lys-wm runs without a config file.

func (*File) Check

func (f *File) Check(edits []Edit) error

Check reports why lys-wm would refuse the override file with the edits made, or nil when it would take it; nothing is written.

func (*File) Overrides

func (f *File) Overrides() (map[string]any, error)

func (*File) Path

func (f *File) Path() string

Path is the config file's path, the link when it is one.

func (*File) Read

func (f *File) Read() (map[string]any, bool, error)

Read is the config file's keys; false when there is no file.

func (*File) ResetAll

func (f *File) ResetAll() (Reload, error)

func (*File) Runtime

func (f *File) Runtime() string

func (*File) Schema

func (f *File) Schema() (*Schema, error)

Schema is the installed lys-wm's description of its config.

func (*File) Writable

func (f *File) Writable() error

Writable says why the override file cannot be changed, or nil.

type Kind

type Kind int

Kind is what a key holds.

const (
	// Composite is a list, a mapping, or a key taking either of two forms.
	Composite Kind = iota
	Bool
	Int
	Float
	Text
	Enum
	// Switch is false, the key off, or an object of the keys Keys lists.
	Switch
)

type ReadOnlyError

type ReadOnlyError struct {
	Path, Target string
	Err          error
}

ReadOnlyError is an override file this program cannot write.

func (*ReadOnlyError) Error

func (e *ReadOnlyError) Error() string

func (*ReadOnlyError) Unwrap

func (e *ReadOnlyError) Unwrap() error

type RejectedError

type RejectedError struct{ Reason string }

RejectedError is a change lys-wm refused; the file was not touched.

func (*RejectedError) Error

func (e *RejectedError) Error() string

type Reload

type Reload int

Reload is what happened after a change reached the file.

const (
	// Unchanged means the file already said so, and lys-wm was not asked.
	Unchanged Reload = iota
	// Reloaded means the running lys-wm took the change.
	Reloaded
	// NotRunning means no lys-wm answered: the next one reads the change.
	NotRunning
)

type ReloadError

type ReloadError struct{ Reason string }

ReloadError is a change that was written but that lys-wm did not take.

func (*ReloadError) Error

func (e *ReloadError) Error() string

type Runner

type Runner func(ctx context.Context, argv ...string) ([]byte, error)

Runner runs a program to its end; a failure is a *ToolError.

type Schema

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

Schema is lys-wm's config schema, parsed at the boundary.

func ParseSchema

func ParseSchema(data []byte) (*Schema, error)

ParseSchema reads what lys-wm --config-schema prints.

func (*Schema) Field

func (s *Schema) Field(path []string) (Field, bool)

Field finds the key at path; false when this lys-wm has no such key.

func (*Schema) Keys

func (s *Schema) Keys(path []string) ([]string, bool)

Keys lists, sorted, the keys of the object at path, or of a Switch's object form; false when path names no object with keys of its own.

type ToolError

type ToolError struct {
	Argv   []string
	Exit   int
	Stderr string
	Err    error
}

ToolError is a program that failed: what it was asked, and what it said.

func (*ToolError) Error

func (e *ToolError) Error() string

func (*ToolError) Unwrap

func (e *ToolError) Unwrap() error

Jump to

Keyboard shortcuts

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