Skip to content

Commit

Permalink
Merge pull request #13 from jstarks/fix_clear
Browse files Browse the repository at this point in the history
Do not move cursor with ED (clear in display)
  • Loading branch information
ahmetb committed Aug 6, 2015
2 parents 0b2121c + 6adeeb9 commit 51d4cb8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions winterm/win_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
if err := h.scrollUp(1); err != nil {
return err
}
return h.moveCursorColumn(1)
return h.moveCursorColumn(1)
}
}

Expand Down Expand Up @@ -205,9 +205,7 @@ func (h *WindowsAnsiEventHandler) ED(param int) error {
// [J -- Erases from the cursor to the end of the screen, including the cursor position.
// [1J -- Erases from the beginning of the screen to the cursor, including the cursor position.
// [2J -- Erases the complete display. The cursor does not move.
// [3J -- Erases the complete display and backing buffer, cursor moves to (0,0)
// Notes:
// -- ANSI.SYS always moved the cursor to (0,0) for both [2J and [3J
// -- Clearing the entire buffer, versus just the Window, works best for Windows Consoles

info, err := GetConsoleScreenBufferInfo(h.fd)
Expand All @@ -230,20 +228,25 @@ func (h *WindowsAnsiEventHandler) ED(param int) error {
case 2:
start = COORD{0, 0}
end = COORD{info.Size.X - 1, info.Size.Y - 1}

case 3:
start = COORD{0, 0}
end = COORD{info.Size.X - 1, info.Size.Y - 1}
}

err = h.clearRange(h.attributes, start, end)
if err != nil {
return err
}

if param == 2 || param == 3 {
err = h.setCursorPosition(COORD{0, 0}, info.Size)
if err != nil {
// If the whole buffer was cleared, move the window to the top while preserving
// the window-relative cursor position.
if param == 2 {
pos := info.CursorPosition
window := info.Window
pos.Y -= window.Top
window.Bottom -= window.Top
window.Top = 0
if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
return err
}
if err := SetConsoleWindowInfo(h.fd, true, window); err != nil {
return err
}
}
Expand Down Expand Up @@ -405,7 +408,7 @@ func (h *WindowsAnsiEventHandler) DECSTBM(top int, bottom int) error {
h.sr.bottom = SHORT(bottom - 1)

// This command also moves the cursor to the origin.
return h.CUP(1,1)
return h.CUP(1, 1)
}

func (h *WindowsAnsiEventHandler) RI() error {
Expand Down

0 comments on commit 51d4cb8

Please sign in to comment.