BEL
authorAndrey Petrov <andrey.petrov@shazow.net>
Sat, 17 Jan 2015 23:56:29 +0000 (15:56 -0800)
committerAndrey Petrov <andrey.petrov@shazow.net>
Sat, 17 Jan 2015 23:56:29 +0000 (15:56 -0800)
chat/message.go
chat/theme.go
chat/user.go

index c98805cc74a466d57fa6677ba812bd09cc899043..d271e0ba513c17d7245a71605ad0fb43055ecd18 100644 (file)
@@ -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 {
index 5e7af3cd77fd2e0c0fc30d0446234014f7d8db99..4d052f466f73f1639a6a106248bdca2363e60e07 100644 (file)
@@ -26,6 +26,9 @@ const (
 
        // Newline
        Newline = "\r\n"
+
+       // BEL
+       Bel = "\007"
 )
 
 // Interface for Styles
index b82c8300820f2b8de10213db2cda8fa48192e8c0..df8114b865dd3ec3c136441c7ede1c968f864d23 100644 (file)
@@ -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
        }