From 00dfacfe13ccd7562b622d15e923a831fca1fd69 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Fri, 29 Apr 2022 01:30:31 +0000 Subject: [PATCH] refactor: m_button, help box text --- src/input_handler/mod.rs | 87 +++++++++++++++++++--------------------- src/ui/draw_blocks.rs | 15 ++++--- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/input_handler/mod.rs b/src/input_handler/mod.rs index 68728b8..af2f63c 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -74,6 +74,41 @@ impl InputHandler { } } + fn m_button(&mut self) { + if self.mouse_capture { + match execute!(std::io::stdout(), DisableMouseCapture) { + Ok(_) => self + .gui_state + .lock() + .set_info_box("✖ mouse capture disabled".to_owned()), + Err(_) => self + .app_data + .lock() + .set_error(AppError::MouseCapture(false)), + } + } else { + match execute!(std::io::stdout(), EnableMouseCapture) { + Ok(_) => self + .gui_state + .lock() + .set_info_box("✓ mouse capture enabled".to_owned()), + Err(_) => self.app_data.lock().set_error(AppError::MouseCapture(true)), + } + }; + + let gui_state = Arc::clone(&self.gui_state); + + if self.info_sleep.is_some() { + self.info_sleep.as_ref().unwrap().abort() + } + self.info_sleep = Some(tokio::spawn(async move { + tokio::time::sleep(std::time::Duration::from_millis(4000)).await; + gui_state.lock().reset_info_box() + })); + + self.mouse_capture = !self.mouse_capture; + } + /// Handle any keyboard button events async fn button_press(&mut self, key_code: KeyCode) { let show_error = self.app_data.lock().show_error; @@ -92,56 +127,16 @@ impl InputHandler { } } else if show_info { match key_code { - KeyCode::Char('q') => { - self.is_running.store(false, Ordering::SeqCst); - } - KeyCode::Char('h') => { - self.gui_state.lock().show_help = false; - } + KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst), + KeyCode::Char('h') => self.gui_state.lock().show_help = false, + KeyCode::Char('m') => self.m_button(), _ => (), } } else { match key_code { - KeyCode::Char('q') => { - self.is_running.store(false, Ordering::SeqCst); - } - KeyCode::Char('h') => { - self.gui_state.lock().show_help = true; - } - KeyCode::Char('m') => { - if self.mouse_capture { - match execute!(std::io::stdout(), DisableMouseCapture) { - Ok(_) => self - .gui_state - .lock() - .set_info_box("✖ mouse capture disabled".to_owned()), - Err(_) => self - .app_data - .lock() - .set_error(AppError::MouseCapture(false)), - } - } else { - match execute!(std::io::stdout(), EnableMouseCapture) { - Ok(_) => self - .gui_state - .lock() - .set_info_box("✓ mouse capture enabled".to_owned()), - Err(_) => self.app_data.lock().set_error(AppError::MouseCapture(true)), - } - }; - - let gui_state = Arc::clone(&self.gui_state); - - if self.info_sleep.is_some() { - self.info_sleep.as_ref().unwrap().abort() - } - self.info_sleep = Some(tokio::spawn(async move { - tokio::time::sleep(std::time::Duration::from_millis(4000)).await; - gui_state.lock().reset_info_box() - })); - - self.mouse_capture = !self.mouse_capture; - } + KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst), + KeyCode::Char('h') => self.gui_state.lock().show_help = true, + KeyCode::Char('m') => self.m_button(), KeyCode::Tab => self.gui_state.lock().next_panel(), KeyCode::BackTab => self.gui_state.lock().previous_panel(), KeyCode::Home => { diff --git a/src/ui/draw_blocks.rs b/src/ui/draw_blocks.rs index e55f3a0..b6bb42d 100644 --- a/src/ui/draw_blocks.rs +++ b/src/ui/draw_blocks.rs @@ -471,12 +471,15 @@ pub fn draw_heading_bar( pub fn draw_help_box(f: &mut Frame<'_, B>) { let title = format!(" {} ", VERSION); - let mut description_text = - String::from("\n A basic docker container information viewer and controller."); - description_text.push_str("\n Tab or Alt+Tab to change panels, arrows to change lines, enter to send docker container commands."); - description_text.push_str("\n Mouse input also available."); - description_text.push_str("\n ( q ) to quit at any time."); - description_text.push_str("\n ( m ) to toggle mouse capture. When disabled, text on screen can be selected & copied, but mouse clicks get disabled"); + let mut description_text = String::new(); + // String::from("\n A basic docker container information viewer and controller."); + description_text.push_str("\n ( tab ) or ( alt+tab ) to change panels"); + description_text.push_str("\n ( ↑ ↓ ← → ) mto change selected line"); + description_text.push_str("\n ( enter ) to send docker container commands"); + description_text.push_str("\n ( m ) to toggle mouse capture - if disabled, text on screen can be selected & copied, but mouse clicks get disabled"); + description_text.push_str("\n ( h ) to toggle this help information"); + description_text.push_str("\n ( q ) to quit at any time"); + description_text.push_str("\n mouse scrolling & clicking also available"); description_text .push_str("\n\n currenty an early work in progress, all and any input appreciated"); description_text.push_str(format!("\n {}", REPO.trim()).as_str());