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>
This commit is contained in:
parent
4dbdf58688
commit
e810ae12d7
2 changed files with 18 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -205,6 +205,10 @@ The values can be one of the following.
|
|||
*<Hex code>*
|
||||
Hexcode for a color can be used. The format must be "\#XXXXXX"
|
||||
|
||||
*<Dec number>*
|
||||
Color based on the palette index. Valid numbers are between 0
|
||||
and 255.
|
||||
|
||||
# SEE ALSO
|
||||
|
||||
*aerc*(1) *aerc-config*(5)
|
||||
|
|
Loading…
Reference in a new issue