Conversation
… [patch] SpectreConsoleProvider.ClipToScreen clipped by string length, so CJK text near the right edge wrapped onto the next row, and an emoji cut at either edge left a lone surrogate. Walk text elements and measure each in terminal cells instead; a wide glyph straddling an edge is dropped whole. Fixes #172 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2kkxDaFKYetxhPcC9
|
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.



Fixes #172
What changed
TUI/Services/SpectreConsoleProvider.cs:ClipToScreenused to clip withtext.Length/Substring. It now walks text elements (StringInfo.GetTextElementEnumerator) and measures each one in cells (Spectre'sGetCellWidth, whichTextElement.MeasureCells/TakeCellsalso use):Width. A wide glyph that would only half fit at the right edge is dropped.ASCII behaviour is unchanged (the existing #139 clip tests still pass).
Tests
New cases in
TUI.Test/SpectreConsoleProviderTests.cs, which use a 10×5 Spectre console over aStringWriter:WriteAt("日本語", (6,0))emitsESC[1;7H日本, where it used to emit all three glyphs and wrap. This is the issue's first repro.WriteAt("a😀", (8,0))emitsESC[1;9Ha, where it used to emita\uD83D. This is the issue's second repro.With the provider change reverted, 7 of the 8 new tests fail. The emoji-that-fits case passes either way and is there as a regression guard. With the change, all pass. Full suite (
dotnet test): 356/356 pass, and the Release build has no new warnings.This branch starts from
mainon its own. It's independent of #262 (#171, the border title), which fixes the element side of the same char-versus-cell problem.Generated by Claude Code