From b8ad1883f50104fc6565496144e646ba9d184021 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 11 Oct 2020 09:49:07 +1100 Subject: fix delta --- go.mod | 2 +- go.sum | 4 +-- vendor/github.com/jesseduffield/gocui/escape.go | 37 ++++++++++++++++++++++--- vendor/github.com/jesseduffield/gocui/view.go | 34 +++++++++++++++++++++++ vendor/modules.txt | 2 +- 5 files changed, 71 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 4403d434d..633bcb6ed 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/imdario/mergo v0.3.11 github.com/integrii/flaggy v1.4.0 github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 - github.com/jesseduffield/gocui v0.3.1-0.20201007110350-cc51e317126e + github.com/jesseduffield/gocui v0.3.1-0.20201010224802-8a6768078fd7 github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe github.com/jesseduffield/yaml v2.1.0+incompatible github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 diff --git a/go.sum b/go.sum index a52aad393..63d20d766 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o= -github.com/jesseduffield/gocui v0.3.1-0.20201007110350-cc51e317126e h1:FYXSJfL6JKWB+1NjGqT5/kYJbMI9oMx+JAI3CcrtLsM= -github.com/jesseduffield/gocui v0.3.1-0.20201007110350-cc51e317126e/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= +github.com/jesseduffield/gocui v0.3.1-0.20201010224802-8a6768078fd7 h1:K3MGrjmpPtIhfXmKh/zsIF0CdmNKOkjpIwcUfAa/J2A= +github.com/jesseduffield/gocui v0.3.1-0.20201010224802-8a6768078fd7/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe h1:qsVhCf2RFyyKIUe/+gJblbCpXMUki9rZrHuEctg6M/E= github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4= github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE= diff --git a/vendor/github.com/jesseduffield/gocui/escape.go b/vendor/github.com/jesseduffield/gocui/escape.go index 540946117..c8bad21ad 100644 --- a/vendor/github.com/jesseduffield/gocui/escape.go +++ b/vendor/github.com/jesseduffield/gocui/escape.go @@ -16,6 +16,19 @@ type escapeInterpreter struct { csiParam []string curFgColor, curBgColor Attribute mode OutputMode + instruction instruction +} + +const ( + NONE = 1 << iota + ERASE_IN_LINE +) + +type instruction struct { + kind int + param1 int + param2 int + toWrite []rune } type escapeState int @@ -57,10 +70,11 @@ func (ei *escapeInterpreter) runes() []rune { // terminal escape sequences. func newEscapeInterpreter(mode OutputMode) *escapeInterpreter { ei := &escapeInterpreter{ - state: stateNone, - curFgColor: ColorDefault, - curBgColor: ColorDefault, - mode: mode, + state: stateNone, + curFgColor: ColorDefault, + curBgColor: ColorDefault, + mode: mode, + instruction: instruction{kind: NONE}, } return ei } @@ -73,6 +87,10 @@ func (ei *escapeInterpreter) reset() { ei.csiParam = nil } +func (ei *escapeInterpreter) instructionRead() { + ei.instruction.kind = NONE +} + // parseOne parses a rune. If isEscape is true, it means that the rune is part // of an escape sequence, and as such should not be printed verbatim. Otherwise, // it's not an escape sequence. @@ -131,6 +149,17 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { return false, errCSIParseError } + ei.state = stateNone + ei.csiParam = nil + return true, nil + case ch == 'K': + p, err := strconv.Atoi(ei.csiParam[0]) + if err != nil { + return false, errCSIParseError + } + ei.instruction.kind = ERASE_IN_LINE + ei.instruction.param1 = p + ei.state = stateNone ei.csiParam = nil return true, nil diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index 89cb7ab28..3b83d4a0c 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -400,6 +400,15 @@ func (v *View) Write(p []byte) (n int, err error) { } default: cells := v.parseInput(ch) + if v.ei.instruction.kind != NONE { + switch v.ei.instruction.kind { + case ERASE_IN_LINE: + v.eraseInLine() + } + v.ei.instructionRead() + continue + } + if cells == nil { continue } @@ -416,6 +425,31 @@ func (v *View) Write(p []byte) (n int, err error) { return len(p), nil } +func (v *View) eraseInLine() { + code := v.ei.instruction.param1 + switch code { + case 0: + // need to write till end of the line with cells containing the same bg colour as we currently have. + + if len(v.lines) == 0 { + v.lines = append(v.lines, []cell{}) + } + nl := len(v.lines) + width, _ := v.Size() + cellCount := width - len(v.lines[nl-1]) + c := cell{ + fgColor: v.ei.curFgColor, + bgColor: v.ei.curBgColor, + chr: ' ', + } + for i := 0; i < cellCount; i++ { + v.lines[nl-1] = append(v.lines[nl-1], c) + } + default: + // don't recognise sequence. Until we merge the gocui master branch we can't handle going backwards. + } +} + // parseInput parses char by char the input written to the View. It returns nil // while processing ESC sequences. Otherwise, it returns a cell slice that // contains the processed data. diff --git a/vendor/modules.txt b/vendor/modules.txt index 052b13c27..5ecef1386 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -104,7 +104,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/noder -# github.com/jesseduffield/gocui v0.3.1-0.20201007110350-cc51e317126e +# github.com/jesseduffield/gocui v0.3.1-0.20201010224802-8a6768078fd7 ## explicit github.com/jesseduffield/gocui # github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe -- cgit v1.2.3