~delthas/senpai-dev

config: add 'color nicks custom' v1 PROPOSED

Lauri Tirkkonen: 1
 config: add 'color nicks custom'

 3 files changed, 22 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~delthas/senpai-dev/patches/48315/mbox | git am -3
Learn more about email & git

[PATCH] config: add 'color nicks custom' Export this patch

this allows users to specify their own custom color scheme with as many
colors as they like.
---
 config.go        | 14 ++++++++++++++
 doc/senpai.5.scd |  2 ++
 ui/colors.go     |  6 ++++++
 3 files changed, 22 insertions(+)

diff --git a/config.go b/config.go
index e7cf553..87d1da3 100644
--- a/config.go
+++ b/config.go
@@ -384,6 +384,20 @@ func unmarshal(filename string, cfg *Config) (err error) {
						cfg.Colors.Nicks.Type = ui.ColorSchemeBase
					case "extended":
						cfg.Colors.Nicks.Type = ui.ColorSchemeExtended
					case "custom":
						var colors []tcell.Color
						cfg.Colors.Nicks.Type = ui.ColorSchemeCustom
						if len(child.Params) < 2 {
							return fmt.Errorf("not enough arguments to 'colors nicks custom'")
						}
						for _, param := range child.Params[1:] {
							var color tcell.Color
							if err = parseColor(param, &color); err != nil {
								return fmt.Errorf("cannot parse 'colors nicks custom': %w", err)
							}
							colors = append(colors, color)
						}
						ui.SetCustomColors(colors)
					case "fixed":
						cfg.Colors.Nicks.Type = ui.ColorSchemeFixed
						if len(child.Params) >= 2 {
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index 38705a1..e135c59 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -192,6 +192,8 @@ colors {
:  show nicks with 16 different colors (default)
|  nicks extended
:  show nicks with 256 different colors
|  nicks custom <color> [color...]
:  show nicks with custom colors randomly chosen from the given list
|  nicks fixed [<others> [self]]
:  show nicks with a fixed color, optionally specifying the colors for other nicks, and self

diff --git a/ui/colors.go b/ui/colors.go
index 9c14a56..8c9fe79 100644
--- a/ui/colors.go
+++ b/ui/colors.go
@@ -18,6 +18,7 @@ const (
	ColorSchemeBase ColorSchemeType = iota
	ColorSchemeExtended
	ColorSchemeFixed
	ColorSchemeCustom
)

var colors = map[ColorSchemeType][]tcell.Color{
@@ -70,6 +71,7 @@ var colors = map[ColorSchemeType][]tcell.Color{
		tcell.Color198, // HSL hue: 328°
		tcell.Color197, // HSL hue: 338°
	},
	ColorSchemeCustom: {},
}

func IdentColor(scheme ColorScheme, ident string, self bool) tcell.Color {
@@ -91,3 +93,7 @@ func IdentString(scheme ColorScheme, ident string, self bool) StyledString {
	style := tcell.StyleDefault.Foreground(color)
	return Styled(ident, style)
}

func SetCustomColors(cols []tcell.Color) {
	colors[ColorSchemeCustom] = cols
}
-- 
2.43.0

-- 
Lauri Tirkkonen | lotheac @ IRCnet