Skip to content

Commit

Permalink
Fix cursor direction escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed May 6, 2020
1 parent 5e5b0f5 commit fa99672
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (t *Terminal) handleEscape(code string) {
t.moveCursor(t.cursorRow+rows, t.cursorCol)
case "C":
cols, _ := strconv.Atoi(message)
t.moveCursor(t.cursorRow, t.cursorCol-cols)
t.moveCursor(t.cursorRow, t.cursorCol+cols)
case "D":
cols, _ := strconv.Atoi(message)
t.moveCursor(t.cursorRow, t.cursorCol+cols)
t.moveCursor(t.cursorRow, t.cursorCol-cols)
case "H", "f":
parts := strings.Split(message, ";")
row, _ := strconv.Atoi(parts[0])
Expand Down
8 changes: 4 additions & 4 deletions escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func TestCursorMove(t *testing.T) {
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)

term.handleEscape("2C")
term.handleEscape("2D")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)

term.handleEscape("2D")
term.handleEscape("2C")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)

Expand All @@ -66,11 +66,11 @@ func TestCursorMove_Overflow(t *testing.T) {
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)

term.handleEscape("2C")
term.handleEscape("2D")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 0, term.cursorCol)

term.handleEscape("5D")
term.handleEscape("5C")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)

Expand Down

0 comments on commit fa99672

Please sign in to comment.