parent
16a5a53692
commit
ee8fc613ee
@ -11,6 +11,19 @@ import (
|
|||||||
"github.com/erroneousboat/slack-term/config"
|
"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 {
|
type Message struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
Name string
|
Name string
|
||||||
@ -23,6 +36,21 @@ type Message struct {
|
|||||||
FormatTime string
|
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
|
// Chat is the definition of a Chat component
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
List *termui.List
|
List *termui.List
|
||||||
@ -66,7 +94,10 @@ func (c *Chat) Buffer() termui.Buffer {
|
|||||||
|
|
||||||
// Name
|
// Name
|
||||||
cells = append(cells, termui.DefaultTxBuilder.Build(
|
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)...,
|
termui.ColorDefault, termui.ColorDefault)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user