summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-04-20 09:38:56 -0500
committerdelthas <delthas@dille.cc>2022-04-20 18:11:23 +0200
commit80d5d8b35b450f7183fd46beedd7316f307c2b8d (patch)
treed063526395629aceddc645ee11e80ad677099773 /config.go
parentUpdate mailing list (diff)
Add a config option for unread buffer text color
This patch adds the ability to set a config option for changing the foreground text color of unread buffers (This was refactored slightly by delthas.)
Diffstat (limited to 'config.go')
-rw-r--r--config.go36
1 files changed, 20 insertions, 16 deletions
diff --git a/config.go b/config.go
index c537623..30a1efd 100644
--- a/config.go
+++ b/config.go
@@ -14,16 +14,14 @@ import (
"git.sr.ht/~emersion/go-scfg"
)
-type Color tcell.Color
-
-func parseColor(s string, c *Color) error {
+func parseColor(s string, c *tcell.Color) error {
if strings.HasPrefix(s, "#") {
hex, err := strconv.ParseInt(s[1:], 16, 32)
if err != nil {
return err
}
- *c = Color(tcell.NewHexColor(int32(hex)))
+ *c = tcell.NewHexColor(int32(hex))
return nil
}
@@ -33,7 +31,7 @@ func parseColor(s string, c *Color) error {
}
if code == -1 {
- *c = Color(tcell.ColorDefault)
+ *c = tcell.ColorDefault
return nil
}
@@ -41,13 +39,14 @@ func parseColor(s string, c *Color) error {
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))
+ *c = tcell.PaletteColor(code)
return nil
}
type ConfigColors struct {
- Prompt Color
+ Prompt tcell.Color
+ Unread tcell.Color
}
type Config struct {
@@ -102,7 +101,8 @@ func Defaults() (cfg Config, err error) {
MemberColWidth: 16,
MemberColEnabled: true,
Colors: ConfigColors{
- Prompt: Color(tcell.ColorDefault),
+ Prompt: tcell.ColorDefault,
+ Unread: tcell.ColorDefault,
},
Debug: false,
}
@@ -268,16 +268,20 @@ func unmarshal(filename string, cfg *Config) (err error) {
}
case "colors":
for _, child := range d.Children {
+ var colorStr string
+ if err := child.ParseParams(&colorStr); err != nil {
+ return err
+ }
+
+ var color tcell.Color
+ if err = parseColor(colorStr, &color); err != nil {
+ return err
+ }
switch child.Name {
case "prompt":
- var prompt string
- if err := child.ParseParams(&prompt); err != nil {
- return err
- }
-
- if err = parseColor(prompt, &cfg.Colors.Prompt); err != nil {
- return err
- }
+ cfg.Colors.Prompt = color
+ case "unread":
+ cfg.Colors.Unread = color
default:
return fmt.Errorf("unknown directive %q", child.Name)
}