Fixed problem caused by overfilling the input queue with scroll events.

This commit is contained in:
ClementTsang 2019-10-12 23:51:15 -04:00
parent 902ed9a839
commit b87edceb86
4 changed files with 24 additions and 10 deletions

View File

@ -5,6 +5,8 @@ os:
- windows - windows
- osx - osx
- linux - linux
env:
- RUST_BACKTRACE=1
GH_TOKEN: &GH_TOKEN GH_TOKEN: &GH_TOKEN
secure: ckWcEQHz8SekxaAdBNpiT+YF6ST0pJS15lC4MNT1mIzLMgEXpJI/peNwwRf+FGJiyqNtaK5YUAB6cP25w9QZsrwBLmLJ9wcGaHJuPc7XKvpHkEiFwTDaOqrIRmYhvAfjwH5IycnyAlAzsHsPujmhCWQyiW4YSziCOqtByY4ftzchOCh44kWmqf7HI6uSPSFfqHtTdkM21Dgwm+NpYPmwO0wmrEIwCNkN62Fb+Ghk9AqJH67vDLs+mvKQTdDc2X+fDT9sQxTI4dftSGx2JDkivwVfxX3kOroZvIRG6WmEGYyzU6wLYJlfFSg6svofdOZwNC71Byr5gEFLZOCfWrd2P4gF+CMA61PqGQMBAgAMVX4kCMblERyAdTVFKtP+WPOEBoWqsNLdzQhulF+w71MDRBnfDmuQ2TRegobCTvKefp0I3YYLLoKrDNMIvQ9572DcvLME4hzBwnizy8G1UBepqz3oa3R/6Kr8NlYBHnbbUBmzVZW1jZokz3T/c7r2fqC7h6pC8VtUh/e246ROF0k9mCVKKrsfrEZ4UjRL8RmuAQ12CeAa1GsSSwtbbwW2VIX0iVVXo080iGMKZHTTvDIRHkjA3MzPuAZyUruCjp9yQmpbG/cSzR8aJPzIia9+qXp0jmML3Du52qsF8m68gbcOpNS0CHOQY9wmuWhCatmzt2Y= secure: ckWcEQHz8SekxaAdBNpiT+YF6ST0pJS15lC4MNT1mIzLMgEXpJI/peNwwRf+FGJiyqNtaK5YUAB6cP25w9QZsrwBLmLJ9wcGaHJuPc7XKvpHkEiFwTDaOqrIRmYhvAfjwH5IycnyAlAzsHsPujmhCWQyiW4YSziCOqtByY4ftzchOCh44kWmqf7HI6uSPSFfqHtTdkM21Dgwm+NpYPmwO0wmrEIwCNkN62Fb+Ghk9AqJH67vDLs+mvKQTdDc2X+fDT9sQxTI4dftSGx2JDkivwVfxX3kOroZvIRG6WmEGYyzU6wLYJlfFSg6svofdOZwNC71Byr5gEFLZOCfWrd2P4gF+CMA61PqGQMBAgAMVX4kCMblERyAdTVFKtP+WPOEBoWqsNLdzQhulF+w71MDRBnfDmuQ2TRegobCTvKefp0I3YYLLoKrDNMIvQ9572DcvLME4hzBwnizy8G1UBepqz3oa3R/6Kr8NlYBHnbbUBmzVZW1jZokz3T/c7r2fqC7h6pC8VtUh/e246ROF0k9mCVKKrsfrEZ4UjRL8RmuAQ12CeAa1GsSSwtbbwW2VIX0iVVXo080iGMKZHTTvDIRHkjA3MzPuAZyUruCjp9yQmpbG/cSzR8aJPzIia9+qXp0jmML3Du52qsF8m68gbcOpNS0CHOQY9wmuWhCatmzt2Y=

View File

@ -26,7 +26,7 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p
- Refactoring! - Refactoring!
- Mouse + key events conflict? Make it so that some events don't clog up the loop if they are not valid keys! - Ensure there's a max number of inputs you can send at once --- for example, sending MANY scroll events clogs up the system
- Modularity - Modularity

View File

@ -75,7 +75,7 @@ impl DataState {
} }
pub async fn update_data(&mut self) { pub async fn update_data(&mut self) {
debug!("Start updating..."); //debug!("Start updating...");
self.sys.refresh_system(); self.sys.refresh_system();
self.sys.refresh_network(); self.sys.refresh_network();
@ -166,6 +166,6 @@ impl DataState {
self.last_clean = current_instant; self.last_clean = current_instant;
} }
debug!("End updating..."); //debug!("End updating...");
} }
} }

View File

@ -8,7 +8,12 @@ extern crate clap;
extern crate failure; extern crate failure;
use crossterm::{input, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent}; use crossterm::{input, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
use std::{io::stdout, sync::mpsc, thread, time::Duration}; use std::{
io::stdout,
sync::mpsc,
thread,
time::{Duration, Instant},
};
use tui_temp_fork::{backend::CrosstermBackend, Terminal}; use tui_temp_fork::{backend::CrosstermBackend, Terminal};
pub mod app; pub mod app;
@ -112,6 +117,7 @@ fn main() -> error::Result<()> {
thread::spawn(move || { thread::spawn(move || {
let input = input(); let input = input();
input.enable_mouse_mode().unwrap(); input.enable_mouse_mode().unwrap();
let mut input_timer = Instant::now();
// TODO: I don't like this... seems odd async doesn't work on linux (then again, sync didn't work on windows) // TODO: I don't like this... seems odd async doesn't work on linux (then again, sync didn't work on windows)
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
@ -119,13 +125,16 @@ fn main() -> error::Result<()> {
for event in reader { for event in reader {
match event { match event {
InputEvent::Keyboard(key) => { InputEvent::Keyboard(key) => {
if tx.send(Event::KeyInput(key.clone())).is_err() { if tx.send(Event::KeyInput(key)).is_err() {
return; return;
} }
} }
InputEvent::Mouse(mouse) => { InputEvent::Mouse(mouse) => {
if tx.send(Event::MouseInput(mouse)).is_err() { if Instant::now().duration_since(input_timer).as_millis() >= 40 {
return; if tx.send(Event::MouseInput(mouse)).is_err() {
return;
}
input_timer = Instant::now();
} }
} }
_ => {} _ => {}
@ -138,13 +147,16 @@ fn main() -> error::Result<()> {
if let Some(event) = reader.next() { if let Some(event) = reader.next() {
match event { match event {
InputEvent::Keyboard(key) => { InputEvent::Keyboard(key) => {
if tx.send(Event::KeyInput(key.clone())).is_err() { if tx.send(Event::KeyInput(key)).is_err() {
return; return;
} }
} }
InputEvent::Mouse(mouse) => { InputEvent::Mouse(mouse) => {
if tx.send(Event::MouseInput(mouse)).is_err() { if Instant::now().duration_since(input_timer).as_millis() >= 40 {
return; if tx.send(Event::MouseInput(mouse)).is_err() {
return;
}
input_timer = Instant::now();
} }
} }
_ => {} _ => {}