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 /ui | |
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
}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/colors.go | 98 | ||||
-rw-r--r-- | ui/ui.go | 3 |
2 files changed, 64 insertions, 37 deletions
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)) } |