diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-01-02 22:54:39 -0500 |
---|---|---|
committer | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-01-02 22:54:39 -0500 |
commit | 7b902a9470457655852307bc5369a64fcd3e5871 (patch) | |
tree | 01561fae11f8ab3e4b0518077e7e2c01e5c4e593 | |
parent | 4ae2882aa6f288841fdab064d8e89a9310708a47 (diff) |
Fix mouse scrolling in windows
-rw-r--r-- | .vscode/settings.json | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/main.rs | 18 |
4 files changed, 15 insertions, 8 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 356e7745..1efd61f6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "AHHHHHH", "Dataset", + "Ryzen", "Tebibyte", "avgcpu", "backend", @@ -24,7 +24,6 @@ futures-timer = "2.0.2" futures = "0.3.1" heim = "0.0.9" log = "0.4" -rayon = "1.3" regex = "1.3.1" sysinfo = "0.9" #0.9 seems to be the last working version for my Ryzen PC... tokio = "0.2.6" @@ -20,6 +20,8 @@ You can currently install by cloning and building yourself using `cargo build -- macOS support will hopefully come soon<sup>TM</sup>. +## Compatibility + The compatibility of each widget and operating systems are, as of version 0.1.0, as follows: | OS/Widget | CPU | Memory | Disks | Temperature | Processes | Networks | @@ -110,3 +112,4 @@ The compatibility of each widget and operating systems are, as of version 0.1.0, - [tokio](https://github.com/tokio-rs/tokio) - [tui-rs](https://github.com/fdehau/tui-rs) - [winapi](https://github.com/retep998/winapi-rs) + - [lazy_static](https://github.com/rust-lang-nursery/lazy-static.rs) diff --git a/src/main.rs b/src/main.rs index f24eca96..644d1e96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ extern crate failure; extern crate lazy_static; use crossterm::{ - event::{self, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent}, + event::{self, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent}, execute, terminal::LeaveAlternateScreen, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen}, @@ -124,10 +124,9 @@ fn main() -> error::Result<()> { let mut stdout = stdout(); enable_raw_mode()?; execute!(stdout, EnterAlternateScreen)?; + execute!(stdout, EnableMouseCapture)?; - let backend = CrosstermBackend::new(stdout); - - let mut terminal = Terminal::new(backend)?; + let mut terminal = Terminal::new(CrosstermBackend::new(stdout))?; terminal.hide_cursor()?; terminal.clear()?; @@ -304,16 +303,21 @@ fn main() -> error::Result<()> { } // Draw! if let Err(err) = canvas::draw_data(&mut terminal, &mut app) { - disable_raw_mode()?; - execute!(terminal.backend_mut(), LeaveAlternateScreen)?; - terminal.show_cursor()?; + cleanup(&mut terminal)?; error!("{}", err); return Err(err); } } + cleanup(&mut terminal)?; + Ok(()) +} + +fn cleanup(terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>) -> error::Result<()> { disable_raw_mode()?; + execute!(terminal.backend_mut(), DisableMouseCapture)?; execute!(terminal.backend_mut(), LeaveAlternateScreen)?; terminal.show_cursor()?; + Ok(()) } |