stone/config.go

140 lines
4.4 KiB
Go

package stone
import "image/color"
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.
type Config struct {
private config.Config
colors [8]color.Color
padding int
center bool
fontSize int
fontNameNormal string
fontNameBold string
fontNameItalic string
fontNameBoldItalic string
}
// Color returns the color value at the specified index.
func (public *Config) Color (index Color) (value color.Color) {
value = public.colors[index]
return
}
// Padding specifies how many cell's worth of padding should be on all sides of
// the buffer.
func (public *Config) Padding () (padding int) {
padding = public.padding
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.
func (public *Config) Center () (center bool) {
center = public.center
return
}
// FontSize specifies how big the font should be.
func (public *Config) FontSize () (fontSize int) {
fontSize = public.fontSize
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
return
}
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,
"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,
"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 },
},
}
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)
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
}