feat(tui-rs): add support for mousewheel scrolling (#641)

It is intuitive to try to scroll the conversation history using the
mouse in the TUI, but prior to this change, we only supported scrolling
via keyboard events.

This PR enables mouse capture upon initialization (and disables it on
exit) such that we get `ScrollUp` and `ScrollDown` events in
`codex-rs/tui/src/app.rs`. I initially mapped each event to scrolling by
one line, but that felt sluggish. I decided to introduce
`ScrollEventHelper` so we could debounce scroll events and measure the
number of scroll events in a 100ms window to determine the "magnitude"
of the scroll event. I put in a basic heuristic to start, but perhaps
someone more motivated can play with it over time.

`ScrollEventHelper` takes care of handling the atomic fields and thread
management to ensure an `AppEvent::Scroll` event is pumped back through
the event loop at the appropriate time with the accumulated delta.
This commit is contained in:
Michael Bolin
2025-04-25 12:01:52 -07:00
committed by GitHub
parent d7a40195e6
commit dc7b83666a
7 changed files with 157 additions and 14 deletions

View File

@@ -3,8 +3,15 @@ use crossterm::event::KeyEvent;
pub(crate) enum AppEvent {
CodexEvent(Event),
Redraw,
KeyEvent(KeyEvent),
/// Scroll event with a value representing the "scroll delta" as the net
/// scroll up/down events within a short time window.
Scroll(i32),
/// Request to exit the application gracefully.
ExitRequest,