diff --git a/chat/message/user.go b/chat/message/user.go index a3de57b..0fc8cc1 100644 --- a/chat/message/user.go +++ b/chat/message/user.go @@ -161,6 +161,9 @@ func (u *User) render(m Message) string { switch m := m.(type) { case PublicMsg: if u == m.From() { + if !cfg.Echo { + return "" + } out += m.RenderSelf(cfg) } else { out += m.RenderFor(cfg) @@ -226,6 +229,7 @@ type UserConfig struct { Highlight *regexp.Regexp Bell bool Quiet bool + Echo bool // Echo shows your own messages after sending, disabled for bots Timeformat *string Timezone *time.Location Theme *Theme @@ -237,6 +241,7 @@ var DefaultUserConfig UserConfig func init() { DefaultUserConfig = UserConfig{ Bell: true, + Echo: true, Quiet: false, } diff --git a/host.go b/host.go index 4c54fba..8973229 100644 --- a/host.go +++ b/host.go @@ -90,11 +90,20 @@ func (h *Host) isOp(conn sshd.Connection) bool { // Connect a specific Terminal to this host and its room. func (h *Host) Connect(term *sshd.Terminal) { - term.SetEnterClear(true) // We provide our own echo rendering id := NewIdentity(term.Conn) user := message.NewUserScreen(id, term) 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) // Load user config overrides from ENV @@ -151,9 +160,11 @@ func (h *Host) Connect(term *sshd.Terminal) { } // Successfully joined. - term.SetPrompt(GetPrompt(user)) - term.AutoCompleteCallback = h.AutoCompleteFunction(user) - user.SetHighlight(user.Name()) + if !apiMode { + term.SetPrompt(GetPrompt(user)) + term.AutoCompleteCallback = h.AutoCompleteFunction(user) + user.SetHighlight(user.Name()) + } // Should the user be op'd on join? if h.isOp(term.Conn) { @@ -190,15 +201,22 @@ func (h *Host) Connect(term *sshd.Terminal) { m := message.ParseInput(line, user) - if m, ok := m.(*message.CommandMsg); ok { - // Other messages render themselves by the room, commands we'll - // have to re-echo ourselves manually. - user.HandleMsg(m) + if !apiMode { + if m, ok := m.(*message.CommandMsg); ok { + // Other messages render themselves by the room, commands we'll + // have to re-echo ourselves manually. + user.HandleMsg(m) + } } // FIXME: Any reason to use h.room.Send(m) instead? h.HandleMsg(m) + if apiMode { + // Skip the remaining rendering workarounds + continue + } + cmd := m.Command() if cmd == "/nick" || cmd == "/theme" { // Hijack /nick command to update terminal synchronously. Wouldn't diff --git a/sshd/terminal.go b/sshd/terminal.go index 7e40a5d..239a5ef 100644 --- a/sshd/terminal.go +++ b/sshd/terminal.go @@ -103,7 +103,7 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) { return nil, err } term := Terminal{ - Terminal: *terminal.NewTerminal(channel, "Connecting..."), + Terminal: *terminal.NewTerminal(channel, ""), Conn: sshConn{conn}, Channel: channel,