diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-11-08 00:56:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 00:56:39 -0500 |
commit | 8101e6fa563fc1084189e01e6297eac2f182533f (patch) | |
tree | f22f34d6d6cdc8f734e9304c7bf03d26b94cd4e6 /src | |
parent | e1be318177ed0447c8997df166987dee1a48e343 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/main.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 45 | ||||
-rw-r--r-- | src/utils/error.rs | 6 |
3 files changed, 31 insertions, 22 deletions
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}, @@ -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<heim::Error> for BottomError { } } -impl From<crossterm::ErrorKind> for BottomError { - fn from(err: crossterm::ErrorKind) -> Self { - BottomError::CrosstermError(err.to_string()) - } -} - impl From<std::num::ParseIntError> for BottomError { fn from(err: std::num::ParseIntError) -> Self { BottomError::ConfigError(err.to_string()) |