Skip to content

feat!: make Area race-free and accept any io.Writer - #26

Draft
MarvinJWendt wants to merge 2 commits into
mainfrom
feat/new-pterm
Draft

MarvinJWendt wants to merge 2 commits into
mainfrom
feat/new-pterm

Conversation

@MarvinJWendt

Copy link
Copy Markdown
Member

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, so Area.WithWriter also redirected cursor.SetTarget's cursor. On Windows, every writer needed a real console Fd(). Area.Down clamped to the wrong value. The Windows newline conversion turned \r\n into \r\r\n. cursor_test_linux.go was 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. Cursor and Area are safe for concurrent use, and each Area owns its cursor. Cursor, Area and SetTarget work with any io.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 autoheight with 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:

  • Requires Go 1.27.
  • SetTarget, Cursor.WithWriter and Area.WithWriter take an io.Writer instead of a cursor.Writer. Existing callers still compile. The cursor.Writer type remains.
  • Area.WithWriter returns an Area with its own cursor and lock, and no longer changes the global cursor.
  • On legacy Windows consoles, ClearLine now clears the whole line and Clear clears 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

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
@MarvinJWendt MarvinJWendt self-assigned this Oct 10, 2026
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.20661% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.44%. Comparing base (93d4a5c) to head (d3d20f3).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
cursor.go 52.00% 3 Missing and 9 partials ⚠️
area.go 83.82% 11 Missing ⚠️
console_other.go 28.57% 5 Missing ⚠️
utils.go 90.47% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants