Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chat/message/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -237,6 +241,7 @@ var DefaultUserConfig UserConfig
func init() {
DefaultUserConfig = UserConfig{
Bell: true,
Echo: true,
Quiet: false,
}

Expand Down
36 changes: 27 additions & 9 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sshd/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down