This allows users to decide how their own nick, and how others' nicks,
should be colored, by setting an appropriate color in the config. If
these colors are set, they will be used instead of the colors generated
from the color scheme. This is nice for users who prefer not to use the
hash-based colors, for example to avoid confusing color collisions.
Signed-off-by: Vlad-Stefan Harbuz <vlad@vladh.net>
---
app.go | 12 +++++++-----
config.go | 6 ++++++
doc/senpai.5.scd | 4 ++++
ui/colors.go | 14 ++++++++++----
ui/ui.go | 10 ++++++----
5 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/app.go b/app.go
index 509a518..0fed149 100644
--- a/app.go
+++ b/app.go
@@ -253,12 +253,14 @@ func (app *App) eventLoop() {
app.updatePrompt()
app.setBufferNumbers()
var currentMembers []irc.Member
+ selfNick := ""
netID, buffer := app.win.CurrentBuffer()
s := app.sessions[netID]
if s != nil && buffer != "" {
currentMembers = s.Names(buffer)
+ selfNick = s.Nick()
}
- app.win.Draw(currentMembers)
+ app.win.Draw(currentMembers, selfNick)
if netID != "" && buffer != "" {
app.win.SetTitle(fmt.Sprintf("%s — senpai", buffer))
} else {
@@ -1390,19 +1392,19 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
if isAction || isNotice {
head = "*"
} else {
- headColor = ui.IdentColor(app.cfg.Colors.Nicks, head)
+ headColor = ui.IdentColor(app.cfg.Colors, head, head == s.Nick())
}
var body ui.StyledStringBuilder
if isNotice {
- color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
+ color := ui.IdentColor(app.cfg.Colors, ev.User, ev.User == s.Nick())
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(app.cfg.Colors.Nicks, ev.User)
+ color := ui.IdentColor(app.cfg.Colors, ev.User, ev.User == s.Nick())
body.SetStyle(tcell.StyleDefault.Foreground(color))
body.WriteString(ev.User)
body.SetStyle(tcell.StyleDefault)
@@ -1544,7 +1546,7 @@ func (app *App) updatePrompt() {
Foreground(tcell.ColorRed),
)
} else {
- prompt = ui.IdentString(app.cfg.Colors.Nicks, s.Nick())
+ prompt = ui.IdentString(app.cfg.Colors, s.Nick(), true)
}
app.win.SetPrompt(prompt)
}
diff --git a/config.go b/config.go
index d9bfe33..9f0f044 100644
--- a/config.go
+++ b/config.go
@@ -111,6 +111,8 @@ func Defaults() Config {
Status: tcell.ColorGray,
Prompt: tcell.ColorDefault,
Unread: tcell.ColorDefault,
+ Self: tcell.ColorDefault,
+ Others: tcell.ColorDefault,
Nicks: ui.ColorSchemeBase,
},
Debug: false,
@@ -361,6 +363,10 @@ func unmarshal(filename string, cfg *Config) (err error) {
cfg.Colors.Unread = color
case "status":
cfg.Colors.Status = color
+ case "self":
+ cfg.Colors.Self = color
+ case "others":
+ cfg.Colors.Others = color
default:
return fmt.Errorf("unknown colors directive %q", child.Name)
}
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index 198157c..e233b9b 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -172,6 +172,10 @@ colors {
:< *Description*
| prompt
: color for ">"-prompt that appears in command mode
+| self
+: foreground color for one's own nick. overrides color from "nicks" if set.
+| others
+: foreground color for others' nicks. overrides color from "nicks" if set.
| unread
: foreground color for unread buffer names in buffer lists
| status
diff --git a/ui/colors.go b/ui/colors.go
index f9b4f3f..754ae36 100644
--- a/ui/colors.go
+++ b/ui/colors.go
@@ -65,15 +65,21 @@ var colors = map[ColorScheme][]tcell.Color{
},
}
-func IdentColor(scheme ColorScheme, ident string) tcell.Color {
+func IdentColor(configColors ConfigColors, ident string, isSelf bool) tcell.Color {
+ if isSelf && configColors.Self != tcell.ColorDefault {
+ return configColors.Self
+ }
+ if configColors.Others != tcell.ColorDefault {
+ return configColors.Others
+ }
h := fnv.New32()
_, _ = h.Write([]byte(ident))
- c := colors[scheme]
+ c := colors[configColors.Nicks]
return c[int(h.Sum32()%uint32(len(c)))]
}
-func IdentString(scheme ColorScheme, ident string) StyledString {
- color := IdentColor(scheme, ident)
+func IdentString(configColors ConfigColors, ident string, isSelf bool) StyledString {
+ color := IdentColor(configColors, ident, isSelf)
style := tcell.StyleDefault.Foreground(color)
return Styled(ident, style)
}
diff --git a/ui/ui.go b/ui/ui.go
index fa72fb0..cbadf3e 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -27,6 +27,8 @@ type ConfigColors struct {
Status tcell.Color
Prompt tcell.Color
Unread tcell.Color
+ Self tcell.Color
+ Others tcell.Color
Nicks ColorScheme
}
@@ -467,7 +469,7 @@ func (ui *UI) Notify(title string, body string) {
ui.screen.Notify(title, body)
}
-func (ui *UI) Draw(members []irc.Member) {
+func (ui *UI) Draw(members []irc.Member, selfNick string) {
w, h := ui.screen.Size()
if ui.channelWidth == 0 {
@@ -483,7 +485,7 @@ func (ui *UI) Draw(members []irc.Member) {
ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.channelWidth, h, &ui.channelOffset)
}
if ui.memberWidth != 0 {
- ui.drawVerticalMemberList(ui.screen, w-ui.memberWidth, 0, ui.memberWidth, h, members, &ui.memberOffset)
+ ui.drawVerticalMemberList(ui.screen, w-ui.memberWidth, 0, ui.memberWidth, h, members, &ui.memberOffset, selfNick)
}
if ui.channelWidth == 0 {
ui.drawStatusBar(ui.channelWidth, h-3, w-ui.memberWidth)
@@ -544,7 +546,7 @@ func (ui *UI) drawStatusBar(x0, y, width int) {
printString(ui.screen, &x, y, s.StyledString())
}
-func (ui *UI) drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member, offset *int) {
+func (ui *UI) drawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member, offset *int, selfNick string) {
if y0+len(members)-*offset < height {
*offset = y0 + len(members) - height
if *offset < 0 {
@@ -609,7 +611,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(ui.config.Colors.Nicks, m.Name.Name)
+ color := IdentColor(ui.config.Colors, m.Name.Name, m.Name.Name == selfNick)
name = Styled(nameText, tcell.StyleDefault.Foreground(color).Reverse(reverse))
}
--
2.42.0