5 // effectiveSr gets the current effective scroll region in buffer coordinates
6 func (h *windowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion {
7 top := addInRange(window.Top, h.sr.top, window.Top, window.Bottom)
8 bottom := addInRange(window.Top, h.sr.bottom, window.Top, window.Bottom)
11 bottom = window.Bottom
13 return scrollRegion{top: top, bottom: bottom}
16 func (h *windowsAnsiEventHandler) scrollUp(param int) error {
17 info, err := GetConsoleScreenBufferInfo(h.fd)
22 sr := h.effectiveSr(info.Window)
23 return h.scroll(param, sr, info)
26 func (h *windowsAnsiEventHandler) scrollDown(param int) error {
27 return h.scrollUp(-param)
30 func (h *windowsAnsiEventHandler) deleteLines(param int) error {
31 info, err := GetConsoleScreenBufferInfo(h.fd)
36 start := info.CursorPosition.Y
37 sr := h.effectiveSr(info.Window)
38 // Lines cannot be inserted or deleted outside the scrolling region.
39 if start >= sr.top && start <= sr.bottom {
41 return h.scroll(param, sr, info)
47 func (h *windowsAnsiEventHandler) insertLines(param int) error {
48 return h.deleteLines(-param)
51 // scroll scrolls the provided scroll region by param lines. The scroll region is in buffer coordinates.
52 func (h *windowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSOLE_SCREEN_BUFFER_INFO) error {
53 logger.Infof("scroll: scrollTop: %d, scrollBottom: %d", sr.top, sr.bottom)
54 logger.Infof("scroll: windowTop: %d, windowBottom: %d", info.Window.Top, info.Window.Bottom)
56 // Copy from and clip to the scroll region (full buffer width)
57 scrollRect := SMALL_RECT{
61 Right: info.Size.X - 1,
64 // Origin to which area should be copied
67 Y: sr.top - int16(param),
72 Attributes: h.attributes,
75 if err := ScrollConsoleScreenBuffer(h.fd, scrollRect, scrollRect, destOrigin, char); err != nil {
81 func (h *windowsAnsiEventHandler) deleteCharacters(param int) error {
82 info, err := GetConsoleScreenBufferInfo(h.fd)
86 return h.scrollLine(param, info.CursorPosition, info)
89 func (h *windowsAnsiEventHandler) insertCharacters(param int) error {
90 return h.deleteCharacters(-param)
93 // scrollLine scrolls a line horizontally starting at the provided position by a number of columns.
94 func (h *windowsAnsiEventHandler) scrollLine(columns int, position COORD, info *CONSOLE_SCREEN_BUFFER_INFO) error {
95 // Copy from and clip to the scroll region (full buffer width)
96 scrollRect := SMALL_RECT{
100 Right: info.Size.X - 1,
103 // Origin to which area should be copied
105 X: position.X - int16(columns),
111 Attributes: h.attributes,
114 if err := ScrollConsoleScreenBuffer(h.fd, scrollRect, scrollRect, destOrigin, char); err != nil {