mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-14 16:17:17 +03:00
BEL
This commit is contained in:
parent
838285ba43
commit
391a66a876
@ -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 {
|
||||
|
@ -26,6 +26,9 @@ const (
|
||||
|
||||
// Newline
|
||||
Newline = "\r\n"
|
||||
|
||||
// BEL
|
||||
Bel = "\007"
|
||||
)
|
||||
|
||||
// Interface for Styles
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user