Repository navigation
Expand tabs and replace control characters before measuring and drawing text [patch] - #202
Merged
Merged
Conversation
…ing and drawing [patch] A tab was measured as one cell but jumped the terminal cursor to the next tab stop, so "Name\tValue" overwrote its border. An escape or other C0/C1 character reached the terminal raw, so text could clear the screen or move the cursor mid-frame. TextElement now expands tabs to the next 8-cell tab stop of each line and draws every other control character as U+FFFD, in SplitIntoLines so measuring and drawing agree. SpectreConsoleProvider.WriteAt replaces any control character that still reaches it, as defence in depth. Fixes #159 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
…f their files Keeps this change clear of the lines #204 edits, so the two merge in either order without a conflict. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
|
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 #159
What was wrong
Measuring, clipping and drawing all treated a tab as a one-cell character, but the terminal moves the cursor to the next tab stop. So
"Name\tValue"in a border was measured narrower than it drew, and it overwrote the right border. Escape and other C0/C1 characters also went straight to the terminal, so any displayed text could clear the screen or move the cursor mid-frame.Change
TextElement.NormalizeControlCharactersruns on every line inSplitIntoLines, so measuring and drawing see the same text:TabWidth(8) stop, counted from the start of its lineControlCharacterPlaceholder(U+FFFD), which takes one cellSpectreConsoleProvider.WriteAtreplaces any control character that still reaches it, such as text written to the provider directly.Tests
TabInABorderMeasuresToTheWidthItDraws:"Name\tValue"measures 15×3 in a border, draws asName Value, and stops before the border.TabsExpandToTheNextTabStopOnEachLine: tab stops are counted per line.ControlCharactersAreDrawnAsAPlaceholder: ESC, BEL, CSI (U+009B) and DEL are drawn as U+FFFD and measured to match.TextElementWritesNoControlCharactersToTheTerminalandWriteAtReplacesControlCharacters: the captured ANSI output contains no ESC except the provider's own cursor moves.With the fix reverted, all 8 new cases fail. With it applied, the full suite passes (261/261).
🤖 Generated with Claude Code
https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
Generated by Claude Code