From 1371ace95caffbfda3adb85cf318d02f2f11f652 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Thu, 15 Nov 2018 11:33:35 +0000 Subject: [PATCH] Adding missing DL CIS handler --- Makefile | 15 +++++++++++++++ buffer/buffer.go | 20 ++++++++++++++++++++ terminal/csi.go | 19 +++++++++++++++++++ terminal/sgr.go | 10 +++++++++- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c8c70cd --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +BINARY := aminal +VERSION ?= vlatest + +.PHONY: build +build: test + mkdir -p release + go build -o release/$(BINARY)-$(VERSION) + +.PHONY: test +test: + go test -v ./... + +.PHONY: install +install: build + install -m 0755 release/$(BINARY)-$(VERSION) /usr/local/bin/aminal diff --git a/buffer/buffer.go b/buffer/buffer.go index c688e60..c00e821 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -442,6 +442,11 @@ func (buffer *Buffer) ViewHeight() uint16 { return buffer.viewHeight } +func (buffer *Buffer) deleteLine() { + index := int(buffer.RawLine()) + buffer.lines = buffer.lines[:index+copy(buffer.lines[index:], buffer.lines[index+1:])] +} + func (buffer *Buffer) insertLine() { defer buffer.emitDisplayChange() @@ -492,6 +497,21 @@ func (buffer *Buffer) InsertLines(count int) { } +func (buffer *Buffer) DeleteLines(count int) { + + if buffer.HasScrollableRegion() && !buffer.InScrollableRegion() { + // should have no effect outside of scrollable region + return + } + + buffer.cursorX = 0 + + for i := 0; i < count; i++ { + buffer.deleteLine() + } + +} + func (buffer *Buffer) Index() { // This sequence causes the active position to move downward one line without changing the column position. diff --git a/terminal/csi.go b/terminal/csi.go index 373e428..34d4c5c 100644 --- a/terminal/csi.go +++ b/terminal/csi.go @@ -41,6 +41,7 @@ var csiSequences = []csiMapping{ {id: 'J', handler: csiEraseInDisplayHandler, description: "Erase in Display (ED), VT100"}, {id: 'K', handler: csiEraseInLineHandler, description: "Erase in Line (EL), VT100"}, {id: 'L', handler: csiInsertLinesHandler, description: "Insert Ps Line(s) (default = 1) (IL)"}, + {id: 'M', handler: csiDeleteLinesHandler, description: "Delete Ps Line(s) (default = 1) (DL)"}, {id: 'P', handler: csiDeleteHandler, description: " Delete Ps Character(s) (default = 1) (DCH)"}, {id: 'S', handler: csiScrollUpHandler, description: "Scroll up Ps lines (default = 1) (SU), VT420, ECMA-48"}, {id: 'T', handler: csiScrollDownHandler, description: "Scroll down Ps lines (default = 1) (SD), VT420"}, @@ -276,6 +277,24 @@ func csiInsertLinesHandler(params []string, intermediate string, terminal *Termi return nil } +func csiDeleteLinesHandler(params []string, intermediate string, terminal *Terminal) error { + count := 1 + if len(params) > 1 { + return fmt.Errorf("Not supported") + } + if len(params) == 1 { + var err error + count, err = strconv.Atoi(params[0]) + if err != nil || count < 1 { + count = 1 + } + } + + terminal.ActiveBuffer().DeleteLines(count) + + return nil +} + func csiScrollDownHandler(params []string, intermediate string, terminal *Terminal) error { distance := 1 if len(params) > 1 { diff --git a/terminal/sgr.go b/terminal/sgr.go index 6a43760..b136679 100644 --- a/terminal/sgr.go +++ b/terminal/sgr.go @@ -3,6 +3,7 @@ package terminal import ( "fmt" "strconv" + "strings" "github.com/liamg/aminal/buffer" "github.com/liamg/aminal/config" @@ -15,7 +16,10 @@ func sgrSequenceHandler(params []string, intermediate string, terminal *Terminal } for i := range params { - switch params[i] { + + p := strings.Replace(strings.Replace(params[i], "[", "", -1), "]", "", -1) + + switch p { case "00", "0": attr := terminal.ActiveBuffer().CursorAttr() *attr = buffer.CellAttributes{ @@ -38,6 +42,8 @@ func sgrSequenceHandler(params []string, intermediate string, terminal *Terminal terminal.ActiveBuffer().CursorAttr().Bold = false case "22": terminal.ActiveBuffer().CursorAttr().Dim = false + case "23": + // not italic case "24": terminal.ActiveBuffer().CursorAttr().Underline = false case "25": @@ -46,6 +52,8 @@ func sgrSequenceHandler(params []string, intermediate string, terminal *Terminal terminal.ActiveBuffer().CursorAttr().Reverse = false case "28": terminal.ActiveBuffer().CursorAttr().Hidden = false + case "29": + // not strikethrough case "39": terminal.ActiveBuffer().CursorAttr().FgColour = terminal.config.ColourScheme.Foreground case "30":