Set the pending-wrap flag only at the phantom column - #115
Merged
Merged
Conversation
SetCursorRaw set PendingWrap = true on EVERY raw advance -- after every printed character -- documented as harmless because "only the boundary column reads it". tomlm#93 quietly broke that contract by adding two readers that consult the flag anywhere: SettleForEditing (ICH/DCH/ECH) and the CUB phantom-column adjustment. From then on, any CUB or DCH issued immediately after printing acted one column LEFT of the cursor. On screen that was the asciiquarium bug: duplicated fragments trailing left-moving sprites (CUB off by one leaves the old cells unerased) and characters eaten from right-moving ones (DCH deletes one cell early). It looked rate- and machine-dependent, but it never was -- it needed a print immediately followed by a relative-back or edit in the stream, which curses emits as a cursor-motion optimisation, so it tracked what the animation happened to draw. A 16-byte repro settles it: ESC[5;1H AB ESC[1P eats the B. The fix makes the flag state a fact instead of trusting its readers: PendingWrap = x > _scrollRight, true exactly at the one-past-the-margin position only a fill can produce. DECRC's explicit restore still runs through SetPendingWrap afterwards, so the saved ambiguity survives. Tests: the three repros (DCH after print, CUB after print, a stale flag carried across a cursor address), plus two guards proving the fix does not regress what the flag is FOR -- autowrap at the last column, and SettleForEditing's fill-then-insert case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tomlm
approved these changes
Aug 30, 2026
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 the asciiquarium rendering corruption: duplicated fragments trailing left-moving sprites, missing characters on right-moving ones.
Root cause
SetCursorRawsetPendingWrap = trueon every raw advance — after every printed character — documented as harmless because "only the boundary column reads it." #93 broke that contract by adding two readers that consult the flag anywhere:SettleForEditing(ICH/DCH/ECH) and the CUB phantom-column adjustment. From then on, any CUB or DCH issued immediately after printing acted one column left of the cursor.It looked rate- and machine-dependent, but never was: it needs a print immediately followed by a relative-back or edit in the stream, which curses emits as a cursor-motion optimisation — so it tracked what the animation happened to draw. A 16-byte repro settles it:
Fix
The flag now states a fact instead of trusting its readers:
PendingWrap = x > _scrollRight, true exactly at the one-past-the-margin position only a fill can produce. DECRC's explicit restore still runs throughSetPendingWrapafterwards, so the saved ambiguity survives.Verification
Co-Authored-By: Claude Fable 5 noreply@anthropic.com