Skip to content

Fix scrolling issues with escape#496

Merged
bl-ue merged 3 commits intoPiebald-AI:mainfrom
brrock:fix-scroll
Feb 8, 2026
Merged

Fix scrolling issues with escape#496
bl-ue merged 3 commits intoPiebald-AI:mainfrom
brrock:fix-scroll

Conversation

@brrock
Copy link
Copy Markdown
Contributor

@brrock brrock commented Feb 8, 2026

fixes #344

Summary by CodeRabbit

  • New Features

    • Added "Scroll escape sequence filter" — a new configurable toggle (off by default) to remove problematic terminal escape sequences and prevent unwanted scrolling; available in Misc settings and via config.
  • Documentation

    • README and changelog updated with feature description, UI example, and config usage.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Configuration & Types
src/defaultSettings.ts, src/types.ts
Added filterScrollEscapeSequences: boolean to default settings and MiscConfig (default false).
Patch Implementation
src/patches/scrollEscapeSequenceFilter.ts, src/patches/index.ts
New patch writer writeScrollEscapeSequenceFilter implemented and registered as filter-scroll-escape-sequences; patch registered conditionally on the new setting.
UI Integration
src/ui/components/MiscView.tsx
Inserted a boolean toggle in MiscView to control settings.misc.filterScrollEscapeSequences.
Documentation & Changelog
README.md, CHANGELOG.md
Documented the "Scroll escape sequence filter" feature, UI/config examples, and added an Unreleased changelog entry.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Misc fixes #440 — Modifies src/patches/index.ts and patch definitions; likely overlaps with patch registration changes in this PR.

Suggested reviewers

  • bl-ue

Poem

🐰 Hopping through the terminal night,
I nibble escapes that cause a fright,
I tuck the scrolls and calm the screen,
A tidy console, neat and clean. 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix scrolling issues with escape' is vague and incomplete; it mentions 'escape' without context, making it unclear that the fix addresses escape sequence filtering to prevent unwanted terminal scrolling. Consider a more descriptive title like 'Add scroll escape sequence filter to prevent unwanted console scrolling' to clearly communicate the change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR addresses the core objective of issue #344 by implementing a filter mechanism to prevent unwanted console scrolling caused by problematic ANSI escape sequences.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the scroll escape sequence filter feature; no unrelated modifications are present in the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@brrock brrock marked this pull request as ready for review February 8, 2026 08:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bl-ue
Copy link
Copy Markdown
Member

bl-ue commented Feb 8, 2026

@brrock This is very cool!  Were you able to actually test that it works?

@brrock
Copy link
Copy Markdown
Contributor Author

brrock commented Feb 8, 2026

Yep I pasted some large text

@brrock
Copy link
Copy Markdown
Contributor Author

brrock commented Feb 8, 2026

@bl-ue

@bl-ue
Copy link
Copy Markdown
Member

bl-ue commented Feb 8, 2026

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?

@brrock
Copy link
Copy Markdown
Contributor Author

brrock commented Feb 8, 2026

Yes just one issue, I'm happy to fix the rest tho

@brrock
Copy link
Copy Markdown
Contributor Author

brrock commented Feb 8, 2026

@bl-ue

@bl-ue bl-ue merged commit 4b391e3 into Piebald-AI:main Feb 8, 2026
2 checks passed
@bl-ue
Copy link
Copy Markdown
Member

bl-ue commented Feb 8, 2026

Yes just one issue, I'm happy to fix the rest tho

That would definitely be incredible. But please don't feel obligated!

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.

[feat request] Unwanted console scrolling prevention

2 participants