voidterm/termutil/theme_factory.go

36 lines
664 B
Go
Raw Permalink Normal View History

2024-01-14 20:15:26 +00:00
package termutil
import "image/color"
type ThemeFactory struct {
theme *Theme
colourMap map[Colour]color.Color
}
func NewThemeFactory() *ThemeFactory {
return &ThemeFactory{
theme: &Theme{
colourMap: map[Colour]color.Color{},
},
colourMap: make(map[Colour]color.Color),
}
}
func (t *ThemeFactory) Build() *Theme {
for id, col := range t.colourMap {
r, g, b, _ := col.RGBA()
t.theme.colourMap[id] = color.RGBA{
R: uint8(r / 0xff),
G: uint8(g / 0xff),
B: uint8(b / 0xff),
A: 0xff,
}
}
return t.theme
}
func (t *ThemeFactory) WithColour(key Colour, colour color.Color) *ThemeFactory {
t.colourMap[key] = colour
return t
}