Skip to content

fix: preserve exact-width lines printed above the view - #1888

Merged
andrinoff merged 2 commits into
charmbracelet:mainfrom
imharjot:fix/exact-width-insert-above
Nov 12, 2026
Merged

andrinoff merged 2 commits into
charmbracelet:mainfrom
imharjot:fix/exact-width-insert-above

Conversation

@imharjot

Copy link
Copy Markdown
Contributor

Fixes #1885.

tea.Println reserves an extra row when an inserted line fills exactly two or more terminal rows. It also clears to the right after writing the line, which can erase its last character while the terminal has a wrap pending.

Count the additional rows with (lineWidth - 1) / width, and clear the row before writing its text. This avoids erasing the final cell without keeping a separate array of measured widths. The existing width-measurement method is unchanged, so this can be combined with #1803 or #1861.

The regression covers short lines, exact widths, one cell over, multiple rows, ANSI styling, wide characters, and multiple lines. Six cases fail on main and pass with the fix; the two non-boundary controls pass on both. The terminal reproduction is based on @n-eriksson's example in the issue.

Validation on macOS arm64:

  • go test ./...

  • go test -race -count 4 -cpu 1,4 ./...

  • go build ./... and go vet ./...

  • golangci-lint run with v2.9.0

  • go build ./... and go test ./... in examples

  • go mod tidy in both modules leaves their module files unchanged

  • The issue's program in a 40-column PTY, with lines of 39, 40, 41, 80, and 120 cells, replayed through Charm's x/vt emulator (v0.1.0) and xterm.js. The exact-multiple cases keep the full inserted line and redraw the inline view in place. x/vt reproduces both defects before the fix; xterm.js reproduces the broken view redraw.

  • I have read CONTRIBUTING.md.

  • I have created a discussion that was approved by a maintainer (for new features). Not applicable: this fixes an existing bug.

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.33%. Comparing base (5982a61) to head (2074f7e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1888      +/-   ##
==========================================
+ Coverage   64.05%   64.33%   +0.27%     
==========================================
  Files          26       26              
  Lines        1430     1430              
==========================================
+ Hits          916      920       +4     
+ Misses        416      414       -2     
+ Partials       98       96       -2     

☔ 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.

@andrinoff
andrinoff merged commit bd09ae6 into charmbracelet:main Nov 12, 2026
18 checks passed
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.

v2: tea.Println erases the last character of full-width lines, and miscounts rows at 2× width

2 participants