commit 1836d50
delthas
·
2023-11-13 11:32:33 +0000 UTC
parent 797447a
Add a fixed color scheme for nicks Fixes: https://todo.sr.ht/~taiite/senpai/122
7 files changed,
+110,
-21
M
app.go
+4,
-4
1@@ -1408,19 +1408,19 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
2 if isAction || isNotice {
3 head = "*"
4 } else {
5- headColor = ui.IdentColor(app.cfg.Colors.Nicks, head)
6+ headColor = ui.IdentColor(app.cfg.Colors.Nicks, head, isFromSelf)
7 }
8
9 var body ui.StyledStringBuilder
10 if isNotice {
11- color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
12+ color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User, isFromSelf)
13 body.SetStyle(tcell.StyleDefault.Foreground(color))
14 body.WriteString(ev.User)
15 body.SetStyle(tcell.StyleDefault)
16 body.WriteString(": ")
17 body.WriteStyledString(ui.IRCString(content))
18 } else if isAction {
19- color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
20+ color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User, isFromSelf)
21 body.SetStyle(tcell.StyleDefault.Foreground(color))
22 body.WriteString(ev.User)
23 body.SetStyle(tcell.StyleDefault)
24@@ -1562,7 +1562,7 @@ func (app *App) updatePrompt() {
25 Foreground(tcell.ColorRed),
26 )
27 } else {
28- prompt = ui.IdentString(app.cfg.Colors.Nicks, s.Nick())
29+ prompt = ui.IdentString(app.cfg.Colors.Nicks, s.Nick(), true)
30 }
31 app.win.SetPrompt(prompt)
32 }
+59,
-3
1@@ -26,6 +26,46 @@ func parseColor(s string, c *tcell.Color) error {
2 *c = tcell.NewHexColor(int32(hex))
3 return nil
4 }
5+ ok := true
6+ switch s {
7+ case "black":
8+ *c = tcell.ColorBlack
9+ case "maroon":
10+ *c = tcell.ColorBrown
11+ case "green":
12+ *c = tcell.ColorGreen
13+ case "olive":
14+ *c = tcell.ColorOlive
15+ case "navy":
16+ *c = tcell.ColorNavy
17+ case "purple":
18+ *c = tcell.ColorPurple
19+ case "teal":
20+ *c = tcell.ColorTeal
21+ case "silver":
22+ *c = tcell.ColorSilver
23+ case "gray", "grey":
24+ *c = tcell.ColorGray
25+ case "red":
26+ *c = tcell.ColorRed
27+ case "lime":
28+ *c = tcell.ColorLime
29+ case "yellow":
30+ *c = tcell.ColorYellow
31+ case "blue":
32+ *c = tcell.ColorBlue
33+ case "fuschia":
34+ *c = tcell.ColorFuchsia
35+ case "aqua":
36+ *c = tcell.ColorAqua
37+ case "white":
38+ *c = tcell.ColorWhite
39+ default:
40+ ok = false
41+ }
42+ if ok {
43+ return nil
44+ }
45
46 code, err := strconv.Atoi(s)
47 if err != nil {
48@@ -111,7 +151,11 @@ func Defaults() Config {
49 Status: tcell.ColorGray,
50 Prompt: tcell.ColorDefault,
51 Unread: tcell.ColorDefault,
52- Nicks: ui.ColorSchemeBase,
53+ Nicks: ui.ColorScheme{
54+ Type: ui.ColorSchemeBase,
55+ Others: tcell.ColorDefault,
56+ Self: tcell.ColorRed,
57+ },
58 },
59 Debug: false,
60 }
61@@ -336,9 +380,21 @@ func unmarshal(filename string, cfg *Config) (err error) {
62 case "nicks":
63 switch colorStr {
64 case "base":
65- cfg.Colors.Nicks = ui.ColorSchemeBase
66+ cfg.Colors.Nicks.Type = ui.ColorSchemeBase
67 case "extended":
68- cfg.Colors.Nicks = ui.ColorSchemeExtended
69+ cfg.Colors.Nicks.Type = ui.ColorSchemeExtended
70+ case "fixed":
71+ cfg.Colors.Nicks.Type = ui.ColorSchemeFixed
72+ if len(child.Params) >= 2 {
73+ if err = parseColor(child.Params[1], &cfg.Colors.Nicks.Others); err != nil {
74+ return err
75+ }
76+ }
77+ if len(child.Params) >= 3 {
78+ if err = parseColor(child.Params[2], &cfg.Colors.Nicks.Self); err != nil {
79+ return err
80+ }
81+ }
82 default:
83 return fmt.Errorf("unknown nick color scheme %q", colorStr)
84 }
+22,
-6
1@@ -170,14 +170,30 @@ colors {
2
3 [[ *Sub-directive*
4 :< *Description*
5-| prompt
6+| prompt <color>
7 : color for ">"-prompt that appears in command mode
8-| unread
9+| unread <color>
10 : foreground color for unread buffer names in buffer lists
11-| status
12-: foreground color for status event lines (e.g. join, part, nick changes) in buffers. "disabled" hides status messages.
13-| nicks
14-: color scheme for user nicks, either "base" (the default, 16 colors) or "extended" (256 colors)
15+| status [...]
16+: foreground color for status event lines (e.g. join, part, nick changes) in buffers, see table below
17+| nicks [...]
18+: color scheme for user nicks, see table below
19+
20+[[ *status sub-directive*
21+:< *Description*
22+| status <color>
23+: show status events with the specified color
24+| status disabled
25+: hide status events
26+
27+[[ *nicks sub-directive*
28+:< *Description*
29+| nicks base
30+: show nicks with 16 different colors (default)
31+| nicks extended
32+: show nicks with 256 different colors
33+| nicks fixed [<others> [self]]
34+: show nicks with a fixed color, optionally specifying the colors for other nicks, and self
35
36 *debug*
37 Advanced.
+2,
-0
1@@ -271,6 +271,7 @@ func (s *Session) Names(target string) []Member {
2 Name: u.Name.Copy(),
3 Away: u.Away,
4 Disconnected: u.Disconnected,
5+ Self: s.nickCf == s.casemap(u.Name.Name),
6 })
7 }
8 }
9@@ -284,6 +285,7 @@ func (s *Session) Names(target string) []Member {
10 Name: &Prefix{
11 Name: s.nick,
12 },
13+ Self: true,
14 })
15 }
16 sort.Sort(members(names))
+1,
-0
1@@ -467,6 +467,7 @@ type Member struct {
2 Name *Prefix
3 Away bool
4 Disconnected bool
5+ Self bool // Added by senpai
6 }
7
8 type members []Member
+21,
-7
1@@ -6,14 +6,21 @@ import (
2 "github.com/gdamore/tcell/v2"
3 )
4
5-type ColorScheme int
6+type ColorSchemeType int
7+
8+type ColorScheme struct {
9+ Type ColorSchemeType
10+ Others tcell.Color
11+ Self tcell.Color
12+}
13
14 const (
15- ColorSchemeBase ColorScheme = iota
16+ ColorSchemeBase ColorSchemeType = iota
17 ColorSchemeExtended
18+ ColorSchemeFixed
19 )
20
21-var colors = map[ColorScheme][]tcell.Color{
22+var colors = map[ColorSchemeType][]tcell.Color{
23 // base 16 colors, excluding grayscale colors.
24 ColorSchemeBase: {
25 tcell.ColorMaroon,
26@@ -65,15 +72,22 @@ var colors = map[ColorScheme][]tcell.Color{
27 },
28 }
29
30-func IdentColor(scheme ColorScheme, ident string) tcell.Color {
31+func IdentColor(scheme ColorScheme, ident string, self bool) tcell.Color {
32 h := fnv.New32()
33 _, _ = h.Write([]byte(ident))
34- c := colors[scheme]
35+ if scheme.Type == ColorSchemeFixed {
36+ if self {
37+ return scheme.Self
38+ } else {
39+ return scheme.Others
40+ }
41+ }
42+ c := colors[scheme.Type]
43 return c[int(h.Sum32()%uint32(len(c)))]
44 }
45
46-func IdentString(scheme ColorScheme, ident string) StyledString {
47- color := IdentColor(scheme, ident)
48+func IdentString(scheme ColorScheme, ident string, self bool) StyledString {
49+ color := IdentColor(scheme, ident, self)
50 style := tcell.StyleDefault.Foreground(color)
51 return Styled(ident, style)
52 }
M
ui/ui.go
+1,
-1
1@@ -613,7 +613,7 @@ func (ui *UI) drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height
2 if m.Away {
3 name = Styled(nameText, tcell.StyleDefault.Foreground(tcell.ColorGray).Reverse(reverse))
4 } else {
5- color := IdentColor(ui.config.Colors.Nicks, m.Name.Name)
6+ color := IdentColor(ui.config.Colors.Nicks, m.Name.Name, m.Self)
7 name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
8 }
9