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

This commit is contained in:
Andrey Petrov 2019-03-15 16:20:13 -04:00
parent eb10bad08e
commit 33d0c08ffe
2 changed files with 11 additions and 1 deletions

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)
}

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 {