mirror of
https://github.com/domcyrus/rustnet.git
synced 2026-04-24 21:49:34 -05:00
double q to quit
This commit is contained in:
+24
-4
@@ -165,19 +165,32 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
|
||||
match (key.code, key.modifiers) {
|
||||
// Quit
|
||||
(KeyCode::Char('q'), _) | (KeyCode::Char('c'), KeyModifiers::CONTROL) => {
|
||||
info!("User requested application exit");
|
||||
// Quit with confirmation
|
||||
(KeyCode::Char('q'), _) => {
|
||||
if ui_state.quit_confirmation {
|
||||
info!("User confirmed application exit");
|
||||
break;
|
||||
} else {
|
||||
info!("User requested quit - showing confirmation");
|
||||
ui_state.quit_confirmation = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ctrl+C always quits immediately
|
||||
(KeyCode::Char('c'), KeyModifiers::CONTROL) => {
|
||||
info!("User requested immediate exit with Ctrl+C");
|
||||
break;
|
||||
}
|
||||
|
||||
// Tab navigation
|
||||
(KeyCode::Tab, _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
ui_state.selected_tab = (ui_state.selected_tab + 1) % 3;
|
||||
}
|
||||
|
||||
// Help toggle
|
||||
(KeyCode::Char('h'), _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
ui_state.show_help = !ui_state.show_help;
|
||||
if ui_state.show_help {
|
||||
ui_state.selected_tab = 2; // Switch to help tab
|
||||
@@ -188,15 +201,18 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
|
||||
|
||||
// Navigation in connection list
|
||||
(KeyCode::Up, _) | (KeyCode::Char('k'), _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
ui_state.move_selection_up(&connections);
|
||||
}
|
||||
|
||||
(KeyCode::Down, _) | (KeyCode::Char('j'), _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
ui_state.move_selection_down(&connections);
|
||||
}
|
||||
|
||||
// Enter to view details
|
||||
(KeyCode::Enter, _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
if ui_state.selected_tab == 0 && !connections.is_empty() {
|
||||
ui_state.selected_tab = 1; // Switch to details view
|
||||
}
|
||||
@@ -204,6 +220,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
|
||||
|
||||
// Escape to go back
|
||||
(KeyCode::Esc, _) => {
|
||||
ui_state.quit_confirmation = false;
|
||||
if ui_state.selected_tab == 1 {
|
||||
ui_state.selected_tab = 0; // Back to overview
|
||||
} else if ui_state.selected_tab == 2 {
|
||||
@@ -211,7 +228,10 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
// Any other key resets quit confirmation
|
||||
_ => {
|
||||
ui_state.quit_confirmation = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ pub struct UIState {
|
||||
pub selected_tab: usize,
|
||||
pub selected_connection_key: Option<String>,
|
||||
pub show_help: bool,
|
||||
pub quit_confirmation: bool,
|
||||
}
|
||||
|
||||
impl UIState {
|
||||
@@ -111,6 +112,7 @@ impl Default for UIState {
|
||||
selected_tab: 0,
|
||||
selected_connection_key: None,
|
||||
show_help: false,
|
||||
quit_confirmation: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +149,7 @@ pub fn draw(
|
||||
_ => {}
|
||||
}
|
||||
|
||||
draw_status_bar(f, connections.len(), chunks[2]);
|
||||
draw_status_bar(f, ui_state, connections.len(), chunks[2]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -637,8 +639,12 @@ fn draw_help(f: &mut Frame, area: Rect) -> Result<()> {
|
||||
]),
|
||||
Line::from(""),
|
||||
Line::from(vec![
|
||||
Span::styled("q, Ctrl+C ", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("Quit application"),
|
||||
Span::styled("q ", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("Quit application (press twice to confirm)"),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Ctrl+C ", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("Quit immediately"),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Tab ", Style::default().fg(Color::Yellow)),
|
||||
@@ -676,14 +682,24 @@ fn draw_help(f: &mut Frame, area: Rect) -> Result<()> {
|
||||
}
|
||||
|
||||
/// Draw status bar
|
||||
fn draw_status_bar(f: &mut Frame, connection_count: usize, area: Rect) {
|
||||
let status = format!(
|
||||
" Press 'h' for help | Connections: {} | Tab to switch views ",
|
||||
connection_count
|
||||
);
|
||||
fn draw_status_bar(f: &mut Frame, ui_state: &UIState, connection_count: usize, area: Rect) {
|
||||
let status = if ui_state.quit_confirmation {
|
||||
" Press 'q' again to quit or any other key to cancel ".to_string()
|
||||
} else {
|
||||
format!(
|
||||
" Press 'h' for help | Connections: {} | Tab to switch views ",
|
||||
connection_count
|
||||
)
|
||||
};
|
||||
|
||||
let style = if ui_state.quit_confirmation {
|
||||
Style::default().fg(Color::Black).bg(Color::Yellow)
|
||||
} else {
|
||||
Style::default().fg(Color::White).bg(Color::Blue)
|
||||
};
|
||||
|
||||
let status_bar = Paragraph::new(status)
|
||||
.style(Style::default().fg(Color::White).bg(Color::Blue))
|
||||
.style(style)
|
||||
.alignment(ratatui::layout::Alignment::Left);
|
||||
|
||||
f.render_widget(status_bar, area);
|
||||
|
||||
Reference in New Issue
Block a user