From 535b9cfb5ce640ac089807a16307b8663940ad25 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 5 May 2024 03:20:31 -0400 Subject: [PATCH 1/3] upgrade to readline v0.1.1-rc1 --- go.mod | 2 +- go.sum | 2 + .../github.com/ergochat/readline/.travis.yml | 8 ---- .../github.com/ergochat/readline/CHANGELOG.md | 6 --- vendor/github.com/ergochat/readline/README.md | 41 +++++++++++++++++++ .../readline/internal/platform/utils_unix.go | 2 +- .../github.com/ergochat/readline/terminal.go | 33 +++++++++------ vendor/github.com/ergochat/readline/vim.go | 20 ++++----- vendor/modules.txt | 2 +- 9 files changed, 76 insertions(+), 40 deletions(-) delete mode 100644 vendor/github.com/ergochat/readline/.travis.yml delete mode 100644 vendor/github.com/ergochat/readline/CHANGELOG.md diff --git a/go.mod b/go.mod index cb2fb36..d6276c5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 github.com/ergochat/irc-go v0.3.0 - github.com/ergochat/readline v0.1.0-rc1 + github.com/ergochat/readline v0.1.1-rc1 github.com/gorilla/websocket v1.5.0 github.com/jwalton/go-supportscolor v1.1.0 golang.org/x/term v0.6.0 diff --git a/go.sum b/go.sum index eeec293..58a26c2 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/ergochat/irc-go v0.3.0 h1:qgvb2knh8d6yIVsHX+PRQ2CiRj1NGG5x88ABmR1lWng github.com/ergochat/irc-go v0.3.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0= github.com/ergochat/readline v0.1.0-rc1 h1:zY4gDCDMV0LpJW9hU+0aA+vlzVb6MJKPEQLM4b8p/h4= github.com/ergochat/readline v0.1.0-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= +github.com/ergochat/readline v0.1.1-rc1 h1:VWYKbzKbRX54feYhcoZIoydRdSwOOUR/UbOGu6wZmMc= +github.com/ergochat/readline v0.1.1-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ= diff --git a/vendor/github.com/ergochat/readline/.travis.yml b/vendor/github.com/ergochat/readline/.travis.yml deleted file mode 100644 index 9c35955..0000000 --- a/vendor/github.com/ergochat/readline/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: - - 1.x -script: - - GOOS=windows go install github.com/chzyer/readline/example/... - - GOOS=linux go install github.com/chzyer/readline/example/... - - GOOS=darwin go install github.com/chzyer/readline/example/... - - go test -race -v diff --git a/vendor/github.com/ergochat/readline/CHANGELOG.md b/vendor/github.com/ergochat/readline/CHANGELOG.md deleted file mode 100644 index c467800..0000000 --- a/vendor/github.com/ergochat/readline/CHANGELOG.md +++ /dev/null @@ -1,6 +0,0 @@ -# Changelog - -## [0.0.6] - 2023-11-06 - -* Added `(*Instance).ClearScreen` (#36, #37) -* Removed `(*Instance).Clean` (#37) diff --git a/vendor/github.com/ergochat/readline/README.md b/vendor/github.com/ergochat/readline/README.md index 23dee73..2acf833 100644 --- a/vendor/github.com/ergochat/readline/README.md +++ b/vendor/github.com/ergochat/readline/README.md @@ -1,6 +1,47 @@ readline ======== +[![Godoc](https://godoc.org/github.com/ergochat/readline?status.svg)](https://godoc.org/github.com/ergochat/readline) + This is a pure Go implementation of functionality comparable to [GNU Readline](https://en.wikipedia.org/wiki/GNU_Readline), i.e. line editing and command history for simple TUI programs. It is a fork of [chzyer/readline](https://github.com/chzyer/readline). + +* Relative to the upstream repository, it is actively maintained and has numerous bug fixes + - See our [changelog](docs/CHANGELOG.md) for details on fixes and improvements + - See our [migration guide](docs/MIGRATING.md) for advice on how to migrate from upstream +* Relative to [x/term](https://pkg.go.dev/golang.org/x/term), it has more features (e.g. tab-completion) +* In use by multiple projects: [gopass](https://github.com/gopasspw/gopass), [fq](https://github.com/wader/fq), and [ircdog](https://github.com/ergochat/ircdog) + + +```go +package main + +import ( + "fmt" + "log" + + "github.com/ergochat/readline" +) + +func main() { + // see readline.NewFromConfig for advanced options: + rl, err := readline.New("> ") + if err != nil { + log.Fatal(err) + } + defer rl.Close() + log.SetOutput(rl.Stderr()) // redraw the prompt correctly after log output + + for { + line, err := rl.ReadLine() + // `err` is either nil, io.EOF, readline.ErrInterrupt, or an unexpected + // condition in stdin: + if err != nil { + return + } + // `line` is returned without the terminating \n or CRLF: + fmt.Fprintf(rl, "you wrote: %s\n", line) + } +} +``` diff --git a/vendor/github.com/ergochat/readline/internal/platform/utils_unix.go b/vendor/github.com/ergochat/readline/internal/platform/utils_unix.go index fdbbb62..1e0795d 100644 --- a/vendor/github.com/ergochat/readline/internal/platform/utils_unix.go +++ b/vendor/github.com/ergochat/readline/internal/platform/utils_unix.go @@ -1,4 +1,4 @@ -//go:build aix || darwin || dragonfly || freebsd || (linux && !appengine) || netbsd || openbsd || os400 || solaris +//go:build aix || darwin || dragonfly || freebsd || (linux && !appengine) || netbsd || openbsd || os400 || solaris || zos package platform diff --git a/vendor/github.com/ergochat/readline/terminal.go b/vendor/github.com/ergochat/readline/terminal.go index 015ae1d..e7dd42d 100644 --- a/vendor/github.com/ergochat/readline/terminal.go +++ b/vendor/github.com/ergochat/readline/terminal.go @@ -2,11 +2,11 @@ package readline import ( "bufio" + "bytes" "errors" "fmt" "io" "strconv" - "strings" "sync" "sync/atomic" "time" @@ -276,6 +276,7 @@ func (t *terminal) ioloop() { defer t.Close() buf := bufio.NewReader(t.GetConfig().Stdin) + var ansiBuf bytes.Buffer for { select { @@ -293,7 +294,7 @@ func (t *terminal) ioloop() { if r == '\x1b' { // we're starting an ANSI escape sequence: // keep reading until we reach the end of the sequence - result, err = t.consumeANSIEscape(buf) + result, err = t.consumeANSIEscape(buf, &ansiBuf) if err != nil { return } @@ -309,7 +310,8 @@ func (t *terminal) ioloop() { } } -func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err error) { +func (t *terminal) consumeANSIEscape(buf *bufio.Reader, ansiBuf *bytes.Buffer) (result readResult, err error) { + ansiBuf.Reset() // initial character is either [ or O; if we got something else, // treat the sequence as terminated and don't interpret it initial, _, err := buf.ReadRune() @@ -318,7 +320,6 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err } // data consists of ; and 0-9 , anything else terminates the sequence - var dataBuf strings.Builder var type_ rune for { r, _, err := buf.ReadRune() @@ -326,13 +327,12 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err return result, err } if r == ';' || ('0' <= r && r <= '9') { - dataBuf.WriteRune(r) + ansiBuf.WriteRune(r) } else { type_ = r break } } - data := dataBuf.String() var r rune switch type_ { @@ -340,7 +340,7 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err if initial == '[' { // DSR CPR response; if we can't parse it, just ignore it // (do not return an error here because that would stop ioloop()) - if cpos, err := parseCPRResponse(data); err == nil { + if cpos, err := parseCPRResponse(ansiBuf.Bytes()); err == nil { return readResult{r: 0, ok: false, pos: &cpos}, nil } } @@ -357,8 +357,15 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err case 'F': r = CharLineEnd case '~': - if initial == '[' && data == "3" { - r = MetaDeleteKey // this is the key typically labeled "Delete" + if initial == '[' { + switch string(ansiBuf.Bytes()) { + case "3": + r = MetaDeleteKey // this is the key typically labeled "Delete" + case "7": + r = CharLineStart // "Home" key + case "8": + r = CharLineEnd // "End" key + } } case 'Z': if initial == '[' { @@ -372,10 +379,10 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader) (result readResult, err return // default: no interpretable rune value } -func parseCPRResponse(payload string) (cursorPosition, error) { - if parts := strings.Split(payload, ";"); len(parts) == 2 { - if row, err := strconv.Atoi(parts[0]); err == nil { - if col, err := strconv.Atoi(parts[1]); err == nil { +func parseCPRResponse(payload []byte) (cursorPosition, error) { + if semicolonIdx := bytes.IndexByte(payload, ';'); semicolonIdx != -1 { + if row, err := strconv.Atoi(string(payload[:semicolonIdx])); err == nil { + if col, err := strconv.Atoi(string(payload[semicolonIdx+1:])); err == nil { return cursorPosition{row: row, col: col}, nil } } diff --git a/vendor/github.com/ergochat/readline/vim.go b/vendor/github.com/ergochat/readline/vim.go index baceab4..4f722b6 100644 --- a/vendor/github.com/ergochat/readline/vim.go +++ b/vendor/github.com/ergochat/readline/vim.go @@ -1,9 +1,9 @@ package readline const ( - VIM_NORMAL = iota - VIM_INSERT - VIM_VISUAL + vim_NORMAL = iota + vim_INSERT + vim_VISUAL ) type opVim struct { @@ -14,7 +14,7 @@ type opVim struct { func newVimMode(op *operation) *opVim { ov := &opVim{ op: op, - vimMode: VIM_INSERT, + vimMode: vim_INSERT, } return ov } @@ -119,7 +119,7 @@ func (o *opVim) handleVimNormalEnterInsert(r rune, readNext func() rune) (t rune func (o *opVim) HandleVimNormal(r rune, readNext func() rune) (t rune) { switch r { case CharEnter, CharInterrupt: - o.vimMode = VIM_INSERT // ??? + o.vimMode = vim_INSERT // ??? return r } @@ -137,15 +137,15 @@ func (o *opVim) HandleVimNormal(r rune, readNext func() rune) (t rune) { } func (o *opVim) EnterVimInsertMode() { - o.vimMode = VIM_INSERT + o.vimMode = vim_INSERT } func (o *opVim) ExitVimInsertMode() { - o.vimMode = VIM_NORMAL + o.vimMode = vim_NORMAL } func (o *opVim) HandleVim(r rune, readNext func() rune) rune { - if o.vimMode == VIM_NORMAL { + if o.vimMode == vim_NORMAL { return o.HandleVimNormal(r, readNext) } if r == CharEsc { @@ -154,9 +154,9 @@ func (o *opVim) HandleVim(r rune, readNext func() rune) rune { } switch o.vimMode { - case VIM_INSERT: + case vim_INSERT: return r - case VIM_VISUAL: + case vim_VISUAL: } return r } diff --git a/vendor/modules.txt b/vendor/modules.txt index ae0bcfa..897098d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,7 +6,7 @@ github.com/docopt/docopt-go github.com/ergochat/irc-go/ircfmt github.com/ergochat/irc-go/ircmsg github.com/ergochat/irc-go/ircreader -# github.com/ergochat/readline v0.1.0-rc1 +# github.com/ergochat/readline v0.1.1-rc1 ## explicit; go 1.19 github.com/ergochat/readline github.com/ergochat/readline/internal/ansi From 5fdc45f18badde89c877abf0d94deaa4faef2a9c Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 5 May 2024 04:02:10 -0400 Subject: [PATCH 2/3] fix tag --- go.mod | 2 +- go.sum | 2 ++ vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index d6276c5..abc6088 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 github.com/ergochat/irc-go v0.3.0 - github.com/ergochat/readline v0.1.1-rc1 + github.com/ergochat/readline v0.1.1-rc2 github.com/gorilla/websocket v1.5.0 github.com/jwalton/go-supportscolor v1.1.0 golang.org/x/term v0.6.0 diff --git a/go.sum b/go.sum index 58a26c2..48787cf 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/ergochat/readline v0.1.0-rc1 h1:zY4gDCDMV0LpJW9hU+0aA+vlzVb6MJKPEQLM4 github.com/ergochat/readline v0.1.0-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= github.com/ergochat/readline v0.1.1-rc1 h1:VWYKbzKbRX54feYhcoZIoydRdSwOOUR/UbOGu6wZmMc= github.com/ergochat/readline v0.1.1-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= +github.com/ergochat/readline v0.1.1-rc2 h1:pkvxu+mZ08gN+yWUxRQQzYSO4v5jShzakZ6mKt7R7TA= +github.com/ergochat/readline v0.1.1-rc2/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ= diff --git a/vendor/modules.txt b/vendor/modules.txt index 897098d..5cca372 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,7 +6,7 @@ github.com/docopt/docopt-go github.com/ergochat/irc-go/ircfmt github.com/ergochat/irc-go/ircmsg github.com/ergochat/irc-go/ircreader -# github.com/ergochat/readline v0.1.1-rc1 +# github.com/ergochat/readline v0.1.1-rc2 ## explicit; go 1.19 github.com/ergochat/readline github.com/ergochat/readline/internal/ansi From b4a9022ddda96de732c196f2490bb41c979728b1 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 6 May 2024 01:11:47 -0400 Subject: [PATCH 3/3] update to production release --- go.mod | 2 +- go.sum | 8 ++------ vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index abc6088..40b13ae 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 github.com/ergochat/irc-go v0.3.0 - github.com/ergochat/readline v0.1.1-rc2 + github.com/ergochat/readline v0.1.1 github.com/gorilla/websocket v1.5.0 github.com/jwalton/go-supportscolor v1.1.0 golang.org/x/term v0.6.0 diff --git a/go.sum b/go.sum index 48787cf..95b40e0 100644 --- a/go.sum +++ b/go.sum @@ -2,12 +2,8 @@ github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 h1:rHnpq7uNlix5l7 github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/ergochat/irc-go v0.3.0 h1:qgvb2knh8d6yIVsHX+PRQ2CiRj1NGG5x88ABmR1lWng= github.com/ergochat/irc-go v0.3.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0= -github.com/ergochat/readline v0.1.0-rc1 h1:zY4gDCDMV0LpJW9hU+0aA+vlzVb6MJKPEQLM4b8p/h4= -github.com/ergochat/readline v0.1.0-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= -github.com/ergochat/readline v0.1.1-rc1 h1:VWYKbzKbRX54feYhcoZIoydRdSwOOUR/UbOGu6wZmMc= -github.com/ergochat/readline v0.1.1-rc1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= -github.com/ergochat/readline v0.1.1-rc2 h1:pkvxu+mZ08gN+yWUxRQQzYSO4v5jShzakZ6mKt7R7TA= -github.com/ergochat/readline v0.1.1-rc2/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= +github.com/ergochat/readline v0.1.1 h1:C8Uuo3ybB23GWOt0uxmHbGzKM9owmtXary6Clrj84s0= +github.com/ergochat/readline v0.1.1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ= diff --git a/vendor/modules.txt b/vendor/modules.txt index 5cca372..b2c40ce 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -6,7 +6,7 @@ github.com/docopt/docopt-go github.com/ergochat/irc-go/ircfmt github.com/ergochat/irc-go/ircmsg github.com/ergochat/irc-go/ircreader -# github.com/ergochat/readline v0.1.1-rc2 +# github.com/ergochat/readline v0.1.1 ## explicit; go 1.19 github.com/ergochat/readline github.com/ergochat/readline/internal/ansi