From 8101e6fa563fc1084189e01e6297eac2f182533f Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 8 Nov 2022 00:56:39 -0500 Subject: deps: Update tui to 0.19.0 and crossterm to 0.25.0 (#878) * deps: update tui to 0.19 and crossterm to 0.25 * fix error * handle breaking changes --- src/bin/main.rs | 2 +- src/lib.rs | 45 ++++++++++++++++++++++++++++++--------------- src/utils/error.rs | 6 ------ 3 files changed, 31 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/bin/main.rs b/src/bin/main.rs index 9c3e8f94..a6a8a1a5 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -14,7 +14,7 @@ use bottom::{ use std::{ boxed::Box, - io::{stdout, Write}, + io::stdout, panic, sync::{ atomic::{AtomicBool, Ordering}, diff --git a/src/lib.rs b/src/lib.rs index 34096843..0ac83582 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,10 @@ use std::{ }; use crossterm::{ - event::{poll, read, DisableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent}, + event::{ + poll, read, DisableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, + MouseEventKind, + }, execute, style::Print, terminal::{disable_raw_mode, LeaveAlternateScreen}, @@ -81,10 +84,11 @@ pub enum ThreadControlEvent { } pub fn handle_mouse_event(event: MouseEvent, app: &mut App) { - match event { - MouseEvent::ScrollUp(_x, _y, _modifiers) => app.handle_scroll_up(), - MouseEvent::ScrollDown(_x, _y, _modifiers) => app.handle_scroll_down(), - MouseEvent::Down(button, x, y, _modifiers) => { + match event.kind { + MouseEventKind::ScrollUp => app.handle_scroll_up(), + MouseEventKind::ScrollDown => app.handle_scroll_down(), + MouseEventKind::Down(button) => { + let (x, y) = (event.column, event.row); if !app.app_config_fields.disable_click { match button { crossterm::event::MouseButton::Left => { @@ -419,20 +423,31 @@ pub fn create_input_thread( if let Ok(poll) = poll(Duration::from_millis(20)) { if poll { if let Ok(event) = read() { - if let Event::Key(key) = event { - if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 { - if sender.send(BottomEvent::KeyInput(key)).is_err() { - break; + // FIXME: Handle all other event cases. + match event { + Event::Key(key) => { + if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 { + if sender.send(BottomEvent::KeyInput(key)).is_err() { + break; + } + keyboard_timer = Instant::now(); } - keyboard_timer = Instant::now(); } - } else if let Event::Mouse(mouse) = event { - if Instant::now().duration_since(mouse_timer).as_millis() >= 20 { - if sender.send(BottomEvent::MouseInput(mouse)).is_err() { - break; + Event::Mouse(mouse) => { + if Instant::now().duration_since(mouse_timer).as_millis() >= 20 { + match mouse.kind { + MouseEventKind::Moved => {} + _ => { + if sender.send(BottomEvent::MouseInput(mouse)).is_err() + { + break; + } + mouse_timer = Instant::now(); + } + } } - mouse_timer = Instant::now(); } + _ => (), } } } diff --git a/src/utils/error.rs b/src/utils/error.rs index 6a7a2cfe..3c61d14b 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -56,12 +56,6 @@ impl From for BottomError { } } -impl From for BottomError { - fn from(err: crossterm::ErrorKind) -> Self { - BottomError::CrosstermError(err.to_string()) - } -} - impl From for BottomError { fn from(err: std::num::ParseIntError) -> Self { BottomError::ConfigError(err.to_string()) -- cgit v1.2.3