@@ -462,12 +462,14 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
462462 // Tab navigation (forward)
463463 ( KeyCode :: Tab , KeyModifiers :: NONE ) => {
464464 ui_state. quit_confirmation = false ;
465+ ui_state. clear_confirmation = false ;
465466 ui_state. selected_tab = ( ui_state. selected_tab + 1 ) % 5 ;
466467 }
467468
468469 // Shift+Tab navigation (backward)
469470 ( KeyCode :: BackTab , _) | ( KeyCode :: Tab , KeyModifiers :: SHIFT ) => {
470471 ui_state. quit_confirmation = false ;
472+ ui_state. clear_confirmation = false ;
471473 ui_state. selected_tab = if ui_state. selected_tab == 0 {
472474 4 // Wrap to last tab
473475 } else {
@@ -478,6 +480,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
478480 // Help toggle
479481 ( KeyCode :: Char ( 'h' ) , _) => {
480482 ui_state. quit_confirmation = false ;
483+ ui_state. clear_confirmation = false ;
481484 ui_state. show_help = !ui_state. show_help ;
482485 if ui_state. show_help {
483486 ui_state. selected_tab = 4 ; // Switch to help tab
@@ -489,6 +492,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
489492 // Interface stats toggle (shortcut to Interface tab)
490493 ( KeyCode :: Char ( 'i' ) , _) | ( KeyCode :: Char ( 'I' ) , _) => {
491494 ui_state. quit_confirmation = false ;
495+ ui_state. clear_confirmation = false ;
492496 if ui_state. selected_tab == 2 {
493497 ui_state. selected_tab = 0 ; // Back to overview
494498 } else {
@@ -499,6 +503,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
499503 // Navigation in connection list
500504 ( KeyCode :: Up , _) | ( KeyCode :: Char ( 'k' ) , _) => {
501505 ui_state. quit_confirmation = false ;
506+ ui_state. clear_confirmation = false ;
502507 // Use the SAME sorted connections list from the main loop
503508 // to ensure index consistency with the displayed table
504509 debug ! ( "Navigation UP: {} connections available" , connections. len( ) ) ;
@@ -507,6 +512,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
507512
508513 ( KeyCode :: Down , _) | ( KeyCode :: Char ( 'j' ) , _) => {
509514 ui_state. quit_confirmation = false ;
515+ ui_state. clear_confirmation = false ;
510516 // Use the SAME sorted connections list from the main loop
511517 // to ensure index consistency with the displayed table
512518 debug ! (
@@ -519,13 +525,15 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
519525 // Page Up/Down navigation
520526 ( KeyCode :: PageUp , _) => {
521527 ui_state. quit_confirmation = false ;
528+ ui_state. clear_confirmation = false ;
522529 // Use the SAME sorted connections list from the main loop
523530 // Move up by roughly 10 items (or adjust based on terminal height)
524531 ui_state. move_selection_page_up ( & connections, 10 ) ;
525532 }
526533
527534 ( KeyCode :: PageDown , _) => {
528535 ui_state. quit_confirmation = false ;
536+ ui_state. clear_confirmation = false ;
529537 // Use the SAME sorted connections list from the main loop
530538 // Move down by roughly 10 items (or adjust based on terminal height)
531539 ui_state. move_selection_page_down ( & connections, 10 ) ;
@@ -534,19 +542,22 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
534542 // Vim-style jump to first/last (g/G)
535543 ( KeyCode :: Char ( 'g' ) , KeyModifiers :: NONE ) => {
536544 ui_state. quit_confirmation = false ;
545+ ui_state. clear_confirmation = false ;
537546 // Jump to first connection (vim-style 'g')
538547 ui_state. move_selection_to_first ( & connections) ;
539548 }
540549
541550 ( KeyCode :: Char ( 'G' ) , _) | ( KeyCode :: Char ( 'g' ) , KeyModifiers :: SHIFT ) => {
542551 ui_state. quit_confirmation = false ;
552+ ui_state. clear_confirmation = false ;
543553 // Jump to last connection (vim-style 'G')
544554 ui_state. move_selection_to_last ( & connections) ;
545555 }
546556
547557 // Enter to view details
548558 ( KeyCode :: Enter , _) => {
549559 ui_state. quit_confirmation = false ;
560+ ui_state. clear_confirmation = false ;
550561 if ui_state. selected_tab == 0 && !connections. is_empty ( ) {
551562 ui_state. selected_tab = 1 ; // Switch to details view
552563 }
@@ -555,6 +566,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
555566 // Toggle port number display
556567 ( KeyCode :: Char ( 'p' ) , _) => {
557568 ui_state. quit_confirmation = false ;
569+ ui_state. clear_confirmation = false ;
558570 ui_state. show_port_numbers = !ui_state. show_port_numbers ;
559571 info ! (
560572 "Toggled port display: {}" ,
@@ -570,6 +582,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
570582 ( KeyCode :: Char ( 'd' ) , _) => {
571583 if app. is_dns_resolution_enabled ( ) {
572584 ui_state. quit_confirmation = false ;
585+ ui_state. clear_confirmation = false ;
573586 ui_state. show_hostnames = !ui_state. show_hostnames ;
574587 info ! (
575588 "Toggled hostname display: {}" ,
@@ -585,6 +598,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
585598 // Cycle sort column with 's'
586599 ( KeyCode :: Char ( 's' ) , KeyModifiers :: NONE ) => {
587600 ui_state. quit_confirmation = false ;
601+ ui_state. clear_confirmation = false ;
588602 ui_state. cycle_sort_column ( ) ;
589603 info ! (
590604 "Sort column: {} ({})" ,
@@ -600,6 +614,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
600614 // Toggle sort direction with 'S' (Shift+s)
601615 ( KeyCode :: Char ( 'S' ) , _) => {
602616 ui_state. quit_confirmation = false ;
617+ ui_state. clear_confirmation = false ;
603618 ui_state. toggle_sort_direction ( ) ;
604619 info ! (
605620 "Sort direction: {} ({})" ,
@@ -615,6 +630,7 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
615630 // Copy remote address to clipboard
616631 ( KeyCode :: Char ( 'c' ) , _) => {
617632 ui_state. quit_confirmation = false ;
633+ ui_state. clear_confirmation = false ;
618634 if let Some ( selected_idx) = ui_state. get_selected_index ( & connections)
619635 && let Some ( conn) = connections. get ( selected_idx)
620636 {
@@ -671,9 +687,28 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
671687 }
672688 }
673689
690+ // Clear all connections with confirmation
691+ ( KeyCode :: Char ( 'x' ) , _) => {
692+ ui_state. quit_confirmation = false ;
693+ if ui_state. clear_confirmation {
694+ info ! ( "User confirmed clear all connections" ) ;
695+ app. clear_all_connections ( ) ;
696+ ui_state. clear_confirmation = false ;
697+ ui_state. selected_connection_key = None ;
698+ ui_state. clipboard_message = Some ( (
699+ "All connections cleared" . to_string ( ) ,
700+ std:: time:: Instant :: now ( ) ,
701+ ) ) ;
702+ } else {
703+ info ! ( "User requested clear - showing confirmation" ) ;
704+ ui_state. clear_confirmation = true ;
705+ }
706+ }
707+
674708 // Escape to go back or clear filter
675709 ( KeyCode :: Esc , _) => {
676710 ui_state. quit_confirmation = false ;
711+ ui_state. clear_confirmation = false ;
677712 if !ui_state. filter_query . is_empty ( ) {
678713 // Clear filter if one is active
679714 ui_state. clear_filter ( ) ;
@@ -684,9 +719,10 @@ fn run_ui_loop<B: ratatui::prelude::Backend>(
684719 }
685720 }
686721
687- // Any other key resets quit confirmation
722+ // Any other key resets confirmations
688723 _ => {
689724 ui_state. quit_confirmation = false ;
725+ ui_state. clear_confirmation = false ;
690726 }
691727 }
692728 }
0 commit comments