fix: correctly set gui error
This commit is contained in:
+12
-11
@@ -80,22 +80,23 @@ impl InputHandler {
|
||||
/// Toggle the mouse capture (via input of the 'm' key)
|
||||
fn m_key(&mut self) {
|
||||
if self.mouse_capture {
|
||||
match execute!(std::io::stdout(), DisableMouseCapture) {
|
||||
Ok(_) => self
|
||||
.gui_state
|
||||
if execute!(std::io::stdout(), DisableMouseCapture).is_ok() {
|
||||
self.gui_state
|
||||
.lock()
|
||||
.set_info_box("✖ mouse capture disabled".to_owned()),
|
||||
Err(_) => {
|
||||
self.app_data
|
||||
.lock()
|
||||
.set_error(AppError::MouseCapture(false));
|
||||
}
|
||||
.set_info_box("✖ mouse capture disabled".to_owned());
|
||||
} else {
|
||||
self.app_data
|
||||
.lock()
|
||||
.set_error(AppError::MouseCapture(false));
|
||||
self.gui_state.lock().status_push(Status::Error);
|
||||
}
|
||||
} else {
|
||||
Ui::enable_mouse_capture();
|
||||
} else if Ui::enable_mouse_capture().is_ok() {
|
||||
self.gui_state
|
||||
.lock()
|
||||
.set_info_box("✓ mouse capture enabled".to_owned());
|
||||
} else {
|
||||
self.app_data.lock().set_error(AppError::MouseCapture(true));
|
||||
self.gui_state.lock().status_push(Status::Error);
|
||||
};
|
||||
|
||||
// If the info box sleep handle is currently being executed, as in 'm' is pressed twice within a 4000ms window
|
||||
|
||||
+12
-13
@@ -43,17 +43,16 @@ pub struct Ui {
|
||||
|
||||
impl Ui {
|
||||
/// Enable mouse capture, but don't enable capture of all the mouse movements, doing so will improve performance, and is part of the fix for the weird mouse event output bug
|
||||
pub fn enable_mouse_capture() {
|
||||
io::stdout()
|
||||
.write_all(
|
||||
concat!(
|
||||
crossterm::csi!("?1000h"),
|
||||
crossterm::csi!("?1015h"),
|
||||
crossterm::csi!("?1006h"),
|
||||
)
|
||||
.as_bytes(),
|
||||
pub fn enable_mouse_capture() -> Result<()> {
|
||||
io::stdout().write_all(
|
||||
concat!(
|
||||
crossterm::csi!("?1000h"),
|
||||
crossterm::csi!("?1015h"),
|
||||
crossterm::csi!("?1006h"),
|
||||
)
|
||||
.unwrap_or(());
|
||||
.as_bytes(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a new Ui struct, and execute the drawing loop
|
||||
@@ -87,13 +86,13 @@ impl Ui {
|
||||
}
|
||||
|
||||
/// Setup the terminal for full-screen drawing mode, with mouse capture
|
||||
fn setup_terminal() -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
|
||||
fn setup_terminal() -> Result<Terminal<CrosstermBackend<Stdout>>> {
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = io::stdout();
|
||||
execute!(stdout, EnterAlternateScreen)?;
|
||||
Self::enable_mouse_capture();
|
||||
Self::enable_mouse_capture()?;
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
Terminal::new(backend)
|
||||
Ok(Terminal::new(backend)?)
|
||||
}
|
||||
|
||||
/// This is a fix for mouse-events being printed to screen, read an event and do nothing with it
|
||||
|
||||
Reference in New Issue
Block a user