Add individual name colors

Fixes #79
This commit is contained in:
erroneousboat 2018-08-11 13:27:19 +02:00
parent 16a5a53692
commit ee8fc613ee

View File

@ -11,6 +11,19 @@ import (
"github.com/erroneousboat/slack-term/config"
)
var (
COLORS = []string{
"fg-black",
"fg-red",
"fg-green",
"fg-yellow",
"fg-blue",
"fg-magenta",
"fg-cyan",
"fg-white",
}
)
type Message struct {
Time time.Time
Name string
@ -23,6 +36,21 @@ type Message struct {
FormatTime string
}
func (m Message) colorizeName(styleName string) string {
if strings.Contains(styleName, "colorize") {
var sum int
for _, c := range m.Name {
sum = sum + int(c)
}
i := sum % len(COLORS)
return strings.Replace(m.StyleName, "colorize", COLORS[i], -1)
}
return styleName
}
// Chat is the definition of a Chat component
type Chat struct {
List *termui.List
@ -66,7 +94,10 @@ func (c *Chat) Buffer() termui.Buffer {
// Name
cells = append(cells, termui.DefaultTxBuilder.Build(
fmt.Sprintf("[<%s>](%s) ", msg.Name, msg.StyleName),
fmt.Sprintf("[<%s>](%s) ",
msg.Name,
msg.colorizeName(msg.StyleName),
),
termui.ColorDefault, termui.ColorDefault)...,
)
}