Skip to content

Commit

Permalink
fix(vt): handling for ED (Erase in Display) control sequence (#338)
Browse files Browse the repository at this point in the history
* test(vt): use ED-2 escape sequence to clear screen

* test(vt): update terminal tests to fix ED-0 output

* fix(vt): update how `Erase in Display` n=0 is handled
  • Loading branch information
ryan-gang authored Jan 22, 2025
1 parent dd310ff commit a969dde
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 75 deletions.
11 changes: 7 additions & 4 deletions vt/csi_screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (

func (t *Terminal) handleScreen() {
width, height := t.Width(), t.Height()
_, y := t.scr.CursorPosition()
x, y := t.scr.CursorPosition()

switch t.parser.Cmd() {
case 'J': // Erase in Display [ansi.ED]
count, _ := t.parser.Param(0, 0)
switch count {
case 0: // Erase screen below (including cursor)
rect := Rect(0, y, width, height-y)
t.scr.Fill(t.scr.blankCell(), rect)
case 0: // Erase screen below (from after cursor position)
rect1 := Rect(x, y, width, 1) // cursor to end of line
rect2 := Rect(0, y+1, width, height-y-1) // next line onwards
for _, rect := range []Rectangle{rect1, rect2} {
t.scr.Fill(t.scr.blankCell(), rect)
}
case 1: // Erase screen above (including cursor)
rect := Rect(0, 0, width, y+1)
t.scr.Fill(t.scr.blankCell(), rect)
Expand Down
Loading

0 comments on commit a969dde

Please sign in to comment.