Repository navigation
feat!: make Area race-free and accept any io.Writer - #26
Draft
MarvinJWendt wants to merge 2 commits into
Draft
MarvinJWendt wants to merge 2 commits into
MarvinJWendt wants to merge 2 commits into
Conversation
Area and Cursor are now safe for concurrent use. Every Area method locks a mutex, and the package level helpers guard their height tracking. An Area now owns its cursor, so Area.WithWriter no longer redirects the global cursor. Cursor, Area and SetTarget accept any io.Writer. They write ANSI escape sequences everywhere and only fall back to the Windows console API for legacy consoles that cannot enable virtual terminal processing. The Windows code uses golang.org/x/sys/windows. Also fix Area.Down clamping, the Windows newline conversion that doubled "\r", and cursor_test_linux.go, which was compiled into the library on Linux because of its name. Tests no longer share global state in parallel. BREAKING CHANGE: requires Go 1.27. SetTarget, Cursor.WithWriter and Area.WithWriter take an io.Writer instead of a cursor.Writer. 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 #26 +/- ##
==========================================
+ Coverage 5.41% 75.44% +70.03%
==========================================
Files 6 4 -2
Lines 240 167 -73
==========================================
+ Hits 13 126 +113
+ Misses 227 32 -195
- Partials 0 9 +9 ☔ 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: go.mod said
go 1.15. Area and the package-level helpers shared unguarded state, and every Area used the global cursor, soArea.WithWriteralso redirectedcursor.SetTarget's cursor. On Windows, every writer needed a real consoleFd().Area.Downclamped to the wrong value. The Windows newline conversion turned\r\ninto\r\r\n.cursor_test_linux.gowas compiled into the library on Linux because of its file name. The tests ran in parallel while they changed global state.After:
go 1.27.0, with golang.org/x/sys as the only dependency.CursorandAreaare safe for concurrent use, and each Area owns its cursor. Cursor, Area and SetTarget work with anyio.Writer.go vet,go test -race ./...and golangci-lint (Linux, Windows, macOS) pass. pterm's test suite also passes against this branch. There was no committed go.work, so there was nothing to remove.How: Every Area method locks a mutex that NewArea creates. A zero-value Area falls back to a package-level lock. The helpers guard
autoheightwith a mutex. Cursor writes ANSI sequences on every platform. On Windows it uses the console API (through golang.org/x/sys/windows) only when the writer is a console that cannot turn on virtual terminal processing. The tests use in-memory buffers, and new tests cover concurrent use.Breaking changes:
SetTarget,Cursor.WithWriterandArea.WithWritertake anio.Writerinstead of acursor.Writer. Existing callers still compile. Thecursor.Writertype remains.Area.WithWriterreturns an Area with its own cursor and lock, and no longer changes the global cursor.ClearLinenow clears the whole line andClearclears from the cursor to the end of the line, the same as the ANSI behavior.🤖 Generated with Claude Code
https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
Generated by Claude Code