mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-09 03:42:25 +03:00
BEL
This commit is contained in:
parent
838285ba43
commit
391a66a876
@ -2,7 +2,6 @@ package chat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -102,13 +101,20 @@ func (m *PublicMsg) Render(t *Theme) string {
|
|||||||
return fmt.Sprintf("%s: %s", t.ColorName(m.from), m.body)
|
return fmt.Sprintf("%s: %s", t.ColorName(m.from), m.body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PublicMsg) RenderHighlighted(t *Theme, highlight *regexp.Regexp) string {
|
func (m *PublicMsg) RenderFor(cfg UserConfig) string {
|
||||||
if highlight == nil || t == nil {
|
if cfg.Highlight == nil || cfg.Theme == nil {
|
||||||
return m.Render(t)
|
return m.Render(cfg.Theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
body := highlight.ReplaceAllString(m.body, t.Highlight("${1}"))
|
if !cfg.Highlight.MatchString(m.body) {
|
||||||
return fmt.Sprintf("%s: %s", t.ColorName(m.from), 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 {
|
func (m *PublicMsg) String() string {
|
||||||
|
@ -26,6 +26,9 @@ const (
|
|||||||
|
|
||||||
// Newline
|
// Newline
|
||||||
Newline = "\r\n"
|
Newline = "\r\n"
|
||||||
|
|
||||||
|
// BEL
|
||||||
|
Bel = "\007"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface for Styles
|
// Interface for Styles
|
||||||
|
@ -116,7 +116,7 @@ func (u *User) SetHighlight(s string) error {
|
|||||||
func (u User) render(m Message) string {
|
func (u User) render(m Message) string {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *PublicMsg:
|
case *PublicMsg:
|
||||||
return m.RenderHighlighted(u.Config.Theme, u.Config.Highlight) + Newline
|
return m.RenderFor(u.Config) + Newline
|
||||||
default:
|
default:
|
||||||
return m.Render(u.Config.Theme) + Newline
|
return m.Render(u.Config.Theme) + Newline
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user