stone/config.go

140 lines
4.4 KiB
Go
Raw Normal View History

2022-10-31 19:51:28 +00:00
package stone
import "image/color"
2022-11-27 01:28:32 +00: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 19:51:28 +00:00
type Config struct {
2022-11-27 01:28:32 +00:00
private config.Config
2022-11-15 16:16:29 +00:00
colors [8]color.Color
2022-10-31 19:51:28 +00:00
padding int
center bool
2022-10-31 19:51:28 +00:00
fontSize int
fontNameNormal string
fontNameBold string
fontNameItalic string
fontNameBoldItalic string
2022-10-31 19:51:28 +00:00
}
2022-11-09 06:01:13 +00:00
// Color returns the color value at the specified index.
2022-11-27 01:28:32 +00:00
func (public *Config) Color (index Color) (value color.Color) {
value = public.colors[index]
2022-10-31 19:51:28 +00:00
return
}
2022-11-09 06:01:13 +00:00
// Padding specifies how many cell's worth of padding should be on all sides of
// the buffer.
2022-11-27 01:28:32 +00:00
func (public *Config) Padding () (padding int) {
padding = public.padding
2022-10-31 19:51:28 +00:00
return
}
// 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-27 01:28:32 +00:00
func (public *Config) Center () (center bool) {
center = public.center
return
}
2022-11-09 06:01:13 +00:00
// FontSize specifies how big the font should be.
2022-11-27 01:28:32 +00:00
func (public *Config) FontSize () (fontSize int) {
fontSize = public.fontSize
2022-10-31 19:51:28 +00:00
return
}
// FontNameNormal specifies the name of the font to use for normal text.
func (public *Config) FontNameNormal () (fontName string) {
fontName = public.fontNameNormal
return
}
// FontNameBold specifies the name of the font to use for bold text.
func (public *Config) FontNameBold () (fontName string) {
fontName = public.fontNameBold
return
}
// FontName specifies the name of the font to use for text.
func (public *Config) FontNameItalic () (fontName string) {
fontName = public.fontNameItalic
return
}
// FontName specifies the name of the font to use for text.
func (public *Config) FontNameBoldItalic () (fontName string) {
fontName = public.fontNameBoldItalic
2022-10-31 19:51:28 +00:00
return
}
2022-11-27 01:28:32 +00:00
func (public *Config) load () {
public.private = config.Config {
LegalParameters: map[string] config.Type {
"fontNormal": config.TypeString,
"fontBold": config.TypeString,
"fontItalic": config.TypeString,
"fontBoldItalic": config.TypeString,
2022-11-27 01:28:32 +00:00
"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": "",
"fontBold": "",
"fontItalic": "",
"fontBoldItalic": "",
"fontSize": 11,
"padding": 2,
"center": false,
2022-11-27 01:28:32 +00:00
"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-27 01:28:32 +00:00
public.private.Load("stone")
params := public.private.Parameters
public.fontNameNormal = params["fontNormal"].(string)
public.fontNameBold = params["fontBold"].(string)
public.fontNameItalic = params["fontItalic"].(string)
public.fontNameBoldItalic = params["fontBoldItalic"].(string)
public.fontSize = params["fontSize"].(int)
public.padding = params["padding"].(int)
public.center = params["center"].(bool)
2022-11-27 01:28:32 +00: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
}