summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorAlexey Yerin <yyp@disroot.org>2021-05-28 13:30:54 +0300
committerHubert Hirtz <hubert@hirtz.pm>2021-05-28 17:52:13 +0200
commit70d519af99ea82a9552189980ccad6f8c29d2d94 (patch)
tree7c229dd7c517de9ba4a64b576be981b303c60134 /config.go
parentAlso make dashes gray for command responses (diff)
Add colors.prompt option to set prompt color
Diffstat (limited to 'config.go')
-rw-r--r--config.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/config.go b/config.go
index 1d8d79a..b744ba8 100644
--- a/config.go
+++ b/config.go
@@ -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
}