diff --git a/chat/message/theme.go b/chat/message/theme.go index d2585b7..9a10cb2 100644 --- a/chat/message/theme.go +++ b/chat/message/theme.go @@ -1,6 +1,9 @@ package message -import "fmt" +import ( + "fmt" + "time" +) const ( // Reset resets the color @@ -122,43 +125,49 @@ type Theme struct { names *Palette } -func (t Theme) ID() string { - return t.id +func (theme Theme) ID() string { + return theme.id } // Colorize name string given some index -func (t Theme) ColorName(u *User) string { - if t.names == nil { +func (theme Theme) ColorName(u *User) string { + if theme.names == nil { return u.Name() } - return t.names.Get(u.colorIdx).Format(u.Name()) + return theme.names.Get(u.colorIdx).Format(u.Name()) } // Colorize the PM string -func (t Theme) ColorPM(s string) string { - if t.pm == nil { +func (theme Theme) ColorPM(s string) string { + if theme.pm == nil { return s } - return t.pm.Format(s) + return theme.pm.Format(s) } // Colorize the Sys message -func (t Theme) ColorSys(s string) string { - if t.sys == nil { +func (theme Theme) ColorSys(s string) string { + if theme.sys == nil { return s } - return t.sys.Format(s) + return theme.sys.Format(s) } // Highlight a matched string, usually name -func (t Theme) Highlight(s string) string { - if t.highlight == nil { +func (theme Theme) Highlight(s string) string { + if theme.highlight == nil { return s } - return t.highlight.Format(s) + return theme.highlight.Format(s) +} + +// Timestamp formats and colorizes the timestamp. +func (theme Theme) Timestamp(t time.Time) string { + // TODO: Change this per-theme? Or config? + return theme.sys.Format(t.Format("2006-01-02 15:04 UTC")) } // List of initialzied themes diff --git a/chat/message/user.go b/chat/message/user.go index d094bde..807d1f4 100644 --- a/chat/message/user.go +++ b/chat/message/user.go @@ -158,17 +158,22 @@ func (u *User) SetHighlight(s string) error { func (u *User) render(m Message) string { cfg := u.Config() + var out string switch m := m.(type) { case PublicMsg: - return m.RenderFor(cfg) + Newline + out += m.RenderFor(cfg) case *PrivateMsg: + out += m.Render(cfg.Theme) if cfg.Bell { - return m.Render(cfg.Theme) + Bel + Newline + out += Bel } - return m.Render(cfg.Theme) + Newline default: - return m.Render(cfg.Theme) + Newline + out += m.Render(cfg.Theme) } + if cfg.Timestamp { + return cfg.Theme.Timestamp(m.Timestamp()) + " " + out + Newline + } + return out + Newline } // writeMsg renders the message and attempts to write it, will Close the user