From 479a391d5598a9c0f52521c48e9dd077530398a5 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 29 Mar 2019 17:25:51 -0400 Subject: [PATCH] sshd/terminal: Use clearline and clearscreen codes for enterClear Fixes emoji offset bug --- sshd/terminal/terminal.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sshd/terminal/terminal.go b/sshd/terminal/terminal.go index 82fa6ad..01cb346 100644 --- a/sshd/terminal/terminal.go +++ b/sshd/terminal/terminal.go @@ -529,11 +529,18 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) { case keyEnter: line = string(t.line) if t.enterClear { - // Clear line on enter instead of starting a new line. The old - // prompt is retained. - t.moveCursorToPos(0) - t.clearLineToRight() - t.clearScreenBelow() // Necessary for wrapped lines + // Clear line on enter instead of starting a new line. + reset := []rune{ + // Clear whole line + keyEscape, '[', '2', 'K', + // Clear screen below (for any wrapped lines) + keyEscape, '[', 'J', + } + t.queue(reset) + // We're still technically on the same line. If we don't offset the + // cursorX, then the fresh prompt could be rendered in the wrong + // position. + t.cursorX += len(reset) } else { // Pushing the line up resets the cursor to 0,0 and we render a // fresh prompt.