2022-10-31 13:51:28 -06:00
|
|
|
package stone
|
|
|
|
|
|
|
|
import "image/color"
|
|
|
|
|
2022-11-26 18:28:32 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/stone/config"
|
|
|
|
|
|
|
|
// Config stores global, read-only configuration parameters that apply to all
|
|
|
|
// applications. Backends only should honor parameters that they can support.
|
2022-10-31 13:51:28 -06:00
|
|
|
type Config struct {
|
2022-11-26 18:28:32 -07:00
|
|
|
private config.Config
|
2022-11-15 09:16:29 -07:00
|
|
|
colors [8]color.Color
|
2022-10-31 13:51:28 -06:00
|
|
|
padding int
|
2022-11-16 09:31:35 -07:00
|
|
|
center bool
|
2022-10-31 13:51:28 -06:00
|
|
|
fontSize int
|
|
|
|
fontName string
|
|
|
|
}
|
|
|
|
|
2022-11-08 23:01:13 -07:00
|
|
|
// Color returns the color value at the specified index.
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) Color (index Color) (value color.Color) {
|
|
|
|
value = public.colors[index]
|
2022-10-31 13:51:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-08 23:01:13 -07:00
|
|
|
// Padding specifies how many cell's worth of padding should be on all sides of
|
|
|
|
// the buffer.
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) Padding () (padding int) {
|
|
|
|
padding = public.padding
|
2022-10-31 13:51:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-16 09:31:35 -07:00
|
|
|
// Center returns whether the buffer should be displayed in the center of the
|
|
|
|
// window like in kitty, or aligned to one corner like in gnome-terminal.
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) Center () (center bool) {
|
|
|
|
center = public.center
|
2022-11-16 09:31:35 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-08 23:01:13 -07:00
|
|
|
// FontSize specifies how big the font should be.
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) FontSize () (fontSize int) {
|
|
|
|
fontSize = public.fontSize
|
2022-10-31 13:51:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-08 23:01:13 -07:00
|
|
|
// FontName specifies the name of the font to use.
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) FontName () (fontName string) {
|
|
|
|
fontName = public.fontName
|
2022-10-31 13:51:28 -06:00
|
|
|
return
|
|
|
|
}
|
2022-11-15 11:43:21 -07:00
|
|
|
|
2022-11-26 18:28:32 -07:00
|
|
|
func (public *Config) load () {
|
|
|
|
public.private = config.Config {
|
|
|
|
LegalParameters: map[string] config.Type {
|
|
|
|
"fontNormal": config.TypeString,
|
|
|
|
"fontSize": config.TypeInteger,
|
|
|
|
"padding": config.TypeInteger,
|
|
|
|
"center": config.TypeBoolean,
|
|
|
|
"colorBackground": config.TypeColor,
|
|
|
|
"colorForeground": config.TypeColor,
|
|
|
|
"colorDim": config.TypeColor,
|
|
|
|
"colorRed": config.TypeColor,
|
|
|
|
"colorYellow": config.TypeColor,
|
|
|
|
"colorGreen": config.TypeColor,
|
|
|
|
"colorBlue": config.TypeColor,
|
|
|
|
"colorPurple": config.TypeColor,
|
|
|
|
},
|
|
|
|
|
|
|
|
Parameters: map[string] any {
|
|
|
|
"fontNormal": "",
|
|
|
|
"fontSize": 11,
|
|
|
|
"padding": 2,
|
|
|
|
"center": false,
|
|
|
|
"colorBackground":
|
|
|
|
color.RGBA { R: 0, G: 0, B: 0, A: 0 },
|
|
|
|
"colorForeground":
|
|
|
|
color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF },
|
|
|
|
"colorDim":
|
|
|
|
color.RGBA { R: 0x80, G: 0x80, B: 0x80, A: 0xFF },
|
|
|
|
"colorRed":
|
|
|
|
color.RGBA { R: 0xFF, G: 0x00, B: 0x00, A: 0xFF },
|
|
|
|
"colorYellow":
|
|
|
|
color.RGBA { R: 0xFF, G: 0xFF, B: 0x00, A: 0xFF },
|
|
|
|
"colorGreen":
|
|
|
|
color.RGBA { R: 0x00, G: 0xFF, B: 0x00, A: 0xFF },
|
|
|
|
"colorBlue":
|
|
|
|
color.RGBA { R: 0x00, G: 0x80, B: 0xFF, A: 0xFF },
|
|
|
|
"colorPurple":
|
|
|
|
color.RGBA { R: 0x80, G: 0x40, B: 0xFF, A: 0xFF },
|
|
|
|
},
|
2022-11-15 11:43:21 -07:00
|
|
|
}
|
|
|
|
|
2022-11-26 18:28:32 -07:00
|
|
|
public.private.Load("stone")
|
|
|
|
params := public.private.Parameters
|
2022-11-15 11:43:21 -07:00
|
|
|
|
2022-11-26 18:28:32 -07:00
|
|
|
public.fontName = params["fontNormal"].(string)
|
|
|
|
public.fontSize = params["fontSize"].(int)
|
|
|
|
public.padding = params["padding"].(int)
|
|
|
|
public.center = params["center"].(bool)
|
2022-11-15 11:43:21 -07:00
|
|
|
|
2022-11-26 18:28:32 -07:00
|
|
|
public.colors[ColorBackground] = params["colorBackground"].(color.RGBA)
|
|
|
|
public.colors[ColorForeground] = params["colorForeground"].(color.RGBA)
|
|
|
|
public.colors[ColorDim] = params["colorDim" ].(color.RGBA)
|
|
|
|
public.colors[ColorRed] = params["colorRed" ].(color.RGBA)
|
|
|
|
public.colors[ColorYellow] = params["colorYellow" ].(color.RGBA)
|
|
|
|
public.colors[ColorGreen] = params["colorGreen" ].(color.RGBA)
|
|
|
|
public.colors[ColorBlue] = params["colorBlue" ].(color.RGBA)
|
|
|
|
public.colors[ColorPurple] = params["colorPurple" ].(color.RGBA)
|
|
|
|
|
|
|
|
return
|
2022-11-15 11:43:21 -07:00
|
|
|
}
|