mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 07:37:17 +03:00
chat/message: Add PublicMsg.RenderSelf(...) to support old-style formatting
This commit is contained in:
parent
eb10bad08e
commit
33d0c08ffe
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user