refactor: m_button, help box text
This commit is contained in:
+41
-46
@@ -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
|
/// Handle any keyboard button events
|
||||||
async fn button_press(&mut self, key_code: KeyCode) {
|
async fn button_press(&mut self, key_code: KeyCode) {
|
||||||
let show_error = self.app_data.lock().show_error;
|
let show_error = self.app_data.lock().show_error;
|
||||||
@@ -92,56 +127,16 @@ impl InputHandler {
|
|||||||
}
|
}
|
||||||
} else if show_info {
|
} else if show_info {
|
||||||
match key_code {
|
match key_code {
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst),
|
||||||
self.is_running.store(false, Ordering::SeqCst);
|
KeyCode::Char('h') => self.gui_state.lock().show_help = false,
|
||||||
}
|
KeyCode::Char('m') => self.m_button(),
|
||||||
KeyCode::Char('h') => {
|
|
||||||
self.gui_state.lock().show_help = false;
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match key_code {
|
match key_code {
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst),
|
||||||
self.is_running.store(false, Ordering::SeqCst);
|
KeyCode::Char('h') => self.gui_state.lock().show_help = true,
|
||||||
}
|
KeyCode::Char('m') => self.m_button(),
|
||||||
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::Tab => self.gui_state.lock().next_panel(),
|
KeyCode::Tab => self.gui_state.lock().next_panel(),
|
||||||
KeyCode::BackTab => self.gui_state.lock().previous_panel(),
|
KeyCode::BackTab => self.gui_state.lock().previous_panel(),
|
||||||
KeyCode::Home => {
|
KeyCode::Home => {
|
||||||
|
|||||||
@@ -471,12 +471,15 @@ pub fn draw_heading_bar<B: Backend>(
|
|||||||
pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
||||||
let title = format!(" {} ", VERSION);
|
let title = format!(" {} ", VERSION);
|
||||||
|
|
||||||
let mut description_text =
|
let mut description_text = String::new();
|
||||||
String::from("\n A basic docker container information viewer and controller.");
|
// 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 ( tab ) or ( alt+tab ) to change panels");
|
||||||
description_text.push_str("\n Mouse input also available.");
|
description_text.push_str("\n ( ↑ ↓ ← → ) mto change selected line");
|
||||||
description_text.push_str("\n ( q ) to quit at any time.");
|
description_text.push_str("\n ( enter ) to send docker container commands");
|
||||||
description_text.push_str("\n ( m ) to toggle mouse capture. When disabled, text on screen can be selected & copied, but mouse clicks get disabled");
|
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
|
description_text
|
||||||
.push_str("\n\n currenty an early work in progress, all and any input appreciated");
|
.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());
|
description_text.push_str(format!("\n {}", REPO.trim()).as_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user