commit f23dd32
delthas
·
2022-08-15 13:57:06 +0000 UTC
parent 1ac38e6
Revert to using base colors by default, making extended configurable
In a previous commit, the color scheme for displaying nicks was changed
to use more colors (30 rather than 14), using extended colors from the
256 colors set.
The issue with this is that most terminal emulators customize the colors
of the first 16 colors to make them more readable (eg, a terminal
emulator with a light theme will make colors darker, and one with a dark
theme will make colors lighter). So the 14 colors used before were
usually not the default color codes from the original xterm/X11 spec,
but specific colors chosen by the terminal emulator to be particularly
readable.
In a way, changing the behavior to use colors from the 256 colors set,
which is usually not overriden, made them much less readable.
Which is why we need a configuration option for this.
I conversatively chose to make the default color scheme the previous
one, with only the base 16 colors.
The 256 colors scheme can be enable by adding to the configuration file:
colors {
nicks extended
}
5 files changed,
+88,
-41
M
app.go
+5,
-4
1@@ -144,6 +144,7 @@ func NewApp(cfg Config) (app *App, err error) {
2 },
3 Colors: ui.ConfigColors{
4 Unread: cfg.Colors.Unread,
5+ Nicks: cfg.Colors.Nicks,
6 },
7 })
8 if err != nil {
9@@ -1259,7 +1260,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
10 if isAction || isNotice {
11 head = "*"
12 } else {
13- headColor = ui.IdentColor(head)
14+ headColor = ui.IdentColor(app.cfg.Colors.Nicks, head)
15 }
16
17 content := strings.TrimSuffix(ev.Content, "\x01")
18@@ -1269,14 +1270,14 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
19 }
20 var body ui.StyledStringBuilder
21 if isNotice {
22- color := ui.IdentColor(ev.User)
23+ color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
24 body.SetStyle(tcell.StyleDefault.Foreground(color))
25 body.WriteString(ev.User)
26 body.SetStyle(tcell.StyleDefault)
27 body.WriteString(": ")
28 body.WriteStyledString(ui.IRCString(content))
29 } else if isAction {
30- color := ui.IdentColor(ev.User)
31+ color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
32 body.SetStyle(tcell.StyleDefault.Foreground(color))
33 body.WriteString(ev.User)
34 body.SetStyle(tcell.StyleDefault)
35@@ -1416,7 +1417,7 @@ func (app *App) updatePrompt() {
36 Foreground(tcell.ColorRed),
37 )
38 } else {
39- prompt = ui.IdentString(s.Nick())
40+ prompt = ui.IdentString(app.cfg.Colors.Nicks, s.Nick())
41 }
42 app.win.SetPrompt(prompt)
43 }
+17,
-0
1@@ -9,6 +9,8 @@ import (
2 "strconv"
3 "strings"
4
5+ "git.sr.ht/~taiite/senpai/ui"
6+
7 "github.com/gdamore/tcell/v2"
8
9 "git.sr.ht/~emersion/go-scfg"
10@@ -47,6 +49,7 @@ func parseColor(s string, c *tcell.Color) error {
11 type ConfigColors struct {
12 Prompt tcell.Color
13 Unread tcell.Color
14+ Nicks ui.ColorScheme
15 }
16
17 type Config struct {
18@@ -107,6 +110,7 @@ func Defaults() (cfg Config, err error) {
19 Colors: ConfigColors{
20 Prompt: tcell.ColorDefault,
21 Unread: tcell.ColorDefault,
22+ Nicks: ui.ColorSchemeBase,
23 },
24 Debug: false,
25 }
26@@ -301,6 +305,19 @@ func unmarshal(filename string, cfg *Config) (err error) {
27 return err
28 }
29
30+ switch child.Name {
31+ case "nicks":
32+ switch colorStr {
33+ case "base":
34+ cfg.Colors.Nicks = ui.ColorSchemeBase
35+ case "extended":
36+ cfg.Colors.Nicks = ui.ColorSchemeExtended
37+ default:
38+ return fmt.Errorf("unknown nick color scheme %q", colorStr)
39+ }
40+ continue
41+ }
42+
43 var color tcell.Color
44 if err = parseColor(colorStr, &color); err != nil {
45 return err
+2,
-0
1@@ -165,6 +165,8 @@ colors {
2 : color for ">"-prompt that appears in command mode
3 | unread
4 : foreground color for unread buffer names in buffer lists
5+| nicks
6+: color scheme for user nicks, either "base" (the default, 16 colors) or "extended" (256 colors)
7
8 *debug*
9 Dump all sent and received data to the home buffer, useful for debugging.
+62,
-36
1@@ -6,48 +6,74 @@ import (
2 "github.com/gdamore/tcell/v2"
3 )
4
5-// all XTerm extended colors with HSL saturation=1, light=0.5
6-var identColors = []tcell.Color{
7- tcell.Color196, // HSL hue: 0°
8- tcell.Color202, // HSL hue: 22°
9- tcell.Color208, // HSL hue: 32°
10- tcell.Color214, // HSL hue: 41°
11- tcell.Color220, // HSL hue: 51°
12- tcell.Color226, // HSL hue: 60°
13- tcell.Color190, // HSL hue: 69°
14- tcell.Color154, // HSL hue: 79°
15- tcell.Color118, // HSL hue: 88°
16- tcell.Color82, // HSL hue: 98°
17- tcell.Color46, // HSL hue: 120°
18- tcell.Color47, // HSL hue: 142°
19- tcell.Color48, // HSL hue: 152°
20- tcell.Color49, // HSL hue: 161°
21- tcell.Color50, // HSL hue: 171°
22- tcell.Color51, // HSL hue: 180°
23- tcell.Color45, // HSL hue: 189°
24- tcell.Color39, // HSL hue: 199°
25- tcell.Color33, // HSL hue: 208°
26- tcell.Color27, // HSL hue: 218°
27- tcell.Color21, // HSL hue: 240°
28- tcell.Color57, // HSL hue: 262°
29- tcell.Color93, // HSL hue: 272°
30- tcell.Color129, // HSL hue: 281°
31- tcell.Color165, // HSL hue: 291°
32- tcell.Color201, // HSL hue: 300°
33- tcell.Color200, // HSL hue: 309°
34- tcell.Color199, // HSL hue: 319°
35- tcell.Color198, // HSL hue: 328°
36- tcell.Color197, // HSL hue: 338°
37+type ColorScheme int
38+
39+const (
40+ ColorSchemeBase ColorScheme = iota
41+ ColorSchemeExtended
42+)
43+
44+var colors = map[ColorScheme][]tcell.Color{
45+ // base 16 colors, excluding grayscale colors.
46+ ColorSchemeBase: {
47+ tcell.ColorMaroon,
48+ tcell.ColorGreen,
49+ tcell.ColorOlive,
50+ tcell.ColorNavy,
51+ tcell.ColorPurple,
52+ tcell.ColorTeal,
53+ tcell.ColorSilver,
54+ tcell.ColorRed,
55+ tcell.ColorLime,
56+ tcell.ColorYellow,
57+ tcell.ColorBlue,
58+ tcell.ColorFuchsia,
59+ tcell.ColorAqua,
60+ },
61+ // all XTerm extended colors with HSL saturation=1, light=0.5
62+ ColorSchemeExtended: {
63+ tcell.Color196, // HSL hue: 0°
64+ tcell.Color202, // HSL hue: 22°
65+ tcell.Color208, // HSL hue: 32°
66+ tcell.Color214, // HSL hue: 41°
67+ tcell.Color220, // HSL hue: 51°
68+ tcell.Color226, // HSL hue: 60°
69+ tcell.Color190, // HSL hue: 69°
70+ tcell.Color154, // HSL hue: 79°
71+ tcell.Color118, // HSL hue: 88°
72+ tcell.Color82, // HSL hue: 98°
73+ tcell.Color46, // HSL hue: 120°
74+ tcell.Color47, // HSL hue: 142°
75+ tcell.Color48, // HSL hue: 152°
76+ tcell.Color49, // HSL hue: 161°
77+ tcell.Color50, // HSL hue: 171°
78+ tcell.Color51, // HSL hue: 180°
79+ tcell.Color45, // HSL hue: 189°
80+ tcell.Color39, // HSL hue: 199°
81+ tcell.Color33, // HSL hue: 208°
82+ tcell.Color27, // HSL hue: 218°
83+ tcell.Color21, // HSL hue: 240°
84+ tcell.Color57, // HSL hue: 262°
85+ tcell.Color93, // HSL hue: 272°
86+ tcell.Color129, // HSL hue: 281°
87+ tcell.Color165, // HSL hue: 291°
88+ tcell.Color201, // HSL hue: 300°
89+ tcell.Color200, // HSL hue: 309°
90+ tcell.Color199, // HSL hue: 319°
91+ tcell.Color198, // HSL hue: 328°
92+ tcell.Color197, // HSL hue: 338°
93+ },
94 }
95
96-func IdentColor(ident string) tcell.Color {
97+func IdentColor(scheme ColorScheme, ident string) tcell.Color {
98 h := fnv.New32()
99 _, _ = h.Write([]byte(ident))
100- return identColors[int(h.Sum32()%uint32(len(identColors)))]
101+ c := colors[scheme]
102+ return c[int(h.Sum32()%uint32(len(c)))]
103 }
104
105-func IdentString(ident string) StyledString {
106- color := IdentColor(ident)
107+func IdentString(scheme ColorScheme, ident string) StyledString {
108+ color := IdentColor(scheme, ident)
109 style := tcell.StyleDefault.Foreground(color)
110 return Styled(ident, style)
111 }
M
ui/ui.go
+2,
-1
1@@ -25,6 +25,7 @@ type Config struct {
2
3 type ConfigColors struct {
4 Unread tcell.Color
5+ Nicks ColorScheme
6 }
7
8 type UI struct {
9@@ -552,7 +553,7 @@ func (ui *UI) drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height
10 if m.Away {
11 name = Styled(nameText, tcell.StyleDefault.Foreground(tcell.ColorGray).Reverse(reverse))
12 } else {
13- color := IdentColor(m.Name.Name)
14+ color := IdentColor(ui.config.Colors.Nicks, m.Name.Name)
15 name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
16 }
17