diff options
author | delthas <delthas@dille.cc> | 2022-08-15 15:57:06 +0200 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-08-15 15:57:06 +0200 |
commit | f23dd3273dd29a32c7c759aab0fb34a3784bd5d0 (patch) | |
tree | 55bb578a8420a1ec8422ad54f709b973cc5744c4 | |
parent | Add a project description (diff) |
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
}
-rw-r--r-- | app.go | 9 | ||||
-rw-r--r-- | config.go | 17 | ||||
-rw-r--r-- | doc/senpai.5.scd | 2 | ||||
-rw-r--r-- | ui/colors.go | 98 | ||||
-rw-r--r-- | ui/ui.go | 3 |
5 files changed, 88 insertions, 41 deletions
@@ -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) } @@ -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) } @@ -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)) } |