Skip to content

Commit

Permalink
Merge pull request #16 from jstarks/more_scrolling_fixes
Browse files Browse the repository at this point in the history
Fix DL, IL, SU, and SD
  • Loading branch information
ahmetb committed Aug 7, 2015
2 parents 326d07f + 0310580 commit 42a7d91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 18 additions & 14 deletions winterm/scroll_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,39 @@ func (h *WindowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion {
return scrollRegion{top: top, bottom: bottom}
}

func (h *WindowsAnsiEventHandler) scrollPageUp() error {
return h.scrollPage(1)
}

func (h *WindowsAnsiEventHandler) scrollPageDown() error {
return h.scrollPage(-1)
}

func (h *WindowsAnsiEventHandler) scrollPage(param int) error {
func (h *WindowsAnsiEventHandler) scrollUp(param int) error {
info, err := GetConsoleScreenBufferInfo(h.fd)
if err != nil {
return err
}

return h.scroll(param, scrollRegion{info.Window.Top, info.Window.Bottom}, info)
sr := h.effectiveSr(info.Window)
return h.scroll(param, sr, info)
}

func (h *WindowsAnsiEventHandler) scrollUp(param int) error {
func (h *WindowsAnsiEventHandler) scrollDown(param int) error {
return h.scrollUp(-param)
}

func (h *WindowsAnsiEventHandler) deleteLines(param int) error {
info, err := GetConsoleScreenBufferInfo(h.fd)
if err != nil {
return err
}

start := info.CursorPosition.Y
sr := h.effectiveSr(info.Window)
return h.scroll(param, sr, info)
// Lines cannot be inserted or deleted outside the scrolling region.
if start >= sr.top && start <= sr.bottom {
sr.top = start
return h.scroll(param, sr, info)
} else {
return nil
}
}

func (h *WindowsAnsiEventHandler) scrollDown(param int) error {
return h.scrollUp(-param)
func (h *WindowsAnsiEventHandler) insertLines(param int) error {
return h.deleteLines(-param)
}

// scroll scrolls the provided scroll region by param lines. The scroll region is in buffer coordinates.
Expand Down
12 changes: 4 additions & 8 deletions winterm/win_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,7 @@ func (h *WindowsAnsiEventHandler) IL(param int) error {
}
logger.Infof("IL: [%v]", strconv.Itoa(param))
h.clearWrap()
if err := h.scrollDown(param); err != nil {
return err
}

return h.EL(2)
return h.insertLines(param)
}

func (h *WindowsAnsiEventHandler) DL(param int) error {
Expand All @@ -497,7 +493,7 @@ func (h *WindowsAnsiEventHandler) DL(param int) error {
}
logger.Infof("DL: [%v]", strconv.Itoa(param))
h.clearWrap()
return h.scrollUp(param)
return h.deleteLines(param)
}

func (h *WindowsAnsiEventHandler) SGR(params []int) error {
Expand Down Expand Up @@ -545,7 +541,7 @@ func (h *WindowsAnsiEventHandler) SU(param int) error {
}
logger.Infof("SU: [%v]", []string{strconv.Itoa(param)})
h.clearWrap()
return h.scrollPageUp()
return h.scrollUp(param)
}

func (h *WindowsAnsiEventHandler) SD(param int) error {
Expand All @@ -554,7 +550,7 @@ func (h *WindowsAnsiEventHandler) SD(param int) error {
}
logger.Infof("SD: [%v]", []string{strconv.Itoa(param)})
h.clearWrap()
return h.scrollPageDown()
return h.scrollDown(param)
}

func (h *WindowsAnsiEventHandler) DA(params []string) error {
Expand Down

0 comments on commit 42a7d91

Please sign in to comment.