From 50e93666e7fad551ddc3da9f53a255ddb52daef0 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 14 Jul 2024 00:17:08 -0400 Subject: [PATCH 1/2] upgrade readline --- go.mod | 2 +- go.sum | 4 +- .../github.com/ergochat/readline/operation.go | 2 +- .../github.com/ergochat/readline/terminal.go | 69 +++++++++++++++++-- vendor/modules.txt | 2 +- 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 40b13ae..c236d7b 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 + github.com/ergochat/readline v0.1.2 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 95b40e0..9cb80bc 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +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.1 h1:C8Uuo3ybB23GWOt0uxmHbGzKM9owmtXary6Clrj84s0= -github.com/ergochat/readline v0.1.1/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= +github.com/ergochat/readline v0.1.2 h1:zxiwQB8DyTLD0HSWthJlnvs5E2X1qnyXZ44RFf1jRlg= +github.com/ergochat/readline v0.1.2/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/operation.go b/vendor/github.com/ergochat/readline/operation.go index 5d48c2d..46460df 100644 --- a/vendor/github.com/ergochat/readline/operation.go +++ b/vendor/github.com/ergochat/readline/operation.go @@ -100,7 +100,7 @@ func (o *operation) readline(deadline chan struct{}) ([]rune, error) { keepInCompleteMode := false r, err := o.t.GetRune(deadline) - if cfg := o.GetConfig(); cfg.FuncFilterInputRune != nil && err != nil { + if cfg := o.GetConfig(); cfg.FuncFilterInputRune != nil && err == nil { var process bool r, process = cfg.FuncFilterInputRune(r) if !process { diff --git a/vendor/github.com/ergochat/readline/terminal.go b/vendor/github.com/ergochat/readline/terminal.go index e7dd42d..5ba31ea 100644 --- a/vendor/github.com/ergochat/readline/terminal.go +++ b/vendor/github.com/ergochat/readline/terminal.go @@ -312,12 +312,29 @@ func (t *terminal) ioloop() { 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() - if err != nil || !(initial == '[' || initial == 'O') { + if err != nil { return } + // we already read one \x1b. this can indicate either the start of an ANSI + // escape sequence, or a keychord with Alt (e.g. Alt+f produces `\x1bf` in + // a typical xterm). + switch initial { + case 'f': + // Alt-f in xterm, or Option+RightArrow in iTerm2 with "Natural text editing" + return readResult{r: MetaForward, ok: true}, nil // Alt-f + case 'b': + // Alt-b in xterm, or Option+LeftArrow in iTerm2 with "Natural text editing" + return readResult{r: MetaBackward, ok: true}, nil // Alt-b + case '[', 'O': + // this is a real ANSI escape sequence, read the rest of the sequence below: + case '\x1b': + // Alt plus a real ANSI escape sequence. Handle this specially since + // right now the only cases we want to handle are the arrow keys: + return consumeAltSequence(buf) + default: + return // invalid, ignore + } // data consists of ; and 0-9 , anything else terminates the sequence var type_ rune @@ -345,9 +362,17 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader, ansiBuf *bytes.Buffer) ( } } case 'D': - r = CharBackward + if altModifierEnabled(ansiBuf.Bytes()) { + r = MetaBackward + } else { + r = CharBackward + } case 'C': - r = CharForward + if altModifierEnabled(ansiBuf.Bytes()) { + r = MetaForward + } else { + r = CharForward + } case 'A': r = CharPrev case 'B': @@ -379,6 +404,40 @@ func (t *terminal) consumeANSIEscape(buf *bufio.Reader, ansiBuf *bytes.Buffer) ( return // default: no interpretable rune value } +func consumeAltSequence(buf *bufio.Reader) (result readResult, err error) { + initial, _, err := buf.ReadRune() + if err != nil { + return + } + if initial != '[' { + return + } + second, _, err := buf.ReadRune() + if err != nil { + return + } + switch second { + case 'D': + return readResult{r: MetaBackward, ok: true}, nil + case 'C': + return readResult{r: MetaForward, ok: true}, nil + default: + return + } +} + +func altModifierEnabled(payload []byte) bool { + // https://www.xfree86.org/current/ctlseqs.html ; modifier keycodes + // go after the semicolon, e.g. Alt-LeftArrow is `\x1b[1;3D` in VTE + // terminals, where 3 indicates Alt + if semicolonIdx := bytes.IndexByte(payload, ';'); semicolonIdx != -1 { + if string(payload[semicolonIdx+1:]) == "3" { + return true + } + } + return false +} + func parseCPRResponse(payload []byte) (cursorPosition, error) { if semicolonIdx := bytes.IndexByte(payload, ';'); semicolonIdx != -1 { if row, err := strconv.Atoi(string(payload[:semicolonIdx])); err == nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index b2c40ce..70619c2 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 +# github.com/ergochat/readline v0.1.2 ## explicit; go 1.19 github.com/ergochat/readline github.com/ergochat/readline/internal/ansi From 67b16468875a439de1d22d7c33f4e4a6dd287578 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 14 Jul 2024 00:39:23 -0400 Subject: [PATCH 2/2] upgrade goreleaser --- .goreleaser.yml | 10 ++++++---- Makefile | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index b60db1a..f1b0cf0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,6 @@ # .goreleaser.yml # Build customization +version: 2 project_name: ircdog builds: - main: ircdog.go @@ -31,11 +32,12 @@ builds: archives: - - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + name_template: >- + {{ .ProjectName }}-{{ .Version }}- + {{- if eq .Os "darwin" }}macos{{- else }}{{ .Os }}{{ end -}}- + {{- if eq .Arch "amd64" }}x86_64{{- else }}{{ .Arch }}{{ end -}} + {{ if .Arm }}v{{ .Arm }}{{ end -}} format: tar.gz - replacements: - amd64: x86_64 - darwin: macos format_overrides: - goos: windows format: zip diff --git a/Makefile b/Makefile index 3b75d0a..e3df971 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ install: go install -v -ldflags "-X main.commit=$(GIT_COMMIT) -X main.version=$(GIT_TAG)" release: - goreleaser --skip-publish --clean + goreleaser --skip=publish --clean test: go test ./...