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:
@@ -20,6 +20,7 @@ use crate::{
|
||||
app_data::{AppData, ContainerId, DockerControls},
|
||||
app_error::AppError,
|
||||
parse_args::CliArgs,
|
||||
stop_running,
|
||||
ui::{GuiState, Status},
|
||||
ENTRY_POINT,
|
||||
};
|
||||
@@ -408,12 +409,7 @@ impl DockerData {
|
||||
.values()
|
||||
.into_iter()
|
||||
.for_each(tokio::task::JoinHandle::abort);
|
||||
// This is a fix for a weird bug on Linux + WSL which will output mouse movement to the stdout
|
||||
// execute!(std::io::stdout(), DisableMouseCapture).unwrap_or(());
|
||||
std::thread::spawn(||{
|
||||
execute!(std::io::stdout(), DisableMouseCapture).unwrap_or(());
|
||||
});
|
||||
self.is_running.store(false, Ordering::SeqCst);
|
||||
stop_running(&self.is_running);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
app_data::{AppData, DockerControls, Header},
|
||||
app_error::AppError,
|
||||
docker_data::DockerMessage,
|
||||
stop_running,
|
||||
ui::{GuiState, SelectablePanel, Status},
|
||||
};
|
||||
pub use message::InputMessages;
|
||||
@@ -134,12 +135,7 @@ impl InputHandler {
|
||||
.lock()
|
||||
.status_contains(&[Status::Error, Status::Init]);
|
||||
if error_init || self.docker_sender.send(DockerMessage::Quit).await.is_err() {
|
||||
// This is a fix for a weird bug on Linux + WSL which will output mouse movement to the stdout
|
||||
|
||||
std::thread::spawn(||{
|
||||
execute!(std::io::stdout(), DisableMouseCapture).unwrap_or(());
|
||||
});
|
||||
self.is_running.store(false, Ordering::SeqCst);
|
||||
stop_running(&self.is_running);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-25
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user