Skip to content

tui: implement mouse support#279

Open
kxxt wants to merge 2 commits into
mainfrom
mouse-support
Open

tui: implement mouse support#279
kxxt wants to merge 2 commits into
mainfrom
mouse-support

Conversation

@kxxt

@kxxt kxxt commented Jun 27, 2026

Copy link
Copy Markdown
Owner

No description provided.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tracexec Ready Ready Preview, Comment Jun 27, 2026 2:45am

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kxxt, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 2 minutes and 45 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 79294140-fa2c-4512-a584-2f5a07207dfa

📥 Commits

Reviewing files that changed from the base of the PR and between 75e39ee and 2b4e077.

⛔ Files ignored due to path filters (6)
  • crates/tracexec-tui/src/snapshots/tracexec_tui__app__tests__snapshot_app_render.snap is excluded by !**/*.snap
  • crates/tracexec-tui/src/snapshots/tracexec_tui__app__tests__snapshot_app_render_with_custom_theme.snap is excluded by !**/*.snap
  • crates/tracexec-tui/src/snapshots/tracexec_tui__help__tests__snapshot_help_popup.snap is excluded by !**/*.snap
  • crates/tracexec-tui/src/snapshots/tracexec_tui__hit_manager__tests__snapshot_hit_manager_editing_default_command.snap is excluded by !**/*.snap
  • crates/tracexec-tui/src/snapshots/tracexec_tui__hit_manager__tests__snapshot_hit_manager_no_default_command.snap is excluded by !**/*.snap
  • crates/tracexec-tui/src/snapshots/tracexec_tui__hit_manager__tests__snapshot_hit_manager_with_hits_and_default_command.snap is excluded by !**/*.snap
📒 Files selected for processing (26)
  • config.toml
  • crates/tracexec-core/src/cli/args.rs
  • crates/tracexec-core/src/cli/config.rs
  • crates/tracexec-core/src/cli/keys.rs
  • crates/tracexec-core/src/cli/tui_theme.rs
  • crates/tracexec-core/src/event.rs
  • crates/tracexec-tui/src/action.rs
  • crates/tracexec-tui/src/app.rs
  • crates/tracexec-tui/src/app/ui.rs
  • crates/tracexec-tui/src/breakpoint_manager.rs
  • crates/tracexec-tui/src/copy_popup.rs
  • crates/tracexec-tui/src/details_popup.rs
  • crates/tracexec-tui/src/event_list/scroll.rs
  • crates/tracexec-tui/src/event_list/ui.rs
  • crates/tracexec-tui/src/help.rs
  • crates/tracexec-tui/src/hit_manager.rs
  • crates/tracexec-tui/src/lib.rs
  • crates/tracexec-tui/src/mouse.rs
  • crates/tracexec-tui/src/pseudo_term.rs
  • crates/tracexec-tui/src/query.rs
  • crates/tracexec-tui/src/theme.rs
  • src/bpf.rs
  • src/main.rs
  • themes/amber.toml
  • themes/high-contrast.toml
  • themes/nord.toml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mouse-support

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive mouse support to the TUI, enabling mouse-based pane switching, event list scrolling and double-clicking, popup navigation, and interactive pane divider dragging. Key feedback focuses on robust mouse event handling: first, converting mouse coordinate encoding in pseudo_term.rs to return raw bytes (Vec<u8>) instead of String to prevent UTF-8 multi-byte corruption of traditional X10 escape sequences; second, utilizing non-blocking try_send instead of await when forwarding mouse events to the PTY to prevent UI freezes under rapid mouse movement; and third, restricting divider dragging to left-click drag events to avoid unexpected jumps if a mouse release event is missed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +506 to 545
fn encode_default_mouse(event: &MouseEvent, col: u16, row: u16) -> Option<String> {
// Traditional encoding: ESC [ M Cb Cx Cy
// Cb = button + 32, Cx = col + 33, Cy = row + 33
// Coordinates are limited to 222 (255 - 33)
if col > 222 || row > 222 {
return None;
}

let button: u8 = match event.kind {
MouseEventKind::Down(MouseButton::Left) => 0,
MouseEventKind::Down(MouseButton::Middle) => 1,
MouseEventKind::Down(MouseButton::Right) => 2,
MouseEventKind::Up(_) => 3, // Release is encoded as button 3
MouseEventKind::Drag(MouseButton::Left) => 32,
MouseEventKind::Drag(MouseButton::Middle) => 33,
MouseEventKind::Drag(MouseButton::Right) => 34,
MouseEventKind::ScrollUp => 64,
MouseEventKind::ScrollDown => 65,
MouseEventKind::ScrollLeft => 66,
MouseEventKind::ScrollRight => 67,
MouseEventKind::Moved => 35,
};

let mut button = button;
if event.modifiers.contains(KeyModifiers::SHIFT) {
button += 4;
}
if event.modifiers.contains(KeyModifiers::ALT) {
button += 8;
}
if event.modifiers.contains(KeyModifiers::CONTROL) {
button += 16;
}

let cb = (button + 32) as char;
let cx = (col as u8 + 33) as char;
let cy = (row as u8 + 33) as char;
Some(format!("\x1b[M{cb}{cx}{cy}"))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

In encode_default_mouse, coordinates col and row are converted to char after adding 33. If col or row is greater than 94, the resulting value (col + 33) will be greater than 127. In Rust, formatting a char with a value greater than 127 into a String encodes it as a multi-byte UTF-8 sequence. However, the traditional X10 mouse protocol expects raw single-byte coordinates. This UTF-8 encoding will corrupt the escape sequence and cause the terminal to misinterpret the mouse position.\n\nTo fix this, both encode_default_mouse and encode_sgr_mouse should return Option<Vec<u8>> instead of Option<String>, allowing raw bytes to be sent directly.

fn encode_default_mouse(event: &MouseEvent, col: u16, row: u16) -> Option<Vec<u8>> {
  if col > 222 || row > 222 {
    return None;
  }

  let button: u8 = match event.kind {
    MouseEventKind::Down(MouseButton::Left) => 0,
    MouseEventKind::Down(MouseButton::Middle) => 1,
    MouseEventKind::Down(MouseButton::Right) => 2,
    MouseEventKind::Up(_) => 3,
    MouseEventKind::Drag(MouseButton::Left) => 32,
    MouseEventKind::Drag(MouseButton::Middle) => 33,
    MouseEventKind::Drag(MouseButton::Right) => 34,
    MouseEventKind::ScrollUp => 64,
    MouseEventKind::ScrollDown => 65,
    MouseEventKind::ScrollLeft => 66,
    MouseEventKind::ScrollRight => 67,
    MouseEventKind::Moved => 35,
  };

  let mut button = button;
  if event.modifiers.contains(KeyModifiers::SHIFT) {
    button += 4;
  }
  if event.modifiers.contains(KeyModifiers::ALT) {
    button += 8;
  }
  if event.modifiers.contains(KeyModifiers::CONTROL) {
    button += 16;
  }

  let cb = button + 32;
  let cx = col as u8 + 33;
  let cy = row as u8 + 33;
  Some(vec![b'\\x1b', b'[', b'M', cb, cx, cy])
}

Comment on lines +384 to +455
pub async fn handle_mouse_event(&self, event: &MouseEvent, col: u16, row: u16) {
let (mode, encoding) = {
let parser = self.parser.read().unwrap();
let screen = parser.screen();
(
screen.mouse_protocol_mode(),
screen.mouse_protocol_encoding(),
)
};

// Only forward mouse events if the program running in the terminal
// has enabled mouse reporting (e.g. via DECSET 1000/1002/1003).
if mode == vt100::MouseProtocolMode::None {
return;
}

// Filter events based on the protocol mode
let dominated = match mode {
vt100::MouseProtocolMode::None => unreachable!(),
// X10: only button press
vt100::MouseProtocolMode::Press => matches!(
event.kind,
MouseEventKind::Down(_)
| MouseEventKind::ScrollUp
| MouseEventKind::ScrollDown
| MouseEventKind::ScrollLeft
| MouseEventKind::ScrollRight
),
// VT200: button press and release
vt100::MouseProtocolMode::PressRelease => matches!(
event.kind,
MouseEventKind::Down(_)
| MouseEventKind::Up(_)
| MouseEventKind::ScrollUp
| MouseEventKind::ScrollDown
| MouseEventKind::ScrollLeft
| MouseEventKind::ScrollRight
),
// Button press, release, and drag (motion with button held)
vt100::MouseProtocolMode::ButtonMotion => matches!(
event.kind,
MouseEventKind::Down(_)
| MouseEventKind::Up(_)
| MouseEventKind::Drag(_)
| MouseEventKind::ScrollUp
| MouseEventKind::ScrollDown
| MouseEventKind::ScrollLeft
| MouseEventKind::ScrollRight
),
// Everything including plain motion
vt100::MouseProtocolMode::AnyMotion => true,
};
if !dominated {
return;
}

let seq = match encoding {
vt100::MouseProtocolEncoding::Sgr => encode_sgr_mouse(event, col, row),
// Default and UTF-8 both use the traditional encoding
vt100::MouseProtocolEncoding::Default | vt100::MouseProtocolEncoding::Utf8 => {
encode_default_mouse(event, col, row)
}
};
if let Some(seq) = seq {
self
.master_tx
.send(Bytes::from(seq.into_bytes()))
.await
.ok();
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using self.master_tx.send(...).await inside handle_mouse_event can block the main TUI thread if the PTY writer channel buffer (size 32) fills up. Rapid mouse movements (especially in AnyMotion mode) can easily flood the channel. Blocking the main thread will freeze the entire user interface.\n\nSince dropping intermediate mouse motion/drag events is perfectly acceptable and much better than freezing the UI, we should use non-blocking try_send instead of awaiting send.

  pub fn handle_mouse_event(&self, event: &MouseEvent, col: u16, row: u16) {
    let (mode, encoding) = {
      let parser = self.parser.read().unwrap();
      let screen = parser.screen();
      (
        screen.mouse_protocol_mode(),
        screen.mouse_protocol_encoding(),
      )
    };

    if mode == vt100::MouseProtocolMode::None {
      return;
    }

    let dominated = match mode {
      vt100::MouseProtocolMode::None => unreachable!(),
      vt100::MouseProtocolMode::Press => matches!(
        event.kind,
        MouseEventKind::Down(_)
          | MouseEventKind::ScrollUp
          | MouseEventKind::ScrollDown
          | MouseEventKind::ScrollLeft
          | MouseEventKind::ScrollRight
      ),
      vt100::MouseProtocolMode::PressRelease => matches!(
        event.kind,
        MouseEventKind::Down(_)
          | MouseEventKind::Up(_)
          | MouseEventKind::ScrollUp
          | MouseEventKind::ScrollDown
          | MouseEventKind::ScrollLeft
          | MouseEventKind::ScrollRight
      ),
      vt100::MouseProtocolMode::ButtonMotion => matches!(
        event.kind,
        MouseEventKind::Down(_)
          | MouseEventKind::Up(_)
          | MouseEventKind::Drag(_)
          | MouseEventKind::ScrollUp
          | MouseEventKind::ScrollDown
          | MouseEventKind::ScrollLeft
          | MouseEventKind::ScrollRight
      ),
      vt100::MouseProtocolMode::AnyMotion => true,
    };
    if !dominated {
      return;
    }

    let seq = match encoding {
      vt100::MouseProtocolEncoding::Sgr => encode_sgr_mouse(event, col, row),
      vt100::MouseProtocolEncoding::Default | vt100::MouseProtocolEncoding::Utf8 => {
        encode_default_mouse(event, col, row)
      }
    };
    if let Some(seq) = seq {
      self
        .master_tx
        .try_send(Bytes::from(seq))
        .ok();
    }
  }

Comment on lines +458 to +501
fn encode_sgr_mouse(event: &MouseEvent, col: u16, row: u16) -> Option<String> {
// SGR (1006) mouse encoding: ESC [ < button ; col ; row M/m
// button: 0 = left, 1 = middle, 2 = right, 64 = scroll up, 65 = scroll down
// +32 for motion events
// M = press/motion, m = release
let (button, is_release) = match event.kind {
MouseEventKind::Down(MouseButton::Left) => (0u8, false),
MouseEventKind::Down(MouseButton::Middle) => (1, false),
MouseEventKind::Down(MouseButton::Right) => (2, false),
MouseEventKind::Up(MouseButton::Left) => (0, true),
MouseEventKind::Up(MouseButton::Middle) => (1, true),
MouseEventKind::Up(MouseButton::Right) => (2, true),
MouseEventKind::Drag(MouseButton::Left) => (32, false),
MouseEventKind::Drag(MouseButton::Middle) => (33, false),
MouseEventKind::Drag(MouseButton::Right) => (34, false),
MouseEventKind::ScrollUp => (64, false),
MouseEventKind::ScrollDown => (65, false),
MouseEventKind::ScrollLeft => (66, false),
MouseEventKind::ScrollRight => (67, false),
MouseEventKind::Moved => (35, false),
};

// Add modifier flags
let mut button = button;
if event.modifiers.contains(KeyModifiers::SHIFT) {
button += 4;
}
if event.modifiers.contains(KeyModifiers::ALT) {
button += 8;
}
if event.modifiers.contains(KeyModifiers::CONTROL) {
button += 16;
}

// SGR format: ESC [ < button ; col+1 ; row+1 M/m
let suffix = if is_release { 'm' } else { 'M' };
Some(format!(
"\x1b[<{};{};{}{}",
button,
col + 1,
row + 1,
suffix
))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To align with the updated signature of encode_default_mouse and avoid unnecessary string-to-byte conversions in the main event loop, encode_sgr_mouse should also return Option<Vec<u8>> instead of Option<String>.

fn encode_sgr_mouse(event: &MouseEvent, col: u16, row: u16) -> Option<Vec<u8>> {
  // SGR (1006) mouse encoding: ESC [ < button ; col ; row M/m
  // button: 0 = left, 1 = middle, 2 = right, 64 = scroll up, 65 = scroll down
  // +32 for motion events
  // M = press/motion, m = release
  let (button, is_release) = match event.kind {
    MouseEventKind::Down(MouseButton::Left) => (0u8, false),
    MouseEventKind::Down(MouseButton::Middle) => (1, false),
    MouseEventKind::Down(MouseButton::Right) => (2, false),
    MouseEventKind::Up(MouseButton::Left) => (0, true),
    MouseEventKind::Up(MouseButton::Middle) => (1, true),
    MouseEventKind::Up(MouseButton::Right) => (2, true),
    MouseEventKind::Drag(MouseButton::Left) => (32, false),
    MouseEventKind::Drag(MouseButton::Middle) => (33, false),
    MouseEventKind::Drag(MouseButton::Right) => (34, false),
    MouseEventKind::ScrollUp => (64, false),
    MouseEventKind::ScrollDown => (65, false),
    MouseEventKind::ScrollLeft => (66, false),
    MouseEventKind::ScrollRight => (67, false),
    MouseEventKind::Moved => (35, false),
  };

  // Add modifier flags
  let mut button = button;
  if event.modifiers.contains(KeyModifiers::SHIFT) {
    button += 4;
  }
  if event.modifiers.contains(KeyModifiers::ALT) {
    button += 8;
  }
  if event.modifiers.contains(KeyModifiers::CONTROL) {
    button += 16;
  }

  // SGR format: ESC [ < button ; col+1 ; row+1 M/m
  let suffix = if is_release { 'm' } else { 'M' };
  Some(format!(
    "\\x1b[<{};{};{}{}",
    button,
    col + 1,
    row + 1,
    suffix
  ).into_bytes())
}

if self.term.is_some() {
if self.dragging_divider {
match me.kind {
MouseEventKind::Drag(MouseButton::Left) | MouseEventKind::Moved => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Matching MouseEventKind::Moved when self.dragging_divider is true can cause the pane divider to unexpectedly jump and follow the mouse cursor even when the left mouse button is not held down. This typically happens if the Up event is missed (e.g., when the mouse is released outside the terminal window). Restricting this match to MouseEventKind::Drag(MouseButton::Left) makes the dragging behavior much more robust.

Suggested change
MouseEventKind::Drag(MouseButton::Left) | MouseEventKind::Moved => {
MouseEventKind::Drag(MouseButton::Left) => {

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.54128% with 495 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.83%. Comparing base (75e39ee) to head (2b4e077).

Files with missing lines Patch % Lines
crates/tracexec-tui/src/app.rs 3.44% 168 Missing ⚠️
crates/tracexec-tui/src/pseudo_term.rs 56.84% 82 Missing ⚠️
crates/tracexec-tui/src/app/ui.rs 58.38% 62 Missing ⚠️
crates/tracexec-tui/src/breakpoint_manager.rs 2.04% 48 Missing ⚠️
crates/tracexec-tui/src/hit_manager.rs 20.00% 44 Missing ⚠️
crates/tracexec-tui/src/details_popup.rs 32.60% 31 Missing ⚠️
crates/tracexec-tui/src/event_list/ui.rs 62.79% 16 Missing ⚠️
crates/tracexec-tui/src/help.rs 62.79% 16 Missing ⚠️
crates/tracexec-tui/src/lib.rs 0.00% 14 Missing ⚠️
crates/tracexec-tui/src/query.rs 75.00% 7 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #279      +/-   ##
==========================================
- Coverage   82.85%   81.83%   -1.02%     
==========================================
  Files          81       82       +1     
  Lines       20475    21257     +782     
==========================================
+ Hits        16964    17396     +432     
- Misses       3511     3861     +350     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant