summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.go9
-rw-r--r--config.go17
-rw-r--r--doc/senpai.5.scd2
-rw-r--r--ui/colors.go98
-rw-r--r--ui/ui.go3
5 files changed, 88 insertions, 41 deletions
diff --git a/app.go b/app.go
index 8b18238..35cc3b8 100644
--- a/app.go
+++ b/app.go
@@ -144,6 +144,7 @@ func NewApp(cfg Config) (app *App, err error) {
},
Colors: ui.ConfigColors{
Unread: cfg.Colors.Unread,
+ Nicks: cfg.Colors.Nicks,
},
})
if err != nil {
@@ -1259,7 +1260,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
if isAction || isNotice {
head = "*"
} else {
- headColor = ui.IdentColor(head)
+ headColor = ui.IdentColor(app.cfg.Colors.Nicks, head)
}
content := strings.TrimSuffix(ev.Content, "\x01")
@@ -1269,14 +1270,14 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
}
var body ui.StyledStringBuilder
if isNotice {
- color := ui.IdentColor(ev.User)
+ color := ui.IdentColor(app.cfg.Colors.Nicks, 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 := ui.IdentColor(ev.User)
+ color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
body.SetStyle(tcell.StyleDefault.Foreground(color))
body.WriteString(ev.User)
body.SetStyle(tcell.StyleDefault)
@@ -1416,7 +1417,7 @@ func (app *App) updatePrompt() {
Foreground(tcell.ColorRed),
)
} else {
- prompt = ui.IdentString(s.Nick())
+ prompt = ui.IdentString(app.cfg.Colors.Nicks, s.Nick())
}
app.win.SetPrompt(prompt)
}
diff --git a/config.go b/config.go
index 2450e75..9ee6d09 100644
--- a/config.go
+++ b/config.go
@@ -9,6 +9,8 @@ import (
"strconv"
"strings"
+ "git.sr.ht/~taiite/senpai/ui"
+
"github.com/gdamore/tcell/v2"
"git.sr.ht/~emersion/go-scfg"
@@ -47,6 +49,7 @@ func parseColor(s string, c *tcell.Color) error {
type ConfigColors struct {
Prompt tcell.Color
Unread tcell.Color
+ Nicks ui.ColorScheme
}
type Config struct {
@@ -107,6 +110,7 @@ func Defaults() (cfg Config, err error) {
Colors: ConfigColors{
Prompt: tcell.ColorDefault,
Unread: tcell.ColorDefault,
+ Nicks: ui.ColorSchemeBase,
},
Debug: false,
}
@@ -301,6 +305,19 @@ func unmarshal(filename string, cfg *Config) (err error) {
return err
}
+ switch child.Name {
+ case "nicks":
+ switch colorStr {
+ case "base":
+ cfg.Colors.Nicks = ui.ColorSchemeBase
+ case "extended":
+ cfg.Colors.Nicks = ui.ColorSchemeExtended
+ default:
+ return fmt.Errorf("unknown nick color scheme %q", colorStr)
+ }
+ continue
+ }
+
var color tcell.Color
if err = parseColor(colorStr, &color); err != nil {
return err
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index d8f04f6..114d60b 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -165,6 +165,8 @@ colors {
: color for ">"-prompt that appears in command mode
| unread
: foreground color for unread buffer names in buffer lists
+| nicks
+: color scheme for user nicks, either "base" (the default, 16 colors) or "extended" (256 colors)
*debug*
Dump all sent and received data to the home buffer, useful for debugging.
diff --git a/ui/colors.go b/ui/colors.go
index 7f0ec3a..f9b4f3f 100644
--- a/ui/colors.go
+++ b/ui/colors.go
@@ -6,48 +6,74 @@ import (
"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°
+type ColorScheme int
+
+const (
+ ColorSchemeBase ColorScheme = iota
+ ColorSchemeExtended
+)
+
+var colors = map[ColorScheme][]tcell.Color{
+ // base 16 colors, excluding grayscale colors.
+ ColorSchemeBase: {
+ tcell.ColorMaroon,
+ tcell.ColorGreen,
+ tcell.ColorOlive,
+ tcell.ColorNavy,
+ tcell.ColorPurple,
+ tcell.ColorTeal,
+ tcell.ColorSilver,
+ tcell.ColorRed,
+ tcell.ColorLime,
+ tcell.ColorYellow,
+ tcell.ColorBlue,
+ tcell.ColorFuchsia,
+ tcell.ColorAqua,
+ },
+ // all XTerm extended colors with HSL saturation=1, light=0.5
+ ColorSchemeExtended: {
+ 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 {
+func IdentColor(scheme ColorScheme, ident string) tcell.Color {
h := fnv.New32()
_, _ = h.Write([]byte(ident))
- return identColors[int(h.Sum32()%uint32(len(identColors)))]
+ c := colors[scheme]
+ return c[int(h.Sum32()%uint32(len(c)))]
}
-func IdentString(ident string) StyledString {
- color := IdentColor(ident)
+func IdentString(scheme ColorScheme, ident string) StyledString {
+ color := IdentColor(scheme, ident)
style := tcell.StyleDefault.Foreground(color)
return Styled(ident, style)
}
diff --git a/ui/ui.go b/ui/ui.go
index 3627939..45c3472 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -25,6 +25,7 @@ type Config struct {
type ConfigColors struct {
Unread tcell.Color
+ Nicks ColorScheme
}
type UI struct {
@@ -552,7 +553,7 @@ 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 {
- color := IdentColor(m.Name.Name)
+ color := IdentColor(ui.config.Colors.Nicks, m.Name.Name)
name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
}