Repository navigation
feat!: replace containerd/console with x/term and harden Listen - #17
Draft
MarvinJWendt wants to merge 2 commits into
Draft
MarvinJWendt wants to merge 2 commits into
MarvinJWendt wants to merge 2 commits into
Conversation
Switch raw mode handling to golang.org/x/term and golang.org/x/sys on Unix and Windows, and drop the testza test dependency. The module graph now only contains golang.org/x/sys and golang.org/x/term. Listen now always restores the terminal, also when the callback returns an error or panics, can be called repeatedly, and returns ErrAlreadyListening for overlapping calls. Terminal reads can be canceled, so no reader goroutine outlives Listen. Escape sequences and control keys that arrive in one read are split into separate keys. ListenReader reads key presses from any io.Reader, for tests and non-interactive input. SimulateKeyPress now sends every argument instead of only the first one. BREAKING CHANGE: requires Go 1.27. Listen returns ErrAlreadyListening when called while another Listen is running. SimulateKeyPress returns an error for unsupported input types. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
===========================================
+ Coverage 42.10% 81.56% +39.46%
===========================================
Files 5 4 -1
Lines 171 217 +46
===========================================
+ Hits 72 177 +105
+ Misses 92 40 -52
+ Partials 7 0 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The v2.11.4 release binary is built with Go 1.26 and refuses to lint a module that targets Go 1.27. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Marvin · project thread
Before: The tests used testza, which pulled an old pterm, gookit/color and xo/terminfo into the module graph. Raw mode went through containerd/console. If the callback returned an error, Listen returned without restoring the terminal, and a panic left it in raw mode. Read errors were turned into empty keys, which could make Listen spin. SimulateKeyPress only sent its first argument.
After: The module only depends on golang.org/x/sys and golang.org/x/term (
go 1.27.0). Listen always restores the terminal, including on callback errors and panics. It can be called any number of times in a row, and Ctrl+C still arrives askeys.CtrlC. The newListenReader(r io.Reader, cb)reads key presses from any reader, for tests and non-tty input.go test -race ./...and golangci-lint (Linux, Windows, macOS) pass. pterm's test suite also passes against this branch.How: Raw mode uses
term.MakeRaw/term.Restore. On Unix, reads wait inselect(2)on the tty and a wake-up pipe, so Listen can cancel the reader and join it before returning.selectis used becausepolldoes not support ttys on macOS. On Windows the reader opensCONIN$and is canceled withCancelIoEx. A new parser splits escape sequences and control keys that arrive in one read. Typed or pasted printable text is still grouped into one RuneKey. The tests use only the standard library. They use a fake terminal, plus a Linux pty test that checks raw mode, Ctrl+C delivery, cancellation and restore.Breaking changes:
Listenreturns the newErrAlreadyListeningwhen it is called while anotherListenis still running (for example, from inside the callback).SimulateKeyPressnow sends every argument instead of only the first one, and returns an error for unsupported input types.Listeninstead of being delivered as empty keys. Invalid UTF-8 input is skipped instead of endingListenwith an error.🤖 Generated with Claude Code
https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
Generated by Claude Code