mirror of https://github.com/liamg/aminal.git
tidy up config
This commit is contained in:
parent
c6dbfc59c7
commit
5889d744f9
|
@ -1,13 +1,12 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitlab.com/liamg/raft/terminal"
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DebugMode bool `yaml:"debug"`
|
DebugMode bool `yaml:"debug"`
|
||||||
ColourScheme terminal.ColourScheme
|
ColourScheme ColourScheme
|
||||||
Rendering RenderingConfig `yaml:"rendering"`
|
Rendering RenderingConfig `yaml:"rendering"`
|
||||||
Slomo bool `yaml:"slomo"`
|
Slomo bool `yaml:"slomo"`
|
||||||
}
|
}
|
||||||
|
@ -18,7 +17,7 @@ type RenderingConfig struct {
|
||||||
|
|
||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
DebugMode: false,
|
DebugMode: false,
|
||||||
ColourScheme: terminal.DefaultColourScheme,
|
ColourScheme: DefaultColourScheme,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(data []byte) (*Config, error) {
|
func Parse(data []byte) (*Config, error) {
|
||||||
|
@ -26,3 +25,81 @@ func Parse(data []byte) (*Config, error) {
|
||||||
err := yaml.Unmarshal(data, &c)
|
err := yaml.Unmarshal(data, &c)
|
||||||
return &c, err
|
return &c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ColourScheme struct {
|
||||||
|
Cursor [3]float32
|
||||||
|
DefaultFg [3]float32
|
||||||
|
BlackFg [3]float32
|
||||||
|
RedFg [3]float32
|
||||||
|
GreenFg [3]float32
|
||||||
|
YellowFg [3]float32
|
||||||
|
BlueFg [3]float32
|
||||||
|
MagentaFg [3]float32
|
||||||
|
CyanFg [3]float32
|
||||||
|
LightGreyFg [3]float32
|
||||||
|
DarkGreyFg [3]float32
|
||||||
|
LightRedFg [3]float32
|
||||||
|
LightGreenFg [3]float32
|
||||||
|
LightYellowFg [3]float32
|
||||||
|
LightBlueFg [3]float32
|
||||||
|
LightMagentaFg [3]float32
|
||||||
|
LightCyanFg [3]float32
|
||||||
|
WhiteFg [3]float32
|
||||||
|
DefaultBg [3]float32
|
||||||
|
BlackBg [3]float32
|
||||||
|
RedBg [3]float32
|
||||||
|
GreenBg [3]float32
|
||||||
|
YellowBg [3]float32
|
||||||
|
BlueBg [3]float32
|
||||||
|
MagentaBg [3]float32
|
||||||
|
CyanBg [3]float32
|
||||||
|
LightGreyBg [3]float32
|
||||||
|
DarkGreyBg [3]float32
|
||||||
|
LightRedBg [3]float32
|
||||||
|
LightGreenBg [3]float32
|
||||||
|
LightYellowBg [3]float32
|
||||||
|
LightBlueBg [3]float32
|
||||||
|
LightMagentaBg [3]float32
|
||||||
|
LightCyanBg [3]float32
|
||||||
|
WhiteBg [3]float32
|
||||||
|
}
|
||||||
|
|
||||||
|
var DefaultColourScheme = ColourScheme{
|
||||||
|
Cursor: [3]float32{0.8, 0.8, 0.8},
|
||||||
|
//fg
|
||||||
|
DefaultFg: [3]float32{1, 1, 1},
|
||||||
|
BlackFg: [3]float32{0, 0, 0},
|
||||||
|
RedFg: [3]float32{1, 0, 0},
|
||||||
|
GreenFg: [3]float32{0, 1, 0},
|
||||||
|
YellowFg: [3]float32{1, 1, 0},
|
||||||
|
BlueFg: [3]float32{0, 0, 1},
|
||||||
|
MagentaFg: [3]float32{1, 0, 1},
|
||||||
|
CyanFg: [3]float32{0, 1, 1},
|
||||||
|
LightGreyFg: [3]float32{0.7, 0.7, 0.7},
|
||||||
|
DarkGreyFg: [3]float32{0.3, 0.3, 0.3},
|
||||||
|
LightRedFg: [3]float32{1, 0.5, 0.5},
|
||||||
|
LightGreenFg: [3]float32{0.5, 1, 0.5},
|
||||||
|
LightYellowFg: [3]float32{1, 1, 0.5},
|
||||||
|
LightBlueFg: [3]float32{0.5, 0.5, 1},
|
||||||
|
LightMagentaFg: [3]float32{1, 0.5, 1},
|
||||||
|
LightCyanFg: [3]float32{0.5, 1, 1},
|
||||||
|
WhiteFg: [3]float32{1, 1, 1},
|
||||||
|
// bg
|
||||||
|
DefaultBg: [3]float32{0.1, 0.1, 0.1},
|
||||||
|
BlackBg: [3]float32{0, 0, 0},
|
||||||
|
RedBg: [3]float32{1, 0, 0},
|
||||||
|
GreenBg: [3]float32{0, 1, 0},
|
||||||
|
YellowBg: [3]float32{1, 1, 0},
|
||||||
|
BlueBg: [3]float32{0, 0, 1},
|
||||||
|
MagentaBg: [3]float32{1, 0, 1},
|
||||||
|
CyanBg: [3]float32{0, 1, 1},
|
||||||
|
LightGreyBg: [3]float32{0.7, 0.7, 0.7},
|
||||||
|
DarkGreyBg: [3]float32{0.3, 0.3, 0.3},
|
||||||
|
LightRedBg: [3]float32{1, 0.5, 0.5},
|
||||||
|
LightGreenBg: [3]float32{0.5, 1, 0.5},
|
||||||
|
LightYellowBg: [3]float32{1, 1, 0.5},
|
||||||
|
LightBlueBg: [3]float32{0.5, 0.5, 1},
|
||||||
|
LightMagentaBg: [3]float32{1, 0.5, 1},
|
||||||
|
LightCyanBg: [3]float32{0.5, 1, 1},
|
||||||
|
WhiteBg: [3]float32{1, 1, 1},
|
||||||
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -88,7 +88,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infof("Creating terminal...")
|
logger.Infof("Creating terminal...")
|
||||||
terminal := terminal.New(pty, logger, conf.ColourScheme)
|
terminal := terminal.New(pty, logger, conf)
|
||||||
|
|
||||||
g := gui.New(conf, terminal, logger)
|
g := gui.New(conf, terminal, logger)
|
||||||
if err := g.Render(); err != nil {
|
if err := g.Render(); err != nil {
|
||||||
|
|
|
@ -19,8 +19,8 @@ type CellAttributes struct {
|
||||||
func (terminal *Terminal) NewCell() Cell {
|
func (terminal *Terminal) NewCell() Cell {
|
||||||
return Cell{
|
return Cell{
|
||||||
attr: CellAttributes{
|
attr: CellAttributes{
|
||||||
FgColour: terminal.colourScheme.DefaultFg,
|
FgColour: terminal.config.ColourScheme.DefaultFg,
|
||||||
BgColour: terminal.colourScheme.DefaultBg,
|
BgColour: terminal.config.ColourScheme.DefaultBg,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
package terminal
|
|
||||||
|
|
||||||
type ColourScheme struct {
|
|
||||||
Cursor [3]float32
|
|
||||||
DefaultFg [3]float32
|
|
||||||
BlackFg [3]float32
|
|
||||||
RedFg [3]float32
|
|
||||||
GreenFg [3]float32
|
|
||||||
YellowFg [3]float32
|
|
||||||
BlueFg [3]float32
|
|
||||||
MagentaFg [3]float32
|
|
||||||
CyanFg [3]float32
|
|
||||||
LightGreyFg [3]float32
|
|
||||||
DarkGreyFg [3]float32
|
|
||||||
LightRedFg [3]float32
|
|
||||||
LightGreenFg [3]float32
|
|
||||||
LightYellowFg [3]float32
|
|
||||||
LightBlueFg [3]float32
|
|
||||||
LightMagentaFg [3]float32
|
|
||||||
LightCyanFg [3]float32
|
|
||||||
WhiteFg [3]float32
|
|
||||||
DefaultBg [3]float32
|
|
||||||
BlackBg [3]float32
|
|
||||||
RedBg [3]float32
|
|
||||||
GreenBg [3]float32
|
|
||||||
YellowBg [3]float32
|
|
||||||
BlueBg [3]float32
|
|
||||||
MagentaBg [3]float32
|
|
||||||
CyanBg [3]float32
|
|
||||||
LightGreyBg [3]float32
|
|
||||||
DarkGreyBg [3]float32
|
|
||||||
LightRedBg [3]float32
|
|
||||||
LightGreenBg [3]float32
|
|
||||||
LightYellowBg [3]float32
|
|
||||||
LightBlueBg [3]float32
|
|
||||||
LightMagentaBg [3]float32
|
|
||||||
LightCyanBg [3]float32
|
|
||||||
WhiteBg [3]float32
|
|
||||||
}
|
|
||||||
|
|
||||||
var DefaultColourScheme = ColourScheme{
|
|
||||||
Cursor: [3]float32{0.8, 0.8, 0.8},
|
|
||||||
//fg
|
|
||||||
DefaultFg: [3]float32{1, 1, 1},
|
|
||||||
BlackFg: [3]float32{0, 0, 0},
|
|
||||||
RedFg: [3]float32{1, 0, 0},
|
|
||||||
GreenFg: [3]float32{0, 1, 0},
|
|
||||||
YellowFg: [3]float32{1, 1, 0},
|
|
||||||
BlueFg: [3]float32{0, 0, 1},
|
|
||||||
MagentaFg: [3]float32{1, 0, 1},
|
|
||||||
CyanFg: [3]float32{0, 1, 1},
|
|
||||||
LightGreyFg: [3]float32{0.7, 0.7, 0.7},
|
|
||||||
DarkGreyFg: [3]float32{0.3, 0.3, 0.3},
|
|
||||||
LightRedFg: [3]float32{1, 0.5, 0.5},
|
|
||||||
LightGreenFg: [3]float32{0.5, 1, 0.5},
|
|
||||||
LightYellowFg: [3]float32{1, 1, 0.5},
|
|
||||||
LightBlueFg: [3]float32{0.5, 0.5, 1},
|
|
||||||
LightMagentaFg: [3]float32{1, 0.5, 1},
|
|
||||||
LightCyanFg: [3]float32{0.5, 1, 1},
|
|
||||||
WhiteFg: [3]float32{1, 1, 1},
|
|
||||||
// bg
|
|
||||||
DefaultBg: [3]float32{0.1, 0.1, 0.1},
|
|
||||||
BlackBg: [3]float32{0, 0, 0},
|
|
||||||
RedBg: [3]float32{1, 0, 0},
|
|
||||||
GreenBg: [3]float32{0, 1, 0},
|
|
||||||
YellowBg: [3]float32{1, 1, 0},
|
|
||||||
BlueBg: [3]float32{0, 0, 1},
|
|
||||||
MagentaBg: [3]float32{1, 0, 1},
|
|
||||||
CyanBg: [3]float32{0, 1, 1},
|
|
||||||
LightGreyBg: [3]float32{0.7, 0.7, 0.7},
|
|
||||||
DarkGreyBg: [3]float32{0.3, 0.3, 0.3},
|
|
||||||
LightRedBg: [3]float32{1, 0.5, 0.5},
|
|
||||||
LightGreenBg: [3]float32{0.5, 1, 0.5},
|
|
||||||
LightYellowBg: [3]float32{1, 1, 0.5},
|
|
||||||
LightBlueBg: [3]float32{0.5, 0.5, 1},
|
|
||||||
LightMagentaBg: [3]float32{1, 0.5, 1},
|
|
||||||
LightCyanBg: [3]float32{0.5, 1, 1},
|
|
||||||
WhiteBg: [3]float32{1, 1, 1},
|
|
||||||
}
|
|
|
@ -14,8 +14,8 @@ func sgrSequenceHandler(params []string, intermediate string, terminal *Terminal
|
||||||
case "00", "0", "":
|
case "00", "0", "":
|
||||||
attr := terminal.buffer.CursorAttr()
|
attr := terminal.buffer.CursorAttr()
|
||||||
*attr = buffer.CellAttributes{
|
*attr = buffer.CellAttributes{
|
||||||
FgColour: terminal.colourScheme.DefaultFg,
|
FgColour: terminal.config.ColourScheme.DefaultFg,
|
||||||
BgColour: terminal.colourScheme.DefaultBg,
|
BgColour: terminal.config.ColourScheme.DefaultBg,
|
||||||
}
|
}
|
||||||
case "1", "01":
|
case "1", "01":
|
||||||
terminal.buffer.CursorAttr().Bold = true
|
terminal.buffer.CursorAttr().Bold = true
|
||||||
|
@ -42,73 +42,73 @@ func sgrSequenceHandler(params []string, intermediate string, terminal *Terminal
|
||||||
case "28":
|
case "28":
|
||||||
terminal.buffer.CursorAttr().Hidden = false
|
terminal.buffer.CursorAttr().Hidden = false
|
||||||
case "39":
|
case "39":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.DefaultFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.DefaultFg
|
||||||
case "30":
|
case "30":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.BlackFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.BlackFg
|
||||||
case "31":
|
case "31":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.RedFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.RedFg
|
||||||
case "32":
|
case "32":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.GreenFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.GreenFg
|
||||||
case "33":
|
case "33":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.YellowFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.YellowFg
|
||||||
case "34":
|
case "34":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.BlueFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.BlueFg
|
||||||
case "35":
|
case "35":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.MagentaFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.MagentaFg
|
||||||
case "36":
|
case "36":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.CyanFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.CyanFg
|
||||||
case "37":
|
case "37":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.WhiteFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.WhiteFg
|
||||||
case "90":
|
case "90":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.DarkGreyFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.DarkGreyFg
|
||||||
case "91":
|
case "91":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightRedFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightRedFg
|
||||||
case "92":
|
case "92":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightGreenFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightGreenFg
|
||||||
case "93":
|
case "93":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightYellowFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightYellowFg
|
||||||
case "94":
|
case "94":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightBlueFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightBlueFg
|
||||||
case "95":
|
case "95":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightMagentaFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightMagentaFg
|
||||||
case "96":
|
case "96":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.LightCyanFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightCyanFg
|
||||||
case "97":
|
case "97":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.colourScheme.WhiteFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.WhiteFg
|
||||||
case "49":
|
case "49":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.DefaultBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.DefaultBg
|
||||||
case "40":
|
case "40":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.BlackBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.BlackBg
|
||||||
case "41":
|
case "41":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.RedBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.RedBg
|
||||||
case "42":
|
case "42":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.GreenBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.GreenBg
|
||||||
case "43":
|
case "43":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.YellowBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.YellowBg
|
||||||
case "44":
|
case "44":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.BlueBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.BlueBg
|
||||||
case "45":
|
case "45":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.MagentaBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.MagentaBg
|
||||||
case "46":
|
case "46":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.CyanBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.CyanBg
|
||||||
case "47":
|
case "47":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.WhiteBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.WhiteBg
|
||||||
case "100":
|
case "100":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.DarkGreyBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.DarkGreyBg
|
||||||
case "101":
|
case "101":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightRedBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightRedBg
|
||||||
case "102":
|
case "102":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightGreenBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightGreenBg
|
||||||
case "103":
|
case "103":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightYellowBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightYellowBg
|
||||||
case "104":
|
case "104":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightBlueBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightBlueBg
|
||||||
case "105":
|
case "105":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightMagentaBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightMagentaBg
|
||||||
case "106":
|
case "106":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.LightCyanBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightCyanBg
|
||||||
case "107":
|
case "107":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.colourScheme.WhiteBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.WhiteBg
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown SGR control sequence: (ESC[%s%sm)", param, intermediate)
|
return fmt.Errorf("Unknown SGR control sequence: (ESC[%s%sm)", param, intermediate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ func New(pty *os.File, logger *zap.SugaredLogger, config config.Config) *Termina
|
||||||
|
|
||||||
return &Terminal{
|
return &Terminal{
|
||||||
buffer: buffer.NewBuffer(0, 0, buffer.CellAttributes{
|
buffer: buffer.NewBuffer(0, 0, buffer.CellAttributes{
|
||||||
FgColour: colourScheme.DefaultFg,
|
FgColour: config.ColourScheme.DefaultFg,
|
||||||
BgColour: colourScheme.DefaultBg,
|
BgColour: config.ColourScheme.DefaultBg,
|
||||||
}),
|
}),
|
||||||
pty: pty,
|
pty: pty,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
Loading…
Reference in New Issue