2019-02-26 04:36:23 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2019-03-14 03:01:44 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
2019-03-08 04:04:46 +00:00
|
|
|
"github.com/sqshq/sampler/console"
|
2019-04-26 05:11:40 +00:00
|
|
|
"image"
|
2019-02-26 04:36:23 +00:00
|
|
|
)
|
|
|
|
|
2019-03-08 04:04:46 +00:00
|
|
|
type ComponentType rune
|
|
|
|
|
|
|
|
const (
|
2019-03-17 23:55:24 +00:00
|
|
|
TypeRunChart ComponentType = 0
|
|
|
|
TypeBarChart ComponentType = 1
|
|
|
|
TypeSparkLine ComponentType = 2
|
|
|
|
TypeTextBox ComponentType = 3
|
|
|
|
TypeAsciiBox ComponentType = 4
|
|
|
|
TypeGauge ComponentType = 5
|
2019-03-08 04:04:46 +00:00
|
|
|
)
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
type ComponentConfig struct {
|
2019-04-07 15:17:28 +00:00
|
|
|
Title string `yaml:"title"`
|
|
|
|
Position [][]int `yaml:"position,flow"`
|
2019-04-07 17:56:20 +00:00
|
|
|
RateMs *int `yaml:"rate-ms,omitempty"`
|
2019-04-07 15:17:28 +00:00
|
|
|
Triggers []TriggerConfig `yaml:"triggers,omitempty"`
|
|
|
|
Type ComponentType `yaml:",omitempty"`
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 02:41:23 +00:00
|
|
|
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]}
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:11:40 +00:00
|
|
|
func (c *ComponentConfig) GetRectangle() image.Rectangle {
|
2019-04-30 03:29:31 +00:00
|
|
|
if c.Position == nil || len(c.Position) == 0 {
|
2019-04-26 05:11:40 +00:00
|
|
|
return image.ZR
|
|
|
|
}
|
2019-07-27 04:15:35 +00:00
|
|
|
return image.Rect(
|
|
|
|
c.Position[0][0],
|
|
|
|
c.Position[0][1],
|
|
|
|
c.Position[0][0]+c.Position[1][0],
|
|
|
|
c.Position[0][1]+c.Position[1][1])
|
2019-04-26 05:11:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 19:35:29 +00:00
|
|
|
type TriggerConfig struct {
|
2019-03-03 23:35:32 +00:00
|
|
|
Title string `yaml:"title"`
|
|
|
|
Condition string `yaml:"condition"`
|
|
|
|
Actions *ActionsConfig `yaml:"actions,omitempty"`
|
2019-03-03 19:35:29 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 23:35:32 +00:00
|
|
|
type ActionsConfig struct {
|
|
|
|
TerminalBell *bool `yaml:"terminal-bell,omitempty"`
|
|
|
|
Sound *bool `yaml:"sound,omitempty"`
|
|
|
|
Visual *bool `yaml:"visual,omitempty"`
|
|
|
|
Script *string `yaml:"script,omitempty"`
|
2019-03-03 19:35:29 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
type GaugeConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
2019-04-06 02:11:52 +00:00
|
|
|
Scale *int `yaml:"scale,omitempty"`
|
|
|
|
Color *ui.Color `yaml:"color,omitempty"`
|
2019-06-22 02:56:23 +00:00
|
|
|
PercentOnly *bool `yaml:"percent-only,omitempty"`
|
2019-04-06 02:11:52 +00:00
|
|
|
Cur Item `yaml:"cur"`
|
|
|
|
Max Item `yaml:"max"`
|
|
|
|
Min Item `yaml:"min"`
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:46:39 +00:00
|
|
|
type SparkLineConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
2019-04-01 04:35:55 +00:00
|
|
|
Scale *int `yaml:"scale,omitempty"`
|
|
|
|
Item Item `yaml:",inline"`
|
|
|
|
Gradient *[]ui.Color `yaml:",omitempty"`
|
2019-03-24 22:46:39 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
type BarChartConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
2019-03-08 04:04:46 +00:00
|
|
|
Scale *int `yaml:"scale,omitempty"`
|
|
|
|
Items []Item `yaml:"items"`
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AsciiBoxConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
2019-03-08 04:04:46 +00:00
|
|
|
Item `yaml:",inline"`
|
2019-04-10 02:30:21 +00:00
|
|
|
Border *bool `yaml:"border,omitempty"`
|
2019-03-08 04:04:46 +00:00
|
|
|
Font *console.AsciiFont `yaml:"font,omitempty"`
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 02:30:21 +00:00
|
|
|
type TextBoxConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
|
|
|
Item `yaml:",inline"`
|
|
|
|
Border *bool `yaml:"border,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
type RunChartConfig struct {
|
|
|
|
ComponentConfig `yaml:",inline"`
|
2019-03-05 03:25:17 +00:00
|
|
|
Legend *LegendConfig `yaml:"legend,omitempty"`
|
|
|
|
Scale *int `yaml:"scale,omitempty"`
|
2019-03-08 04:04:46 +00:00
|
|
|
Items []Item `yaml:"items"`
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LegendConfig struct {
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
Details bool `yaml:"details"`
|
|
|
|
}
|
|
|
|
|
2019-03-08 04:04:46 +00:00
|
|
|
type Item struct {
|
2019-06-23 04:08:24 +00:00
|
|
|
Label *string `yaml:"label,omitempty"`
|
|
|
|
Color *ui.Color `yaml:"color,omitempty"`
|
|
|
|
Pty *bool `yaml:"pty,omitempty"`
|
|
|
|
InitScript *string `yaml:"init,omitempty"`
|
|
|
|
MultiStepInitScript *[]string `yaml:"multistep-init,omitempty"`
|
|
|
|
SampleScript *string `yaml:"sample"`
|
|
|
|
TransformScript *string `yaml:"transform,omitempty"`
|
2019-03-08 04:04:46 +00:00
|
|
|
}
|
2019-02-26 04:36:23 +00:00
|
|
|
|
2019-03-18 02:41:23 +00:00
|
|
|
type Location struct {
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
}
|
|
|
|
|
|
|
|
type Size struct {
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
}
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
type ComponentSettings struct {
|
|
|
|
Type ComponentType
|
|
|
|
Title string
|
|
|
|
Size Size
|
2019-03-18 02:41:23 +00:00
|
|
|
Location Location
|
|
|
|
}
|
|
|
|
|
|
|
|
func getPosition(location Location, size Size) [][]int {
|
|
|
|
return [][]int{
|
|
|
|
{location.X, location.Y},
|
|
|
|
{size.X, size.Y},
|
|
|
|
}
|
2019-02-26 04:36:23 +00:00
|
|
|
}
|