diff options
| author | Hubert Hirtz <hubert.hirtz@laposte.net> | 2020-06-03 22:31:57 +0200 |
|---|---|---|
| committer | Hubert Hirtz <hubert.hirtz@laposte.net> | 2020-06-03 22:31:57 +0200 |
| commit | 7824063063ee2d637e2990ac718dbf82fb0de8c1 (patch) | |
| tree | 14acf0119b0233415380f23a84013c6918f86ae0 | |
| parent | typing=done (diff) | |
Nick colors
Diffstat (limited to '')
| -rw-r--r-- | cmd/irc/main.go | 31 | ||||
| -rw-r--r-- | ui/ui.go | 3 |
2 files changed, 29 insertions, 5 deletions
diff --git a/cmd/irc/main.go b/cmd/irc/main.go index 06db1cb..5c2d436 100644 --- a/cmd/irc/main.go +++ b/cmd/irc/main.go @@ -7,6 +7,7 @@ import ( "git.sr.ht/~taiite/senpai/irc" "git.sr.ht/~taiite/senpai/ui" "github.com/gdamore/tcell" + "hash/fnv" "log" "os/user" "strings" @@ -167,8 +168,10 @@ func handleInput(s *irc.Session, buffer, content string) { } func formatIRCMessage(nick, content string) (line string) { + c := color(nick) + if content == "" { - line = fmt.Sprintf("\x02%s\x00:", nick) + line = fmt.Sprintf("%s%s\x00:", string(c[:]), nick) return } @@ -176,15 +179,35 @@ func formatIRCMessage(nick, content string) (line string) { content = strings.TrimSuffix(content[1:], "\x01") if strings.HasPrefix(content, "ACTION") { - line = fmt.Sprintf("*\x02%s\x00%s", nick, content[6:]) + line = fmt.Sprintf("%s%s\x00%s", string(c[:]), nick, content[6:]) } else { - line = fmt.Sprintf("\x1dCTCP request from\x1d \x02%s\x00: %s", nick, content) + line = fmt.Sprintf("\x1dCTCP request from\x1d %s%s\x00: %s", string(c[:]), nick, content) } return } - line = fmt.Sprintf("\x02%s\x00 %s", nick, content) + line = fmt.Sprintf("%s%s\x00: %s", string(c[:]), nick, content) + + return +} + +func color(nick string) (c [3]rune) { + h := fnv.New32() + _, _ = h.Write([]byte(nick)) + + sum := h.Sum32() % 14 + + if 1 <= sum { + sum++ + } + if 8 <= sum { + sum++ + } + + c[0] = '\x03' + c[1] = rune(sum/10) + '0' + c[2] = rune(sum%10) + '0' return } @@ -364,7 +364,8 @@ func (ui *UI) drawBuffer() { bold = false italic = false underline = false - st = st.Normal() + colorState = 0 + st = tcell.StyleDefault continue } if r == 0x02 { |
