From 414d23ccb1f56633afd8d13f40f964bbb221aa8b Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Sat, 24 Nov 2018 21:56:48 +0000 Subject: [PATCH] Add support for CSI ICH (@) --- buffer/buffer.go | 10 ++++++++++ terminal/csi.go | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/buffer/buffer.go b/buffer/buffer.go index c00e821..9ebc535 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -482,6 +482,16 @@ func (buffer *Buffer) insertLine() { } } +func (buffer *Buffer) InsertBlankCharacters(count int) { + + index := int(buffer.RawLine()) + for i := 0; i < count; i++ { + cells := buffer.lines[index].cells + c := Cell{} + buffer.lines[index].cells = append(cells[:buffer.cursorX], append([]Cell{c}, cells[buffer.cursorX:]...)...) + } +} + func (buffer *Buffer) InsertLines(count int) { if buffer.HasScrollableRegion() && !buffer.InScrollableRegion() { diff --git a/terminal/csi.go b/terminal/csi.go index 34d4c5c..7ef6781 100644 --- a/terminal/csi.go +++ b/terminal/csi.go @@ -46,6 +46,7 @@ var csiSequences = []csiMapping{ {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"}, {id: 'X', handler: csiEraseCharactersHandler, description: "Erase Ps Character(s) (default = 1) (ECH"}, + {id: '@', handler: csiInsertBlankCharactersHandler, description: "Insert Ps (Blank) Character(s) (default = 1) (ICH)"}, } func csiHandler(pty chan rune, terminal *Terminal) error { @@ -259,6 +260,24 @@ func csiScrollUpHandler(params []string, intermediate string, terminal *Terminal return nil } +func csiInsertBlankCharactersHandler(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().InsertBlankCharacters(count) + + return nil +} + func csiInsertLinesHandler(params []string, intermediate string, terminal *Terminal) error { count := 1 if len(params) > 1 {