Skip to content

Commit

Permalink
feat: mouse selection support (atuinsh#1209)
Browse files Browse the repository at this point in the history
* feat: mouse selection support

* refactor: don't import self
  • Loading branch information
YummyOreo authored Sep 11, 2023
1 parent 6d3b14b commit 34654ad
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,13 +66,24 @@ impl State {
Ok(results)
}

fn handle_input(&mut self, settings: &Settings, input: &Event) -> Option<usize> {
match input {
fn handle_input<W>(
&mut self,
settings: &Settings,
input: &Event,
w: &mut W,
) -> Result<Option<usize>>
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<usize> {
Expand Down Expand Up @@ -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)? {
Expand Down

0 comments on commit 34654ad

Please sign in to comment.