fix: stop_running function

Use stop_running to set the global is_running AtomicBool to false, and to also, on a seperate thread, enable & then disable mouse capture, as was experience strange issue on Linux & WSL with mouse movements being piped to stdout
This commit is contained in:
Jack Wills
2023-02-28 18:10:24 +00:00
parent 31bfaa7a95
commit 2626250ace
3 changed files with 31 additions and 37 deletions
+27 -25
View File
@@ -1,24 +1,28 @@
#![forbid(unsafe_code)]
// #![warn(
// clippy::nursery,
// clippy::pedantic,
// clippy::expect_used,
// clippy::todo,
// clippy::unused_async,
// clippy::unwrap_used
// )]
// // Warning - These are indeed pedantic
// #![allow(
// clippy::module_name_repetitions,
// clippy::doc_markdown,
// clippy::similar_names
// )]
#![warn(
clippy::nursery,
clippy::pedantic,
clippy::expect_used,
clippy::todo,
clippy::unused_async,
clippy::unwrap_used
)]
// Warning - These are indeed pedantic
#![allow(
clippy::module_name_repetitions,
clippy::doc_markdown,
clippy::similar_names
)]
// Only allow when debugging
#![allow(unused)]
use app_data::AppData;
use app_error::AppError;
use bollard::Docker;
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture},
execute,
};
use docker_data::DockerData;
use input_handler::InputMessages;
use parking_lot::Mutex;
@@ -66,6 +70,15 @@ fn check_if_containerised() -> bool {
}
}
/// Set is_running to false, disable mouse capture, due to weird bug on Linux & WSL terminals
/// where mouse movement will be piped to the stdout
fn stop_running(is_running: &AtomicBool) {
std::thread::spawn(|| {
execute!(std::io::stdout(), EnableMouseCapture).unwrap_or(());
execute!(std::io::stdout(), DisableMouseCapture).unwrap_or(());
});
is_running.store(false, std::sync::atomic::Ordering::SeqCst);
}
/// Create docker daemon handler, and only spawn up the docker data handler if a ping returns non-error
async fn docker_init(
app_data: &Arc<Mutex<AppData>>,
@@ -149,15 +162,4 @@ async fn main() {
.await;
}
}
// let mut child = std::process::Command::new("tput").arg("reset").spawn().unwrap_or_else(|e| panic!("Could not run tput: {}", e));
// let result = child.wait().unwrap_or_else(|e| panic!("Could not wait for tput process: {}", e));
// if ! result.success() {
// panic!("tput failed with error code {}", result.code().unwrap());
// }
// Clear screen
// std::io::stdout().lock().flush().unwrap_or(());
// std::io::stdout().lock().write(b"").unwrap_or_default();
}