From daf32ef9caae2ae981086411e8fa842712d203da Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Sun, 12 Aug 2018 20:24:53 +0100 Subject: [PATCH] started work on scrollable regions --- buffer/buffer.go | 8 ++++++++ terminal/csi.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/buffer/buffer.go b/buffer/buffer.go index d0baa14..8e43852 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -15,6 +15,8 @@ type Buffer struct { savedX uint16 savedY uint16 scrollLinesFromBottom uint + topMargin uint // see DECSTBM docs - this is for scrollable regions + bottomMargin uint // see DECSTBM docs - this is for scrollable regions } // NewBuffer creates a new terminal buffer @@ -29,6 +31,11 @@ func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer { return b } +func (buffer *Buffer) SetMargins(top uint, bottom uint) { + buffer.topMargin = top + buffer.bottomMargin = bottom +} + func (buffer *Buffer) GetScrollOffset() uint { return buffer.scrollLinesFromBottom } @@ -536,4 +543,5 @@ func (buffer *Buffer) ResizeView(width uint16, height uint16) { line = buffer.getCurrentLine() buffer.cursorX = uint16((len(line.cells) - cXFromEndOfLine) - 1) + buffer.SetMargins(0, uint(buffer.viewHeight-1)) } diff --git a/terminal/csi.go b/terminal/csi.go index 81ce0b5..cf5ae68 100644 --- a/terminal/csi.go +++ b/terminal/csi.go @@ -16,6 +16,37 @@ var csiSequenceMap = map[rune]csiSequenceHandler{ 'd': csiLinePositionAbsolute, 't': csiWindowManipulation, 'X': csiEraseCharactersHandler, + 'r': csiSetMarginsHandler, +} + +// DECSTBM +func csiSetMarginsHandler(params []string, intermediate string, terminal *Terminal) error { + top := 1 + bottom := int(terminal.ActiveBuffer().ViewHeight()) + if len(params) > 0 { + var err error + top, err = strconv.Atoi(params[0]) + if err != nil { + top = 1 + } + + if len(params) > 1 { + var err error + bottom, err = strconv.Atoi(params[1]) + if err != nil { + bottom = 1 + } + if bottom > int(terminal.ActiveBuffer().ViewHeight()) { + bottom = int(terminal.ActiveBuffer().ViewHeight()) + } + } + } + top -= 1 + bottom -= 1 + + terminal.ActiveBuffer().SetPosition(0, 0) + + return nil } func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {