Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Fix #170 by not using ANSI DSR on every key press (#174)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stbenjam authored and AlecAivazis committed Jan 23, 2019
1 parent 38cdfa1 commit 49e2fbe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions terminal/runereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49e2fbe

Please sign in to comment.