mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 19:03:17 +03:00
commit
3b8e644c9e
@ -161,6 +161,9 @@ func (u *User) render(m Message) string {
|
|||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case PublicMsg:
|
case PublicMsg:
|
||||||
if u == m.From() {
|
if u == m.From() {
|
||||||
|
if !cfg.Echo {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
out += m.RenderSelf(cfg)
|
out += m.RenderSelf(cfg)
|
||||||
} else {
|
} else {
|
||||||
out += m.RenderFor(cfg)
|
out += m.RenderFor(cfg)
|
||||||
@ -226,6 +229,7 @@ type UserConfig struct {
|
|||||||
Highlight *regexp.Regexp
|
Highlight *regexp.Regexp
|
||||||
Bell bool
|
Bell bool
|
||||||
Quiet bool
|
Quiet bool
|
||||||
|
Echo bool // Echo shows your own messages after sending, disabled for bots
|
||||||
Timeformat *string
|
Timeformat *string
|
||||||
Timezone *time.Location
|
Timezone *time.Location
|
||||||
Theme *Theme
|
Theme *Theme
|
||||||
@ -237,6 +241,7 @@ var DefaultUserConfig UserConfig
|
|||||||
func init() {
|
func init() {
|
||||||
DefaultUserConfig = UserConfig{
|
DefaultUserConfig = UserConfig{
|
||||||
Bell: true,
|
Bell: true,
|
||||||
|
Echo: true,
|
||||||
Quiet: false,
|
Quiet: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
host.go
36
host.go
@ -90,11 +90,20 @@ func (h *Host) isOp(conn sshd.Connection) bool {
|
|||||||
|
|
||||||
// Connect a specific Terminal to this host and its room.
|
// Connect a specific Terminal to this host and its room.
|
||||||
func (h *Host) Connect(term *sshd.Terminal) {
|
func (h *Host) Connect(term *sshd.Terminal) {
|
||||||
term.SetEnterClear(true) // We provide our own echo rendering
|
|
||||||
id := NewIdentity(term.Conn)
|
id := NewIdentity(term.Conn)
|
||||||
user := message.NewUserScreen(id, term)
|
user := message.NewUserScreen(id, term)
|
||||||
cfg := user.Config()
|
cfg := user.Config()
|
||||||
cfg.Theme = &h.theme
|
|
||||||
|
apiMode := strings.ToLower(term.Term()) == "bot"
|
||||||
|
|
||||||
|
if apiMode {
|
||||||
|
cfg.Theme = message.MonoTheme
|
||||||
|
cfg.Echo = false
|
||||||
|
} else {
|
||||||
|
term.SetEnterClear(true) // We provide our own echo rendering
|
||||||
|
cfg.Theme = &h.theme
|
||||||
|
}
|
||||||
|
|
||||||
user.SetConfig(cfg)
|
user.SetConfig(cfg)
|
||||||
|
|
||||||
// Load user config overrides from ENV
|
// Load user config overrides from ENV
|
||||||
@ -151,9 +160,11 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Successfully joined.
|
// Successfully joined.
|
||||||
term.SetPrompt(GetPrompt(user))
|
if !apiMode {
|
||||||
term.AutoCompleteCallback = h.AutoCompleteFunction(user)
|
term.SetPrompt(GetPrompt(user))
|
||||||
user.SetHighlight(user.Name())
|
term.AutoCompleteCallback = h.AutoCompleteFunction(user)
|
||||||
|
user.SetHighlight(user.Name())
|
||||||
|
}
|
||||||
|
|
||||||
// Should the user be op'd on join?
|
// Should the user be op'd on join?
|
||||||
if h.isOp(term.Conn) {
|
if h.isOp(term.Conn) {
|
||||||
@ -190,15 +201,22 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
|||||||
|
|
||||||
m := message.ParseInput(line, user)
|
m := message.ParseInput(line, user)
|
||||||
|
|
||||||
if m, ok := m.(*message.CommandMsg); ok {
|
if !apiMode {
|
||||||
// Other messages render themselves by the room, commands we'll
|
if m, ok := m.(*message.CommandMsg); ok {
|
||||||
// have to re-echo ourselves manually.
|
// Other messages render themselves by the room, commands we'll
|
||||||
user.HandleMsg(m)
|
// have to re-echo ourselves manually.
|
||||||
|
user.HandleMsg(m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Any reason to use h.room.Send(m) instead?
|
// FIXME: Any reason to use h.room.Send(m) instead?
|
||||||
h.HandleMsg(m)
|
h.HandleMsg(m)
|
||||||
|
|
||||||
|
if apiMode {
|
||||||
|
// Skip the remaining rendering workarounds
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
cmd := m.Command()
|
cmd := m.Command()
|
||||||
if cmd == "/nick" || cmd == "/theme" {
|
if cmd == "/nick" || cmd == "/theme" {
|
||||||
// Hijack /nick command to update terminal synchronously. Wouldn't
|
// Hijack /nick command to update terminal synchronously. Wouldn't
|
||||||
|
@ -103,7 +103,7 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
term := Terminal{
|
term := Terminal{
|
||||||
Terminal: *terminal.NewTerminal(channel, "Connecting..."),
|
Terminal: *terminal.NewTerminal(channel, ""),
|
||||||
Conn: sshConn{conn},
|
Conn: sshConn{conn},
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user