Fix scrolling issues with escape#496
Conversation
📝 WalkthroughWalkthroughAdds a configurable filter to strip terminal escape sequences that cause unwanted console scrolling; includes a new patch implementation, settings/type additions, UI toggle, and documentation/changelog updates. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/patches/scrollEscapeSequenceFilter.ts`:
- Around line 3-25: getScrollEscapeSequenceFilterLocation always returns a
number (0 or positive) so change its signature to return number (remove | null)
and update any caller that does an unnecessary null-check (e.g. the "index ===
null" check) to treat 0 as the valid injection point; alternatively, if you
prefer an explicit failure path, modify getScrollEscapeSequenceFilterLocation to
return null when no injection point is found (use -1 or a boolean flag to detect
failure) and keep callers expecting number | null—pick one approach and make the
return type and all callers (including the check against "index === null")
consistent with that choice.
- Around line 38-56: The injected stdout filter overrides process.stdout.write
(see _origStdoutWrite and the replacement function) but uses invalid/duplicate
ANSI patterns, duplicates escape forms, and coerces Buffers to strings; fix it
by only transforming when typeof chunk === 'string' (pass Buffers through
unchanged), remove redundant .replace calls for \x1b/\033/\u001b, and replace
the fragile patterns with proper CSI regexes such as /\x1b\[(?:\d+;?\d*)?H/g to
catch cursor-home variants (e.g. \x1b[H and \x1b[1;1H) and /\x1b\[\d*A/g to
catch cursor-up sequences (e.g. \x1b[A, \x1b[3A), then call _origStdoutWrite
with the original argument types and same encoding/cb parameters to preserve
binary and multi-byte correctness.
|
@brrock This is very cool! Were you able to actually test that it works? |
|
Yep I pasted some large text |
|
Okay, so I was confused about something. You're specifically fixing anthropics/claude-code#826, where the terminal scrolls around to different points when there's a very long session, but not the well known flickering issue like anthropics/claude-code#769 and anthropics/claude-code#1913, right? |
|
Yes just one issue, I'm happy to fix the rest tho |
That would definitely be incredible. But please don't feel obligated! |
fixes #344
Summary by CodeRabbit
New Features
Documentation