From 8b710da728dddf0487a88ea14c6a064a9b08956b Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Tue, 19 Mar 2019 12:09:54 -0400 Subject: [PATCH] sshd/terminal: Fix mid-line enter and reflow bugs --- sshd/terminal/terminal.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sshd/terminal/terminal.go b/sshd/terminal/terminal.go index 00963f6..eb036cc 100644 --- a/sshd/terminal/terminal.go +++ b/sshd/terminal/terminal.go @@ -511,22 +511,23 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) { } } case keyEnter: - t.moveCursorToPos(len(t.line)) line = string(t.line) - if t.ClearLine { - // Clear line on enter instead of starting a new line - t.eraseNPreviousChars(t.pos) - ok = true - return + // Clear line on enter instead of starting a new line. The old + // prompt is retained. + t.moveCursorToPos(0) + t.clearLineToRight() + } else { + // Pushing the line up resets the cursor to 0,0 and we render a + // fresh prompt. + t.moveCursorToPos(len(t.line)) + t.queue([]rune("\r\n")) + t.cursorX = 0 + t.cursorY = 0 } - - t.queue([]rune("\r\n")) ok = true t.line = t.line[:0] t.pos = 0 - t.cursorX = 0 - t.cursorY = 0 t.maxLine = 0 case keyDeleteWord: // Delete zero or more spaces and then one or more characters.