diff --git a/chat/message.go b/chat/message.go index c98805c..d271e0b 100644 --- a/chat/message.go +++ b/chat/message.go @@ -2,7 +2,6 @@ package chat import ( "fmt" - "regexp" "strings" "time" ) @@ -102,13 +101,20 @@ func (m *PublicMsg) Render(t *Theme) string { return fmt.Sprintf("%s: %s", t.ColorName(m.from), m.body) } -func (m *PublicMsg) RenderHighlighted(t *Theme, highlight *regexp.Regexp) string { - if highlight == nil || t == nil { - return m.Render(t) +func (m *PublicMsg) RenderFor(cfg UserConfig) string { + if cfg.Highlight == nil || cfg.Theme == nil { + return m.Render(cfg.Theme) } - body := highlight.ReplaceAllString(m.body, t.Highlight("${1}")) - return fmt.Sprintf("%s: %s", t.ColorName(m.from), body) + if !cfg.Highlight.MatchString(m.body) { + return m.Render(cfg.Theme) + } + + body := cfg.Highlight.ReplaceAllString(m.body, cfg.Theme.Highlight("${1}")) + if cfg.Bell { + body += Bel + } + return fmt.Sprintf("%s: %s", cfg.Theme.ColorName(m.from), body) } func (m *PublicMsg) String() string { diff --git a/chat/theme.go b/chat/theme.go index 5e7af3c..4d052f4 100644 --- a/chat/theme.go +++ b/chat/theme.go @@ -26,6 +26,9 @@ const ( // Newline Newline = "\r\n" + + // BEL + Bel = "\007" ) // Interface for Styles diff --git a/chat/user.go b/chat/user.go index b82c830..df8114b 100644 --- a/chat/user.go +++ b/chat/user.go @@ -116,7 +116,7 @@ func (u *User) SetHighlight(s string) error { func (u User) render(m Message) string { switch m := m.(type) { case *PublicMsg: - return m.RenderHighlighted(u.Config.Theme, u.Config.Highlight) + Newline + return m.RenderFor(u.Config) + Newline default: return m.Render(u.Config.Theme) + Newline }