From 34654adececfd366e8a6a9bdd808cc336f3c8af7 Mon Sep 17 00:00:00 2001 From: YummyOreo Date: Mon, 11 Sep 2023 02:49:06 -0500 Subject: [PATCH] feat: mouse selection support (#1209) * feat: mouse selection support * refactor: don't import self --- .../src/command/client/search/interactive.rs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs index 79399ab..8c12b1f 100644 --- a/atuin/src/command/client/search/interactive.rs +++ b/atuin/src/command/client/search/interactive.rs @@ -4,7 +4,10 @@ use std::{ }; use crossterm::{ - event::{self, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent}, + event::{ + self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, + MouseEvent, + }, execute, terminal, }; use eyre::Result; @@ -63,13 +66,24 @@ impl State { Ok(results) } - fn handle_input(&mut self, settings: &Settings, input: &Event) -> Option { - match input { + fn handle_input( + &mut self, + settings: &Settings, + input: &Event, + w: &mut W, + ) -> Result> + where + W: Write, + { + execute!(w, EnableMouseCapture)?; + let r = match input { Event::Key(k) => self.handle_key_input(settings, k), Event::Mouse(m) => self.handle_mouse_input(*m), Event::Paste(d) => self.handle_paste_input(d), _ => None, - } + }; + execute!(w, DisableMouseCapture)?; + Ok(r) } fn handle_mouse_input(&mut self, input: MouseEvent) -> Option { @@ -639,7 +653,7 @@ pub async fn history( event_ready = event_ready => { if event_ready?? { loop { - if let Some(i) = app.handle_input(settings, &event::read()?) { + if let Some(i) = app.handle_input(settings, &event::read()?, &mut std::io::stdout())? { break 'render i; } if !event::poll(Duration::ZERO)? {