main: Add TERM=bot handling for Host

This commit is contained in:
Andrey Petrov 2020-04-13 11:23:11 -04:00
parent 2076980aea
commit cce7defd5e

23
host.go
View File

@ -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?