commit 0621fe2

delthas  ·  2022-08-10 11:58:18 +0000 UTC
parent 0ba374b
Color nicks in the member list the same as in the timeline

Also, change the color scheme to use more colors. Now 30 instead of 15,
and with the consistent color codes offered by the extended XTerm 256
color scheme.

Fixes: https://todo.sr.ht/~taiite/senpai/90
4 files changed,  +59, -19
M app.go
M app.go
+4, -4
 1@@ -1259,7 +1259,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
 2 	if isAction || isNotice {
 3 		head = "*"
 4 	} else {
 5-		headColor = identColor(head)
 6+		headColor = ui.IdentColor(head)
 7 	}
 8 
 9 	content := strings.TrimSuffix(ev.Content, "\x01")
10@@ -1269,14 +1269,14 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
11 	}
12 	var body ui.StyledStringBuilder
13 	if isNotice {
14-		color := identColor(ev.User)
15+		color := ui.IdentColor(ev.User)
16 		body.SetStyle(tcell.StyleDefault.Foreground(color))
17 		body.WriteString(ev.User)
18 		body.SetStyle(tcell.StyleDefault)
19 		body.WriteString(": ")
20 		body.WriteStyledString(ui.IRCString(content))
21 	} else if isAction {
22-		color := identColor(ev.User)
23+		color := ui.IdentColor(ev.User)
24 		body.SetStyle(tcell.StyleDefault.Foreground(color))
25 		body.WriteString(ev.User)
26 		body.SetStyle(tcell.StyleDefault)
27@@ -1416,7 +1416,7 @@ func (app *App) updatePrompt() {
28 				Foreground(tcell.ColorRed),
29 		)
30 	} else {
31-		prompt = identString(s.Nick())
32+		prompt = ui.IdentString(s.Nick())
33 	}
34 	app.win.SetPrompt(prompt)
35 }
+53, -0
 1@@ -0,0 +1,53 @@
 2+package ui
 3+
 4+import (
 5+	"hash/fnv"
 6+
 7+	"github.com/gdamore/tcell/v2"
 8+)
 9+
10+// all XTerm extended colors with HSL saturation=1, light=0.5
11+var identColors = []tcell.Color{
12+	tcell.Color196, // HSL hue: 0°
13+	tcell.Color202, // HSL hue: 22°
14+	tcell.Color208, // HSL hue: 32°
15+	tcell.Color214, // HSL hue: 41°
16+	tcell.Color220, // HSL hue: 51°
17+	tcell.Color226, // HSL hue: 60°
18+	tcell.Color190, // HSL hue: 69°
19+	tcell.Color154, // HSL hue: 79°
20+	tcell.Color118, // HSL hue: 88°
21+	tcell.Color82,  // HSL hue: 98°
22+	tcell.Color46,  // HSL hue: 120°
23+	tcell.Color47,  // HSL hue: 142°
24+	tcell.Color48,  // HSL hue: 152°
25+	tcell.Color49,  // HSL hue: 161°
26+	tcell.Color50,  // HSL hue: 171°
27+	tcell.Color51,  // HSL hue: 180°
28+	tcell.Color45,  // HSL hue: 189°
29+	tcell.Color39,  // HSL hue: 199°
30+	tcell.Color33,  // HSL hue: 208°
31+	tcell.Color27,  // HSL hue: 218°
32+	tcell.Color21,  // HSL hue: 240°
33+	tcell.Color57,  // HSL hue: 262°
34+	tcell.Color93,  // HSL hue: 272°
35+	tcell.Color129, // HSL hue: 281°
36+	tcell.Color165, // HSL hue: 291°
37+	tcell.Color201, // HSL hue: 300°
38+	tcell.Color200, // HSL hue: 309°
39+	tcell.Color199, // HSL hue: 319°
40+	tcell.Color198, // HSL hue: 328°
41+	tcell.Color197, // HSL hue: 338°
42+}
43+
44+func IdentColor(ident string) tcell.Color {
45+	h := fnv.New32()
46+	_, _ = h.Write([]byte(ident))
47+	return identColors[int(h.Sum32()%uint32(len(identColors)))]
48+}
49+
50+func IdentString(ident string) StyledString {
51+	color := IdentColor(ident)
52+	style := tcell.StyleDefault.Foreground(color)
53+	return Styled(ident, style)
54+}
+2, -1
 1@@ -552,7 +552,8 @@ 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-			name = Styled(nameText, tcell.StyleDefault.Reverse(reverse))
 6+			color := IdentColor(m.Name.Name)
 7+			name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
 8 		}
 9 
10 		printString(screen, &x, y, name)
+0, -14
 1@@ -1,12 +1,10 @@
 2 package senpai
 3 
 4 import (
 5-	"hash/fnv"
 6 	"strings"
 7 	"time"
 8 
 9 	"git.sr.ht/~taiite/senpai/ui"
10-	"github.com/gdamore/tcell/v2"
11 )
12 
13 const welcomeMessage = "senpai dev build. See senpai(1) for a list of keybindings and commands."
14@@ -86,15 +84,3 @@ func (app *App) setBufferNumbers() {
15 	showBufferNumbers := len(command) != 0 && strings.HasPrefix("buffer", command)
16 	app.win.ShowBufferNumbers(showBufferNumbers)
17 }
18-
19-func identColor(ident string) tcell.Color {
20-	h := fnv.New32()
21-	_, _ = h.Write([]byte(ident))
22-	return tcell.Color((h.Sum32()%15)+1) + tcell.ColorValid
23-}
24-
25-func identString(ident string) ui.StyledString {
26-	color := identColor(ident)
27-	style := tcell.StyleDefault.Foreground(color)
28-	return ui.Styled(ident, style)
29-}