diff options
author | Alexey Yerin <yyp@disroot.org> | 2021-05-28 13:30:54 +0300 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-28 17:52:13 +0200 |
commit | 70d519af99ea82a9552189980ccad6f8c29d2d94 (patch) | |
tree | 7c229dd7c517de9ba4a64b576be981b303c60134 /config.go | |
parent | Also make dashes gray for command responses (diff) |
Add colors.prompt option to set prompt color
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -4,10 +4,48 @@ import ( "errors" "fmt" "io/ioutil" + "strings" + "strconv" + + "github.com/gdamore/tcell/v2" "gopkg.in/yaml.v2" ) +type Color tcell.Color + +func (c *Color) UnmarshalText(data []byte) error { + s := string(data) + + if strings.HasPrefix(s, "#") { + hex, err := strconv.ParseInt(s[1:], 16, 32) + if err != nil { + return err + } + + *c = Color(tcell.NewHexColor(int32(hex))) + return nil + } + + code, err := strconv.Atoi(s) + if err != nil { + return err + } + + if code == -1 { + *c = Color(tcell.ColorDefault) + return nil + } + + if code < 0 || code > 255 { + return fmt.Errorf("color code must be between 0-255. If you meant to use true colors, use #aabbcc notation") + } + + *c = Color(tcell.PaletteColor(code)) + + return nil +} + type Config struct { Addr string Nick string @@ -24,6 +62,10 @@ type Config struct { NickColWidth int `yaml:"nick-column-width"` ChanColWidth int `yaml:"chan-column-width"` + Colors struct { + Prompt Color + } + Debug bool } |