Fixed autocomplete crashing bug (#166)

This commit is contained in:
Andrey Petrov 2016-08-03 17:42:53 -04:00
parent a978f2ce00
commit 13ea34b912

View File

@ -120,8 +120,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
// Successfully joined. // Successfully joined.
term.SetPrompt(GetPrompt(user)) term.SetPrompt(GetPrompt(user))
// FIXME: Re-enable once https://github.com/shazow/ssh-chat/issues/166 is fixed. term.AutoCompleteCallback = h.AutoCompleteFunction(user)
//term.AutoCompleteCallback = h.AutoCompleteFunction(user)
user.SetHighlight(user.Name()) user.SetHighlight(user.Name())
// Should the user be op'd on join? // Should the user be op'd on join?
@ -220,7 +219,10 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
fields := strings.Fields(line[:pos]) fields := strings.Fields(line[:pos])
isFirst := len(fields) < 2 isFirst := len(fields) < 2
partial := fields[len(fields)-1] partial := ""
if len(fields) > 0 {
partial = fields[len(fields)-1]
}
posPartial := pos - len(partial) posPartial := pos - len(partial)
var completed string var completed string