package config import ( ui "github.com/gizak/termui/v3" "github.com/sqshq/sampler/console" ) type ComponentType rune const ( TypeRunChart ComponentType = 0 TypeBarChart ComponentType = 1 TypeSparkLine ComponentType = 2 TypeTextBox ComponentType = 3 TypeAsciiBox ComponentType = 4 TypeGauge ComponentType = 5 ) type ComponentConfig struct { Title string `yaml:"title"` RefreshRateMs *int `yaml:"refresh-rate-ms,omitempty"` Position [][]int `yaml:"position,flow"` Triggers []TriggerConfig `yaml:"triggers,omitempty"` Type ComponentType `yaml:",omitempty"` } func (c *ComponentConfig) GetLocation() Location { return Location{X: c.Position[0][0], Y: c.Position[0][1]} } func (c *ComponentConfig) GetSize() Size { return Size{X: c.Position[1][0], Y: c.Position[1][1]} } type TriggerConfig struct { Title string `yaml:"title"` Condition string `yaml:"condition"` Actions *ActionsConfig `yaml:"actions,omitempty"` } type ActionsConfig struct { TerminalBell *bool `yaml:"terminal-bell,omitempty"` Sound *bool `yaml:"sound,omitempty"` Visual *bool `yaml:"visual,omitempty"` Script *string `yaml:"script,omitempty"` } type GaugeConfig struct { ComponentConfig `yaml:",inline"` Scale *int `yaml:"scale,omitempty"` Color *ui.Color `yaml:"color,omitempty"` Values map[string]string `yaml:"values"` Items []Item `yaml:",omitempty"` } type BarChartConfig struct { ComponentConfig `yaml:",inline"` Scale *int `yaml:"scale,omitempty"` Items []Item `yaml:"items"` } type AsciiBoxConfig struct { ComponentConfig `yaml:",inline"` Item `yaml:",inline"` Font *console.AsciiFont `yaml:"font,omitempty"` } type RunChartConfig struct { ComponentConfig `yaml:",inline"` Legend *LegendConfig `yaml:"legend,omitempty"` Scale *int `yaml:"scale,omitempty"` Items []Item `yaml:"items"` } type LegendConfig struct { Enabled bool `yaml:"enabled"` Details bool `yaml:"details"` } type Item struct { Label *string `yaml:"label,omitempty"` Script string `yaml:"value"` Color *ui.Color `yaml:"color,omitempty"` } type Location struct { X int Y int } type Size struct { X int Y int } type ComponentSettings struct { Type ComponentType Title string Size Size Location Location } func getPosition(location Location, size Size) [][]int { return [][]int{ {location.X, location.Y}, {size.X, size.Y}, } }