From 2076980aea6d57bddb2c80e48a2df7250f1cb8b1 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Mon, 13 Apr 2020 11:22:53 -0400 Subject: [PATCH 1/4] chat/message: Add UserConfig.Echo --- chat/message/user.go | 5 +++++ 1 file changed, 5 insertions(+) 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, } From cce7defd5e829e32c58b1b6af0783d6155bf0539 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Mon, 13 Apr 2020 11:23:11 -0400 Subject: [PATCH 2/4] main: Add TERM=bot handling for Host --- host.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/host.go b/host.go index 4c54fba..1916e62 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 @@ -190,10 +199,12 @@ 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? From 5055bbc859daa7fa08c313cc456a2048b684371b Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Mon, 13 Apr 2020 11:32:38 -0400 Subject: [PATCH 3/4] sshd: Remove temporary "Connecting..." prompt --- sshd/terminal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From a3f41865fdd9948fa5a2a6a3f140d6ea2fe782eb Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Mon, 13 Apr 2020 11:33:12 -0400 Subject: [PATCH 4/4] main: Skip prompt, highlight, autocomplete in bot mode --- host.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/host.go b/host.go index 1916e62..8973229 100644 --- a/host.go +++ b/host.go @@ -160,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) { @@ -210,6 +212,11 @@ func (h *Host) Connect(term *sshd.Terminal) { // 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