config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config provides configuration management for dumber with Viper integration.

Package config provides default configuration values for dumber.

Package config provides XDG Base Directory specification compliance utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDirectories

func EnsureDirectories() error

EnsureDirectories creates the XDG directories if they don't exist.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the XDG config directory for dumber.

func GetConfigFile

func GetConfigFile() (string, error)

GetConfigFile returns the path to the main configuration file.

func GetDataDir

func GetDataDir() (string, error)

GetDataDir returns the XDG data directory for dumber.

func GetDatabaseFile

func GetDatabaseFile() (string, error)

GetDatabaseFile returns the path to the database file in the state directory.

func GetDefaultSearchShortcuts

func GetDefaultSearchShortcuts() map[string]SearchShortcut

GetDefaultSearchShortcuts returns the default search shortcuts.

func GetStateDir

func GetStateDir() (string, error)

GetStateDir returns the XDG state directory for dumber.

func Init

func Init() error

Init initializes the global configuration manager.

func OnConfigChange

func OnConfigChange(callback func(*Config))

OnConfigChange registers a callback for global configuration changes.

func Watch

func Watch() error

Watch starts watching the global configuration for changes.

Types

type AppearanceConfig

type AppearanceConfig struct {
	// Default fonts for pages that do not specify fonts.
	SansFont      string `mapstructure:"sans_font" yaml:"sans_font"`
	SerifFont     string `mapstructure:"serif_font" yaml:"serif_font"`
	MonospaceFont string `mapstructure:"monospace_font" yaml:"monospace_font"`
	// Default font size in CSS pixels (approx).
	DefaultFontSize int `mapstructure:"default_font_size" yaml:"default_font_size"`
}

AppearanceConfig holds UI/rendering preferences.

type Config

type Config struct {
	Database        DatabaseConfig            `mapstructure:"database" yaml:"database"`
	History         HistoryConfig             `mapstructure:"history" yaml:"history"`
	SearchShortcuts map[string]SearchShortcut `mapstructure:"search_shortcuts" yaml:"search_shortcuts"`
	Dmenu           DmenuConfig               `mapstructure:"dmenu" yaml:"dmenu"`
	Logging         LoggingConfig             `mapstructure:"logging" yaml:"logging"`
	Appearance      AppearanceConfig          `mapstructure:"appearance" yaml:"appearance"`
	// RenderingMode controls GPU/CPU rendering selection for WebKit
	RenderingMode RenderingMode `mapstructure:"rendering_mode" yaml:"rendering_mode"`
}

Config represents the complete configuration for dumber.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration values for dumber.

func Get

func Get() *Config

Get returns the global configuration.

type DatabaseConfig

type DatabaseConfig struct {
	Path           string        `mapstructure:"path" yaml:"path"`
	MaxConnections int           `mapstructure:"max_connections" yaml:"max_connections"`
	MaxIdleTime    time.Duration `mapstructure:"max_idle_time" yaml:"max_idle_time"`
	QueryTimeout   time.Duration `mapstructure:"query_timeout" yaml:"query_timeout"`
}

DatabaseConfig holds database-related configuration.

type DmenuConfig

type DmenuConfig struct {
	MaxHistoryItems  int    `mapstructure:"max_history_items" yaml:"max_history_items"`
	ShowVisitCount   bool   `mapstructure:"show_visit_count" yaml:"show_visit_count"`
	ShowLastVisited  bool   `mapstructure:"show_last_visited" yaml:"show_last_visited"`
	HistoryPrefix    string `mapstructure:"history_prefix" yaml:"history_prefix"`
	ShortcutPrefix   string `mapstructure:"shortcut_prefix" yaml:"shortcut_prefix"`
	URLPrefix        string `mapstructure:"url_prefix" yaml:"url_prefix"`
	DateFormat       string `mapstructure:"date_format" yaml:"date_format"`
	SortByVisitCount bool   `mapstructure:"sort_by_visit_count" yaml:"sort_by_visit_count"`
}

DmenuConfig holds dmenu/rofi integration configuration.

type HistoryConfig

type HistoryConfig struct {
	MaxEntries          int `mapstructure:"max_entries" yaml:"max_entries"`
	RetentionPeriodDays int `mapstructure:"retention_period_days" yaml:"retention_period_days"`
	CleanupIntervalDays int `mapstructure:"cleanup_interval_days" yaml:"cleanup_interval_days"`
}

HistoryConfig holds history-related configuration.

type LoggingConfig

type LoggingConfig struct {
	Level      string `mapstructure:"level" yaml:"level"`
	Format     string `mapstructure:"format" yaml:"format"`
	Filename   string `mapstructure:"filename" yaml:"filename"`
	MaxSize    int    `mapstructure:"max_size" yaml:"max_size"`
	MaxBackups int    `mapstructure:"max_backups" yaml:"max_backups"`
	MaxAge     int    `mapstructure:"max_age" yaml:"max_age"`
	Compress   bool   `mapstructure:"compress" yaml:"compress"`
}

LoggingConfig holds logging configuration.

type Manager

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

Manager handles configuration loading, watching, and reloading.

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new configuration manager.

func (*Manager) Get

func (m *Manager) Get() *Config

Get returns the current configuration (thread-safe).

func (*Manager) GetConfigFile

func (m *Manager) GetConfigFile() string

GetConfigFile returns the path to the configuration file being used.

func (*Manager) Load

func (m *Manager) Load() error

Load loads the configuration from file and environment variables.

func (*Manager) OnConfigChange

func (m *Manager) OnConfigChange(callback func(*Config))

OnConfigChange registers a callback function to be called when config changes.

func (*Manager) Watch

func (m *Manager) Watch() error

Watch starts watching the config file for changes and reloads automatically.

type RenderingMode

type RenderingMode string

RenderingMode selects GPU vs CPU rendering.

const (
	RenderingModeAuto RenderingMode = "auto"
	RenderingModeGPU  RenderingMode = "gpu"
	RenderingModeCPU  RenderingMode = "cpu"
)

type SearchShortcut

type SearchShortcut struct {
	URL         string `mapstructure:"url" yaml:"url"`
	Description string `mapstructure:"description" yaml:"description"`
}

SearchShortcut represents a search shortcut configuration.

type XDGDirs

type XDGDirs struct {
	ConfigHome string
	DataHome   string
	StateHome  string
}

XDGDirs holds the XDG Base Directory paths for the application.

func GetXDGDirs

func GetXDGDirs() (*XDGDirs, error)

GetXDGDirs returns the XDG Base Directory paths for dumber. It follows the XDG Base Directory specification: - $XDG_CONFIG_HOME/dumber (default: ~/.config/dumber) - $XDG_DATA_HOME/dumber (default: ~/.local/share/dumber) - $XDG_STATE_HOME/dumber (default: ~/.local/state/dumber)

Jump to

Keyboard shortcuts

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