mirror of https://github.com/liamg/aminal.git
nice colour scheme by default
This commit is contained in:
parent
8649ab7d76
commit
8f1efd822e
|
@ -9,28 +9,39 @@ import (
|
||||||
|
|
||||||
type Colour [3]float32
|
type Colour [3]float32
|
||||||
|
|
||||||
func (c *Colour) UnmarshalText(data []byte) error {
|
func strToColourNoErr(hexStr string) Colour {
|
||||||
|
c, _ := strToColour(hexStr)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
hexStr := string(data)
|
func strToColour(hexStr string) (Colour, error) {
|
||||||
|
|
||||||
|
c := [3]float32{0, 0, 0}
|
||||||
|
|
||||||
if strings.HasPrefix(hexStr, "#") {
|
if strings.HasPrefix(hexStr, "#") {
|
||||||
hexStr = hexStr[1:]
|
hexStr = hexStr[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(hexStr) != 6 {
|
if len(hexStr) != 6 {
|
||||||
return fmt.Errorf("Invalid colour format. Should be like #ffffff")
|
return c, fmt.Errorf("Invalid colour format. Should be like #ffffff")
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := hex.DecodeString(hexStr)
|
bytes, err := hex.DecodeString(hexStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c[0] = float32(bytes[0]) / 255
|
c[0] = float32(bytes[0]) / 255
|
||||||
c[1] = float32(bytes[1]) / 255
|
c[1] = float32(bytes[1]) / 255
|
||||||
c[2] = float32(bytes[2]) / 255
|
c[2] = float32(bytes[2]) / 255
|
||||||
|
|
||||||
return nil
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Colour) UnmarshalText(data []byte) error {
|
||||||
|
var err error
|
||||||
|
*c, err = strToColour(string(data))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Colour) MarshalText() (text []byte, err error) {
|
func (c Colour) MarshalText() (text []byte, err error) {
|
||||||
|
@ -43,39 +54,23 @@ func (c Colour) MarshalText() (text []byte, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ColourScheme struct {
|
type ColourScheme struct {
|
||||||
Cursor Colour `toml:"cursor"`
|
Cursor Colour `toml:"cursor"`
|
||||||
DefaultFg Colour `toml:"default_fg"`
|
Foreground Colour `toml:"foreground"`
|
||||||
BlackFg Colour `toml:"black_fg"`
|
Background Colour `toml:"background"`
|
||||||
RedFg Colour `toml:"red_fg"`
|
Black Colour `toml:"black"`
|
||||||
GreenFg Colour `toml:"green_fg"`
|
Red Colour `toml:"red"`
|
||||||
YellowFg Colour `toml:"yellow_fg"`
|
Green Colour `toml:"green"`
|
||||||
BlueFg Colour `toml:"blue_fg"`
|
Yellow Colour `toml:"yellow"`
|
||||||
MagentaFg Colour `toml:"magenta_fg"`
|
Blue Colour `toml:"blue"`
|
||||||
CyanFg Colour `toml:"cyan_fg"`
|
Magenta Colour `toml:"magenta"`
|
||||||
LightGreyFg Colour `toml:"light_grey_fg"`
|
Cyan Colour `toml:"cyan"`
|
||||||
DarkGreyFg Colour `toml:"dark_grey_fg"`
|
LightGrey Colour `toml:"light_grey"`
|
||||||
LightRedFg Colour `toml:"light_red_fg"`
|
DarkGrey Colour `toml:"dark_grey"`
|
||||||
LightGreenFg Colour `toml:"light_green_fg"`
|
LightRed Colour `toml:"light_red"`
|
||||||
LightYellowFg Colour `toml:"light_yellow_fg"`
|
LightGreen Colour `toml:"light_green"`
|
||||||
LightBlueFg Colour `toml:"light_blue_fg"`
|
LightYellow Colour `toml:"light_yellow"`
|
||||||
LightMagentaFg Colour `toml:"light_magenta_fg"`
|
LightBlue Colour `toml:"light_blue"`
|
||||||
LightCyanFg Colour `toml:"light_cyan_fg"`
|
LightMagenta Colour `toml:"light_magenta"`
|
||||||
WhiteFg Colour `toml:"white_fg"`
|
LightCyan Colour `toml:"light_cyan"`
|
||||||
DefaultBg Colour `toml:"default_bg"`
|
White Colour `toml:"white"`
|
||||||
BlackBg Colour `toml:"black_bg"`
|
|
||||||
RedBg Colour `toml:"red_bg"`
|
|
||||||
GreenBg Colour `toml:"green_bg"`
|
|
||||||
YellowBg Colour `toml:"yellow_bg"`
|
|
||||||
BlueBg Colour `toml:"blue_bg"`
|
|
||||||
MagentaBg Colour `toml:"magenta_bg"`
|
|
||||||
CyanBg Colour `toml:"cyan_bg"`
|
|
||||||
LightGreyBg Colour `toml:"light_grey_bg"`
|
|
||||||
DarkGreyBg Colour `toml:"dark_grey_bg"`
|
|
||||||
LightRedBg Colour `toml:"light_red_bg"`
|
|
||||||
LightGreenBg Colour `toml:"light_green_bg"`
|
|
||||||
LightYellowBg Colour `toml:"light_yellow_bg"`
|
|
||||||
LightBlueBg Colour `toml:"light_blue_bg"`
|
|
||||||
LightMagentaBg Colour `toml:"light_magenta_bg"`
|
|
||||||
LightCyanBg Colour `toml:"light_cyan_bg"`
|
|
||||||
WhiteBg Colour `toml:"white_bg"`
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,42 +3,24 @@ package config
|
||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
DebugMode: false,
|
DebugMode: false,
|
||||||
ColourScheme: ColourScheme{
|
ColourScheme: ColourScheme{
|
||||||
Cursor: [3]float32{0.8, 0.8, 0.8},
|
Cursor: strToColourNoErr("#e8dfd6"),
|
||||||
//fg
|
Foreground: strToColourNoErr("#e8dfd6"),
|
||||||
DefaultFg: [3]float32{1, 1, 1},
|
Background: strToColourNoErr("#021b21"),
|
||||||
BlackFg: [3]float32{0, 0, 0},
|
Black: strToColourNoErr("#032c36"),
|
||||||
RedFg: [3]float32{1, 0, 0},
|
Red: strToColourNoErr("#c2454e"),
|
||||||
GreenFg: [3]float32{0, 1, 0},
|
Green: strToColourNoErr("#7cbf9e"),
|
||||||
YellowFg: [3]float32{1, 1, 0},
|
Yellow: strToColourNoErr("#8a7a63"),
|
||||||
BlueFg: [3]float32{0, 0, 1},
|
Blue: strToColourNoErr("#2e3340"),
|
||||||
MagentaFg: [3]float32{1, 0, 1},
|
Magenta: strToColourNoErr("#ff5879"),
|
||||||
CyanFg: [3]float32{0, 1, 1},
|
Cyan: strToColourNoErr("#44b5b1"),
|
||||||
LightGreyFg: [3]float32{0.7, 0.7, 0.7},
|
LightGrey: strToColourNoErr("#f2f1b9"),
|
||||||
DarkGreyFg: [3]float32{0.3, 0.3, 0.3},
|
DarkGrey: strToColourNoErr("#065f73"),
|
||||||
LightRedFg: [3]float32{1, 0.5, 0.5},
|
LightRed: strToColourNoErr("#ef5847"),
|
||||||
LightGreenFg: [3]float32{0.5, 1, 0.5},
|
LightGreen: strToColourNoErr("#a2db91"),
|
||||||
LightYellowFg: [3]float32{1, 1, 0.5},
|
LightYellow: strToColourNoErr("#beb090"),
|
||||||
LightBlueFg: [3]float32{0.5, 0.5, 1},
|
LightBlue: strToColourNoErr("#61778d"),
|
||||||
LightMagentaFg: [3]float32{1, 0.5, 1},
|
LightMagenta: strToColourNoErr("#ff99a1"),
|
||||||
LightCyanFg: [3]float32{0.5, 1, 1},
|
LightCyan: strToColourNoErr("#9ed9d8"),
|
||||||
WhiteFg: [3]float32{1, 1, 1},
|
White: strToColourNoErr("#f6f6c9"),
|
||||||
// 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},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,9 @@ func (gui *GUI) Render() error {
|
||||||
//glfw.SwapInterval(1)
|
//glfw.SwapInterval(1)
|
||||||
|
|
||||||
gl.ClearColor(
|
gl.ClearColor(
|
||||||
gui.config.ColourScheme.DefaultBg[0],
|
gui.config.ColourScheme.Background[0],
|
||||||
gui.config.ColourScheme.DefaultBg[1],
|
gui.config.ColourScheme.Background[1],
|
||||||
gui.config.ColourScheme.DefaultBg[2],
|
gui.config.ColourScheme.Background[2],
|
||||||
1.0,
|
1.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) {
|
||||||
gl.UseProgram(r.program)
|
gl.UseProgram(r.program)
|
||||||
|
|
||||||
// don't bother rendering rectangles that are the same colour as the background
|
// don't bother rendering rectangles that are the same colour as the background
|
||||||
if bg != r.config.ColourScheme.DefaultBg {
|
if bg != r.config.ColourScheme.Background {
|
||||||
rect.setColour(bg)
|
rect.setColour(bg)
|
||||||
gl.BindVertexArray(rect.vao)
|
gl.BindVertexArray(rect.vao)
|
||||||
gl.DrawArrays(gl.TRIANGLES, 0, 6)
|
gl.DrawArrays(gl.TRIANGLES, 0, 6)
|
||||||
|
|
|
@ -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.config.ColourScheme.DefaultFg,
|
FgColour: terminal.config.ColourScheme.Foreground,
|
||||||
BgColour: terminal.config.ColourScheme.DefaultBg,
|
BgColour: terminal.config.ColourScheme.Background,
|
||||||
}
|
}
|
||||||
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.config.ColourScheme.DefaultFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Foreground
|
||||||
case "30":
|
case "30":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.BlackFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Black
|
||||||
case "31":
|
case "31":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.RedFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Red
|
||||||
case "32":
|
case "32":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.GreenFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Green
|
||||||
case "33":
|
case "33":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.YellowFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Yellow
|
||||||
case "34":
|
case "34":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.BlueFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Blue
|
||||||
case "35":
|
case "35":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.MagentaFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Magenta
|
||||||
case "36":
|
case "36":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.CyanFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.Cyan
|
||||||
case "37":
|
case "37":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.WhiteFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.White
|
||||||
case "90":
|
case "90":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.DarkGreyFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.DarkGrey
|
||||||
case "91":
|
case "91":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightRedFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightRed
|
||||||
case "92":
|
case "92":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightGreenFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightGreen
|
||||||
case "93":
|
case "93":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightYellowFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightYellow
|
||||||
case "94":
|
case "94":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightBlueFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightBlue
|
||||||
case "95":
|
case "95":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightMagentaFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightMagenta
|
||||||
case "96":
|
case "96":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightCyanFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.LightCyan
|
||||||
case "97":
|
case "97":
|
||||||
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.WhiteFg
|
terminal.buffer.CursorAttr().FgColour = terminal.config.ColourScheme.White
|
||||||
case "49":
|
case "49":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.DefaultBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Background
|
||||||
case "40":
|
case "40":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.BlackBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Black
|
||||||
case "41":
|
case "41":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.RedBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Red
|
||||||
case "42":
|
case "42":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.GreenBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Green
|
||||||
case "43":
|
case "43":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.YellowBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Yellow
|
||||||
case "44":
|
case "44":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.BlueBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Blue
|
||||||
case "45":
|
case "45":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.MagentaBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Magenta
|
||||||
case "46":
|
case "46":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.CyanBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.Cyan
|
||||||
case "47":
|
case "47":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.WhiteBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.White
|
||||||
case "100":
|
case "100":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.DarkGreyBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.DarkGrey
|
||||||
case "101":
|
case "101":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightRedBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightRed
|
||||||
case "102":
|
case "102":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightGreenBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightGreen
|
||||||
case "103":
|
case "103":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightYellowBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightYellow
|
||||||
case "104":
|
case "104":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightBlueBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightBlue
|
||||||
case "105":
|
case "105":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightMagentaBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightMagenta
|
||||||
case "106":
|
case "106":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightCyanBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.LightCyan
|
||||||
case "107":
|
case "107":
|
||||||
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.WhiteBg
|
terminal.buffer.CursorAttr().BgColour = terminal.config.ColourScheme.White
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,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: config.ColourScheme.DefaultFg,
|
FgColour: config.ColourScheme.Foreground,
|
||||||
BgColour: config.ColourScheme.DefaultBg,
|
BgColour: config.ColourScheme.Background,
|
||||||
}),
|
}),
|
||||||
pty: pty,
|
pty: pty,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
Loading…
Reference in New Issue