chat/message: Add PublicMsg.RenderSelf(...) to support old-style formatting

This commit is contained in:
Andrey Petrov committed 2019-03-16 11:52:07 -04:00
1 parent eb10bad08e
commit 33d0c08ffe
2 files changed
+11 -1

No files matched your search

+6
View File
@@ -112,6 +112,7 @@ func (m PublicMsg) Render(t *Theme) string {
return fmt.Sprintf("%s: %s", t.ColorName(m.from), m.body)
}
// RenderFor renders the message for other users to see.
func (m PublicMsg) RenderFor(cfg UserConfig) string {
if cfg.Highlight == nil || cfg.Theme == nil {
return m.Render(cfg.Theme)
@@ -128,6 +129,11 @@ func (m PublicMsg) RenderFor(cfg UserConfig) string {
return fmt.Sprintf("%s: %s", cfg.Theme.ColorName(m.from), body)
}
// RenderSelf renders the message for when it's echoing your own message.
func (m PublicMsg) RenderSelf(cfg UserConfig) string {
return fmt.Sprintf("[%s] %s", cfg.Theme.ColorName(m.from), m.body)
}
func (m PublicMsg) String() string {
return fmt.Sprintf("%s: %s", m.from.Name(), m.body)
}
+5 -1
View File
@@ -161,7 +161,11 @@ func (u *User) render(m Message) string {
var out string
switch m := m.(type) {
case PublicMsg:
out += m.RenderFor(cfg)
if u == m.From() {
out += m.RenderSelf(cfg)
} else {
out += m.RenderFor(cfg)
}
case *PrivateMsg:
out += m.Render(cfg.Theme)
if cfg.Bell {