diff options
author | Tobias Wölfel <tobias.woelfel@mailbox.org> | 2022-04-07 12:20:31 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-04-07 12:51:09 +0200 |
commit | e810ae12d7b86dfe51aed6f5b88e90c1fe1814ac (patch) | |
tree | 1a45d97e580c12b568de27f071e0787495d50287 /config/style.go | |
parent | 4dbdf586887614a334b2af47d6a83f3a5d0ea516 (diff) | |
download | aerc-e810ae12d7b86dfe51aed6f5b88e90c1fe1814ac.tar.gz |
stylesets: allow specifying color by number
Make it possible to specify the color in the style sets by number in
addition to the color name. This allows using colors defined by the
terminal.
Signed-off-by: Tobias Wölfel <tobias.woelfel@mailbox.org>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config/style.go')
-rw-r--r-- | config/style.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/config/style.go b/config/style.go index c3e85032..fc6f7db7 100644 --- a/config/style.go +++ b/config/style.go @@ -6,6 +6,7 @@ import ( "os" "path" "regexp" + "strconv" "strings" "github.com/gdamore/tcell/v2" @@ -139,12 +140,23 @@ func boolSwitch(val string, cur_val bool) (bool, error) { } } +func extractColor(val string) tcell.Color { + // Check if the string can be interpreted as a number, indicating a + // reference to the color number. Otherwise retrieve the number based + // on the name. + if i, err := strconv.ParseUint(val, 10, 8); err == nil { + return tcell.PaletteColor(int(i)) + } else { + return tcell.GetColor(val) + } +} + func (s *Style) Set(attr, val string) error { switch attr { case "fg": - s.Fg = tcell.GetColor(val) + s.Fg = extractColor(val) case "bg": - s.Bg = tcell.GetColor(val) + s.Bg = extractColor(val) case "bold": if state, err := boolSwitch(val, s.Bold); err != nil { return err |