summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.go8
-rw-r--r--ui/colors.go53
-rw-r--r--ui/ui.go3
-rw-r--r--window.go14
4 files changed, 59 insertions, 19 deletions
diff --git a/app.go b/app.go
index 318fd4c..8b18238 100644
--- a/app.go
+++ b/app.go
@@ -1259,7 +1259,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
if isAction || isNotice {
head = "*"
} else {
- headColor = identColor(head)
+ headColor = ui.IdentColor(head)
}
content := strings.TrimSuffix(ev.Content, "\x01")
@@ -1269,14 +1269,14 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
}
var body ui.StyledStringBuilder
if isNotice {
- color := identColor(ev.User)
+ color := ui.IdentColor(ev.User)
body.SetStyle(tcell.StyleDefault.Foreground(color))
body.WriteString(ev.User)
body.SetStyle(tcell.StyleDefault)
body.WriteString(": ")
body.WriteStyledString(ui.IRCString(content))
} else if isAction {
- color := identColor(ev.User)
+ color := ui.IdentColor(ev.User)
body.SetStyle(tcell.StyleDefault.Foreground(color))
body.WriteString(ev.User)
body.SetStyle(tcell.StyleDefault)
@@ -1416,7 +1416,7 @@ func (app *App) updatePrompt() {
Foreground(tcell.ColorRed),
)
} else {
- prompt = identString(s.Nick())
+ prompt = ui.IdentString(s.Nick())
}
app.win.SetPrompt(prompt)
}
diff --git a/ui/colors.go b/ui/colors.go
new file mode 100644
index 0000000..7f0ec3a
--- /dev/null
+++ b/ui/colors.go
@@ -0,0 +1,53 @@
+package ui
+
+import (
+ "hash/fnv"
+
+ "github.com/gdamore/tcell/v2"
+)
+
+// all XTerm extended colors with HSL saturation=1, light=0.5
+var identColors = []tcell.Color{
+ tcell.Color196, // HSL hue: 0°
+ tcell.Color202, // HSL hue: 22°
+ tcell.Color208, // HSL hue: 32°
+ tcell.Color214, // HSL hue: 41°
+ tcell.Color220, // HSL hue: 51°
+ tcell.Color226, // HSL hue: 60°
+ tcell.Color190, // HSL hue: 69°
+ tcell.Color154, // HSL hue: 79°
+ tcell.Color118, // HSL hue: 88°
+ tcell.Color82, // HSL hue: 98°
+ tcell.Color46, // HSL hue: 120°
+ tcell.Color47, // HSL hue: 142°
+ tcell.Color48, // HSL hue: 152°
+ tcell.Color49, // HSL hue: 161°
+ tcell.Color50, // HSL hue: 171°
+ tcell.Color51, // HSL hue: 180°
+ tcell.Color45, // HSL hue: 189°
+ tcell.Color39, // HSL hue: 199°
+ tcell.Color33, // HSL hue: 208°
+ tcell.Color27, // HSL hue: 218°
+ tcell.Color21, // HSL hue: 240°
+ tcell.Color57, // HSL hue: 262°
+ tcell.Color93, // HSL hue: 272°
+ tcell.Color129, // HSL hue: 281°
+ tcell.Color165, // HSL hue: 291°
+ tcell.Color201, // HSL hue: 300°
+ tcell.Color200, // HSL hue: 309°
+ tcell.Color199, // HSL hue: 319°
+ tcell.Color198, // HSL hue: 328°
+ tcell.Color197, // HSL hue: 338°
+}
+
+func IdentColor(ident string) tcell.Color {
+ h := fnv.New32()
+ _, _ = h.Write([]byte(ident))
+ return identColors[int(h.Sum32()%uint32(len(identColors)))]
+}
+
+func IdentString(ident string) StyledString {
+ color := IdentColor(ident)
+ style := tcell.StyleDefault.Foreground(color)
+ return Styled(ident, style)
+}
diff --git a/ui/ui.go b/ui/ui.go
index 0a380a7..3627939 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -552,7 +552,8 @@ func (ui *UI) drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height
if m.Away {
name = Styled(nameText, tcell.StyleDefault.Foreground(tcell.ColorGray).Reverse(reverse))
} else {
- name = Styled(nameText, tcell.StyleDefault.Reverse(reverse))
+ color := IdentColor(m.Name.Name)
+ name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
}
printString(screen, &x, y, name)
diff --git a/window.go b/window.go
index 6135deb..66e0a31 100644
--- a/window.go
+++ b/window.go
@@ -1,12 +1,10 @@
package senpai
import (
- "hash/fnv"
"strings"
"time"
"git.sr.ht/~taiite/senpai/ui"
- "github.com/gdamore/tcell/v2"
)
const welcomeMessage = "senpai dev build. See senpai(1) for a list of keybindings and commands."
@@ -86,15 +84,3 @@ func (app *App) setBufferNumbers() {
showBufferNumbers := len(command) != 0 && strings.HasPrefix("buffer", command)
app.win.ShowBufferNumbers(showBufferNumbers)
}
-
-func identColor(ident string) tcell.Color {
- h := fnv.New32()
- _, _ = h.Write([]byte(ident))
- return tcell.Color((h.Sum32()%15)+1) + tcell.ColorValid
-}
-
-func identString(ident string) ui.StyledString {
- color := identColor(ident)
- style := tcell.StyleDefault.Foreground(color)
- return ui.Styled(ident, style)
-}