Skip to content

fix(cli): restore mouse wheel scrolling for TUI#2341

Open
Sskift wants to merge 2 commits into
esengine:v1from
Sskift:fix/cli-scroll-wheel
Open

fix(cli): restore mouse wheel scrolling for TUI#2341
Sskift wants to merge 2 commits into
esengine:v1from
Sskift:fix/cli-scroll-wheel

Conversation

@Sskift
Copy link
Copy Markdown

@Sskift Sskift commented May 30, 2026

Summary

Fixes the scroll wheel portion of #2260 — mouse wheel not working in the CLI TUI after model finishes answering.

Root cause

src/cli/ui/history-scroll-mode.ts defaulted to "native" for most terminals when historyScrollMode was "auto". In "native" mode, mouse-mode.ts sends RESET_ALL (disabling all mouse tracking), relying on the terminal native scrollback. But in the TUI alt-screen buffer, there is nothing "above" the screen for native scrollback to scroll — wheel events produce no movement.

Changes

1. src/cli/ui/history-scroll-mode.ts — default to app-managed scroll

  • Changed the default return from "native" to "app" so CardStream captures wheel events
  • Added explicit Apple Terminal exception (native renderer crashes on mouse-mode toggles)
  • Classic Windows console (conhost, no TERM_PROGRAM) stays on "native" — it does not forward wheel events to the alt-screen

2. src/cli/commands/chat.tsx — honor opt-out flags

  • --no-mouse and mouseTracking: false now force "native" as a hard override before the resolver runs

3. src/cli/ui/stdin-reader.ts — decode modified SGR wheel codes

  • Changed from exact match btn === 64 / btn === 65 to bit masking btn & 64 with btn & 1 for direction
  • This catches modified codes (68 = wheel-up+Ctrl, 69 = wheel-down+Ctrl, 80 = wheel-up+Shift) that some terminals emit

Verification

  • npm run typecheck
  • npm run lint

Default historyScrollMode from 'native' to 'app' so CardStream
captures wheel events in alt-screen terminals where native
scrollback cannot scroll TUI content.

- Apple Terminal and classic Windows console (conhost) stay on
  'native' to avoid renderer crashes / missing wheel forwarding.
- --no-mouse / mouseTracking:false now force 'native' as a hard
  override before the resolver runs.
- Decode modified SGR wheel button codes (68/69/80 etc.) that
  some terminals (Windows Terminal previews) send with modifier
  bits set — the old exact-match on 64/65 silently dropped them.

Fixes esengine#2260 (scroll wheel portion)
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 315d9a46f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Default to app-managed scroll for all other terminals so the mouse
// wheel feeds into CardStream's scroll logic. Native scrollback
// cannot scroll TUI alt-screen content on most terminals.
return "app";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update stale auto-mode test expectation

Changing the auto-mode fall-through to "app" leaves tests/chat-scroll-wheel.test.ts:97-104 asserting that an unknown xterm/linux environment still resolves to "native"; any CI path that runs npm test/npm run verify will fail on that assertion even though this is now the intended default. Please update the test to match the new default or keep the old behavior for that environment.

Useful? React with 👍 / 👎.

The auto-mode fall-through now returns 'app' instead of 'native',
so the test for unknown terminals must expect 'app'.

Added two new test cases:
- Apple Terminal stays on 'native' (renderer crash avoidance)
- Classic Windows console (no TERM_PROGRAM) stays on 'native'
@Sskift
Copy link
Copy Markdown
Author

Sskift commented May 30, 2026

@chatgpt-codex-connector good catch — pushed b9b9df67 which updates tests/chat-scroll-wheel.test.ts:

  • Changed the unknown-terminal expectation from "native" to "app"
  • Added two new test cases: Apple Terminal → "native", classic Windows console → `"native"

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@esengine esengine added the v1 Legacy TypeScript line (0.x) — v1 branch, maintenance only label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Legacy TypeScript line (0.x) — v1 branch, maintenance only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants