config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is a type to mirror viper.Config, but with better custom type support. This stems from the closure of github.com/spf13/viper#271.

func New

func New(opener Opener, name string, dirs ...string) (*Config, error)

New returns a Config for the given Config file name (without extension) and list of valid directories for that file to be found in.

func (*Config) Get

func (c *Config) Get(k string) any

Get gets the value at k. If the default value has been set using SetDefault, the data will be converted to the same type as the default value.

func (*Config) Keys

func (c *Config) Keys() []string

Keys returns a list of all keys available in c.

func (*Config) Set

func (c *Config) Set(k string, v any)

Set sets the value at k.

func (*Config) SetDefault

func (c *Config) SetDefault(k string, v any)

SetDefault sets the type and the default value for the data at k.

func (*Config) Write

func (c *Config) Write() error

Write writes c to the path it was opened from, or the most preferred path path otherwise.

type Opener

type Opener interface {
	Open(path string) (f io.ReadCloser, err error)
	Create(path string) (f io.WriteCloser, err error)
}

Opener is a type which can read files.

type Prefs

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

func NewPrefs

func NewPrefs() *Prefs

func (*Prefs) Font

func (p *Prefs) Font(ctx context.Context) *string

Font returns the user's preferred font.

TODO: - decide how to represent fonts. - figure out how to load system fonts properly. - figure out how to set font preferences.

func (*Prefs) Glob

func (p *Prefs) Glob(ctx context.Context, pattern string) []string

func (*Prefs) Lookup

func (p *Prefs) Lookup(file, key string) (any, error)

func (*Prefs) SetDefault

func (p *Prefs) SetDefault(file, key string, v any) error

func (*Prefs) UI

func (p *Prefs) UI(ctx context.Context, l ...ui.NamedConstructor) (string, ui.Creator, error)

UI finds the user's preferred UI plugin and returns it. The name of the chosen UI will be returned even if the ui errors, so that logs/output are able to include the UI library's name.

TODO:

  • Add user preference settings for UIs
  • Actually loop through the list looking for a preferred UI
  • Handle errors, maybe falling back to other UIs if the preferred one fails.

Jump to

Keyboard shortcuts

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