config

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package config handles loading and validation of TOML configuration files.

Index

Constants

View Source
const LeaveEmpty = "leaveEmptyToken"

Variables

This section is empty.

Functions

func Cond added in v1.3.0

func Cond(cond, a *string, b string) string

func CreateDefaultConfig added in v1.3.0

func CreateDefaultConfig(path string) error

Types

type Config

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

func NewConfig added in v0.1.0

func NewConfig(path string) (*Config, error)

func (*Config) Get added in v0.1.0

func (c *Config) Get() *RawConfig

func (*Config) Reload added in v0.1.0

func (c *Config) Reload() error

type ConfigFileType

type ConfigFileType int
const (
	Static ConfigFileType = iota
	Template
)

func (*ConfigFileType) MarshalTOML added in v0.1.0

func (e *ConfigFileType) MarshalTOML() ([]byte, error)

func (*ConfigFileType) UnmarshalTOML

func (e *ConfigFileType) UnmarshalTOML(value any) error

func (ConfigFileType) Value

func (e ConfigFileType) Value() string

type DbusQueryObject

type DbusQueryObject struct {
	Destination              string               `toml:"destination"`
	Path                     string               `toml:"path"`
	Method                   string               `toml:"method"`
	Args                     []DbusQueryObjectArg `toml:"args"`
	ExpectedDischargingValue string               `toml:"expected_discharging_value"`
	ExpectedLidClosingValue  string               `toml:"expected_lid_closing_value"`
}

func (*DbusQueryObject) CollectArgs

func (d *DbusQueryObject) CollectArgs() []interface{}

func (*DbusQueryObject) Validate

func (d *DbusQueryObject) Validate(defaultDestination, defaultMethod, defaultPath,
	defaultExpectedDischargingValue string,
	defaultArgs []DbusQueryObjectArg, defaultExpectedLidClosingValue string,
) error

type DbusQueryObjectArg

type DbusQueryObjectArg struct {
	Arg string `toml:"arg"`
}

type DbusSignalMatchRule

type DbusSignalMatchRule struct {
	Sender     *string `toml:"sender"`
	Interface  *string `toml:"interface"`
	Member     *string `toml:"member"`
	ObjectPath *string `toml:"object_path"`
}

func (*DbusSignalMatchRule) Validate

func (dr *DbusSignalMatchRule) Validate(defaultInterface, defaultMember, defaultObjectPath string) error

type DbusSignalReceiveFilter

type DbusSignalReceiveFilter struct {
	Name *string `toml:"name"`
	Body *string `toml:"body"`
}

func (*DbusSignalReceiveFilter) Validate

func (d *DbusSignalReceiveFilter) Validate() error

type GeneralSection

type GeneralSection struct {
	Destination    *string `toml:"destination"`
	DebounceTimeMs *int    `toml:"debounce_time_ms"`
	PostApplyExec  *string `toml:"post_apply_exec"`
	PreApplyExec   *string `toml:"pre_apply_exec"`
}

func (*GeneralSection) Validate

func (g *GeneralSection) Validate() error

type HotReloadSection added in v0.1.0

type HotReloadSection struct {
	UpdateDebounceTimer *int `toml:"debounce_time_ms"`
}

func (*HotReloadSection) Validate added in v0.1.0

func (h *HotReloadSection) Validate() error

type LidSection added in v1.3.0

type LidSection struct {
	DbusSignalMatchRules     []*DbusSignalMatchRule     `toml:"dbus_signal_match_rules"`
	DbusSignalReceiveFilters []*DbusSignalReceiveFilter `toml:"dbus_signal_receive_filters"`
	DbusQueryObject          *DbusQueryObject           `toml:"dbus_query_object"`
}

func (*LidSection) Validate added in v1.3.0

func (ls *LidSection) Validate() error

type LidStateType added in v1.3.0

type LidStateType int
const (
	UnknownLidStateType LidStateType = iota
	OpenedLidStateType
	ClosedLidStateType
)

func (*LidStateType) MarshalTOML added in v1.3.0

func (e *LidStateType) MarshalTOML() ([]byte, error)

func (*LidStateType) UnmarshalTOML added in v1.3.0

func (e *LidStateType) UnmarshalTOML(value any) error

func (LidStateType) Value added in v1.3.0

func (e LidStateType) Value() string

type Notifications added in v0.1.0

type Notifications struct {
	Disabled  *bool  `toml:"disabled"`
	TimeoutMs *int32 `toml:"timeout_ms"`
}

func (*Notifications) Validate added in v0.1.0

func (n *Notifications) Validate() error

type PowerSection

type PowerSection struct {
	DbusSignalMatchRules     []*DbusSignalMatchRule     `toml:"dbus_signal_match_rules"`
	DbusSignalReceiveFilters []*DbusSignalReceiveFilter `toml:"dbus_signal_receive_filters"`
	DbusQueryObject          *DbusQueryObject           `toml:"dbus_query_object"`
}

func (*PowerSection) Validate

func (ps *PowerSection) Validate() error

type PowerStateType

type PowerStateType int
const (
	BAT PowerStateType = iota
	AC
)

func (*PowerStateType) MarshalTOML added in v0.1.0

func (e *PowerStateType) MarshalTOML() ([]byte, error)

func (*PowerStateType) UnmarshalTOML

func (e *PowerStateType) UnmarshalTOML(value any) error

func (PowerStateType) Value

func (e PowerStateType) Value() string

type Profile

type Profile struct {
	Name                 string            `toml:"-"`
	ConfigFileModTime    time.Time         `toml:"-"`
	ConfigFileDir        string            `toml:"-"`
	ConfigFile           string            `toml:"config_file"`
	ConfigType           *ConfigFileType   `toml:"config_file_type"`
	Conditions           *ProfileCondition `toml:"conditions"`
	StaticTemplateValues map[string]string `toml:"static_template_values"`
	IsFallbackProfile    bool              `toml:"-"`
	PostApplyExec        *string           `toml:"post_apply_exec"`
	PreApplyExec         *string           `toml:"pre_apply_exec"`
	KeyOrder             int               `toml:"-"`
}

func (*Profile) SetPath added in v1.0.0

func (p *Profile) SetPath(configPath string) error

func (*Profile) Validate

func (p *Profile) Validate(configPath string) error

type ProfileCondition

type ProfileCondition struct {
	RequiredMonitors []*RequiredMonitor `toml:"required_monitors"`
	PowerState       *PowerStateType    `toml:"power_state"`
	LidState         *LidStateType      `toml:"lid_state"`
}

func (*ProfileCondition) IsEmpty added in v0.1.0

func (pc *ProfileCondition) IsEmpty() bool

func (*ProfileCondition) Validate

func (pc *ProfileCondition) Validate() error

type RawConfig added in v0.1.0

type RawConfig struct {
	ConfigDirPath        string              `toml:"-"`
	ConfigPath           string              `toml:"-"`
	Profiles             map[string]*Profile `toml:"profiles"`
	FallbackProfile      *Profile            `toml:"fallback_profile"`
	General              *GeneralSection     `toml:"general"`
	Scoring              *ScoringSection     `toml:"scoring"`
	PowerEvents          *PowerSection       `toml:"power_events"`
	LidEvents            *LidSection         `toml:"lid_events"`
	HotReload            *HotReloadSection   `toml:"hot_reload_section"`
	Notifications        *Notifications      `toml:"notifications"`
	StaticTemplateValues map[string]string   `toml:"static_template_values"`
	KeysOrder            []string            `toml:"-"`
	TUISection           *TUISection         `toml:"tui"`
}

func Load

func Load(configPath string) (*RawConfig, error)

func (*RawConfig) OrderedProfileKeys added in v1.0.3

func (c *RawConfig) OrderedProfileKeys() []string

OrderedProfileKeys returns the profile names in the order they appear in the toml file

func (*RawConfig) Validate added in v0.1.0

func (c *RawConfig) Validate() error

type RequiredMonitor

type RequiredMonitor struct {
	Name                       *string        `toml:"name"`
	Description                *string        `toml:"description"`
	MonitorTag                 *string        `toml:"monitor_tag"`
	MatchDescriptionUsingRegex *bool          `toml:"match_description_using_regex"`
	MatchNameUsingRegex        *bool          `toml:"match_name_using_regex"`
	DescriptionRegex           *regexp.Regexp `toml:"-"`
	NameRegex                  *regexp.Regexp `toml:"-"`
}

func (*RequiredMonitor) HasDescription added in v1.3.9

func (rm *RequiredMonitor) HasDescription() bool

func (*RequiredMonitor) HasName added in v1.3.9

func (rm *RequiredMonitor) HasName() bool

func (*RequiredMonitor) MatchDescription added in v1.3.9

func (rm *RequiredMonitor) MatchDescription(desc string) bool

func (*RequiredMonitor) MatchName added in v1.3.9

func (rm *RequiredMonitor) MatchName(name string) bool

func (*RequiredMonitor) Validate

func (rm *RequiredMonitor) Validate() error

type ScoringSection

type ScoringSection struct {
	NameMatch        *int `toml:"name_match"`
	DescriptionMatch *int `toml:"description_match"`
	PowerStateMatch  *int `toml:"power_state_match"`
	LidStateMatch    *int `toml:"lid_state_match"`
}

func (*ScoringSection) Validate

func (s *ScoringSection) Validate() error

type TUIColors added in v1.4.0

type TUIColors struct {
	SourceFile    *string `toml:"source"`
	SourceFileDir *string `toml:"-"`

	// Pane borders
	ActivePaneColor   *string `toml:"active_pane_color"`
	InactivePaneColor *string `toml:"inactive_pane_color"`

	// Header colors
	HeaderColor          *string `toml:"header_color"`
	HeaderIndicatorColor *string `toml:"header_indicator_color"`
	HeaderIndicatorBg    *string `toml:"header_indicator_bg"`

	// Program name in the top bar
	ProgramNameColor *string `toml:"program_name_color"`
	ProgramNameBg    *string `toml:"program_name_bg"`

	// Status colors
	ErrorColor   *string `toml:"error_color"`
	ErrorBg      *string `toml:"error_bg"`
	SuccessColor *string `toml:"success_color"`
	SuccessBg    *string `toml:"success_bg"`
	WarningColor *string `toml:"warning_color"`
	MutedColor   *string `toml:"muted_color"`

	// Tab colors
	TabActiveColor   *string `toml:"tab_active_color"`
	TabActiveBg      *string `toml:"tab_active_bg"`
	TabInactiveColor *string `toml:"tab_inactive_color"`
	TabInactiveBg    *string `toml:"tab_inactive_bg"`

	// Monitor lists colors
	MonitorColorModeColor     *string `toml:"monitor_color_mode_color"`
	MonitorScaleModeColor     *string `toml:"monitor_scale_mode_color"`
	MonitorMirroringModeColor *string `toml:"monitor_mirroring_mode_color"`
	MonitorEditingModeColor   *string `toml:"monitor_editing_mode_color"`
	MonitorModeSelectionColor *string `toml:"monitor_mode_selection_color"`

	// Lists
	ListItemSubtitleColor   *string `toml:"list_item_subtitle_color"`
	ListItemUnselectedColor *string `toml:"list_item_unselected_color"`
	ListItemSelectedColor   *string `toml:"list_item_selected_color"`

	// Legend and selection
	LegendColor                *string `toml:"legend_color"`
	LegendSelectedMonitorColor *string `toml:"legend_selected_monitor_color"`
	LegendSelectedMonitorBg    *string `toml:"legend_selected_monitor_bg"`

	// Title and subtitle colors
	TitleColor    *string `toml:"title_color"`
	SubtitleColor *string `toml:"subtitle_color"`
	InfoColor     *string `toml:"info_color"`
	LinkColor     *string `toml:"link_color"`

	// Grid and monitor edge colors
	GridDotColor                           *string   `toml:"grid_dot_color"`
	MonitorEdgeColors                      *[]string `toml:"monitor_edge_colors"`
	MonitorFillColorsUnselected            *[]string `toml:"monitor_fill_colors_unselected"`
	MonitorFillColorsSelected              *[]string `toml:"monitor_fill_colors_selected"`
	MonitorBottomColors                    *[]string `toml:"monitor_bottom_colors"`
	MonitorPreviewPaneLabelBackgroundColor *string   `toml:"monitor_preview_pane_label_bg"`
	GridSnappingLineColor                  *string   `toml:"grid_snapping_line_color"`

	// Help
	HelpKeyColor         *string `toml:"help_key_color"`
	HelpDescriptionColor *string `toml:"help_description_color"`
	HelpSeparatorColor   *string `toml:"help_separator_color"`
}

func (*TUIColors) Validate added in v1.4.0

func (t *TUIColors) Validate() error

type TUISection added in v1.4.0

type TUISection struct {
	Colors *TUIColors `toml:"colors"`
}

func (*TUISection) Validate added in v1.4.0

func (t *TUISection) Validate(configDirPath string) error

Jump to

Keyboard shortcuts

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