From 49e2fbe5917c359f48b5e50062df01fb5554daf8 Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 23 Jan 2019 03:22:17 -0500 Subject: [PATCH] Fix #170 by not using ANSI DSR on every key press (#174) Instead of using the ANSI DSR escape code on every key press, only do it once at the beginning of reading input, and keep track of cursor location ourselves. --- terminal/runereader.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/terminal/runereader.go b/terminal/runereader.go index ebd17e85..74f3d835 100644 --- a/terminal/runereader.go +++ b/terminal/runereader.go @@ -41,14 +41,18 @@ func (rr *RuneReader) ReadLine(mask rune) ([]rune, error) { // we get the terminal width and height (if resized after this point the property might become invalid) terminalSize, _ := cursor.Size(rr.Buffer()) + // we set the current location of the cursor once + cursorCurrent, _ := cursor.Location(rr.Buffer()) + for { // wait for some input r, _, err := rr.ReadRune() if err != nil { return line, err } - // we set the current location of the cursor and update it after every key press - cursorCurrent, err := cursor.Location(rr.Buffer()) + // increment cursor location + cursorCurrent.X++ + // if the user pressed enter or some other newline/termination like ctrl+d if r == '\r' || r == '\n' || r == KeyEndTransmission { // delete what's printed out on the console screen (cleanup)