Registry Mirror
Skip to content

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #172

What changed

  • TUI/Services/SpectreConsoleProvider.cs: ClipToScreen used to clip with text.Length/Substring. It now walks text elements (StringInfo.GetTextElementEnumerator) and measures each one in cells (Spectre's GetCellWidth, which TextElement.MeasureCells/TakeCells also use):
    1. Elements left of column 0 are dropped. That includes a wide glyph that straddles column 0, and the write then starts at the column after it.
    2. Elements are taken while they still fit before Width. A wide glyph that would only half fit at the right edge is dropped.
    3. The cut always falls between text elements, so a surrogate pair is never split.

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 a StringWriter:

  • WriteAt("日本語", (6,0)) emits ESC[1;7H日本, where it used to emit all three glyphs and wrap. This is the issue's first repro.
  • WriteAt("a😀", (8,0)) emits ESC[1;9Ha, where it used to emit a\uD83D. This is the issue's second repro.
  • A wide glyph straddling the right edge is dropped. An emoji that fits exactly is kept whole.
  • Left-edge clipping by cells at x = -1, -2 and -3. An emoji straddling column 0 isn't split.

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 main on 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

… [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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit db76e40 into main Nov 13, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/172-clip-to-screen-cells branch November 13, 2026 21:44
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.

SpectreConsoleProvider.WriteAt lets wide text wrap past the right screen edge and can emit half an emoji, because ClipToScreen counts chars

2 participants