From a9fca843ede4512c8b1a5e389b4359a93dd5a644 Mon Sep 17 00:00:00 2001 From: lalvarezt Date: Fri, 25 Jul 2025 09:50:35 +0200 Subject: [PATCH] refactor(help_panel): bring back channel/remote keybinging awareness --- television/screen/help_panel.rs | 111 +++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/television/screen/help_panel.rs b/television/screen/help_panel.rs index 6d5a99b..9fdc5a9 100644 --- a/television/screen/help_panel.rs +++ b/television/screen/help_panel.rs @@ -53,6 +53,102 @@ pub fn draw_help_panel( f.render_widget(paragraph, area); } +/// Checks if an action is relevant for the given mode +fn is_action_relevant_for_mode(action: &Action, mode: Mode) -> bool { + match mode { + Mode::Channel => { + // Channel mode - all actions except those specifically for remote mode switching + match action { + // Input actions - available in both modes + Action::AddInputChar(_) + | Action::DeletePrevChar + | Action::DeletePrevWord + | Action::DeleteNextChar + | Action::DeleteLine + | Action::GoToPrevChar + | Action::GoToNextChar + | Action::GoToInputStart + | Action::GoToInputEnd + // Navigation actions - available in both modes + | Action::SelectNextEntry + | Action::SelectPrevEntry + | Action::SelectNextPage + | Action::SelectPrevPage + // Selection actions - channel specific (multi-select) + | Action::ToggleSelectionDown + | Action::ToggleSelectionUp + | Action::ConfirmSelection + // Preview actions - channel specific + | Action::ScrollPreviewUp + | Action::ScrollPreviewDown + | Action::ScrollPreviewHalfPageUp + | Action::ScrollPreviewHalfPageDown + | Action::TogglePreview + // Channel-specific actions + | Action::CopyEntryToClipboard + | Action::ReloadSource + | Action::CycleSources + | Action::SelectPrevHistory + | Action::SelectNextHistory + // UI toggles - global + | Action::ToggleRemoteControl + | Action::ToggleHelp + | Action::ToggleStatusBar + // Application actions - global + | Action::Quit => true, + + // Skip actions not relevant to help or internal actions + Action::NoOp + | Action::Render + | Action::Resize(_, _) + | Action::ClearScreen + | Action::Tick + | Action::Suspend + | Action::Resume + | Action::Error(_) + | Action::OpenEntry + | Action::SwitchToChannel(_) + | Action::WatchTimer + | Action::SelectEntryAtPosition(_, _) + | Action::MouseClickAt(_, _) + | Action::ToggleSendToChannel + | Action::SelectAndExit => false, + } + } + Mode::RemoteControl => { + // Remote control mode - limited set of actions + match action { + // Input actions - available in both modes + Action::AddInputChar(_) + | Action::DeletePrevChar + | Action::DeletePrevWord + | Action::DeleteNextChar + | Action::DeleteLine + | Action::GoToPrevChar + | Action::GoToNextChar + | Action::GoToInputStart + | Action::GoToInputEnd + // Navigation actions - available in both modes + | Action::SelectNextEntry + | Action::SelectPrevEntry + | Action::SelectNextPage + | Action::SelectPrevPage + // Selection in remote mode - just confirm (no multi-select) + | Action::ConfirmSelection + // UI toggles - global + | Action::ToggleRemoteControl + | Action::ToggleHelp + | Action::ToggleStatusBar + // Application actions - global + | Action::Quit => true, + + // All other actions not relevant in remote control mode + _ => false, + } + } + } +} + /// Adds keybinding lines for specific keys to the given lines vector fn add_keybinding_lines_for_keys( lines: &mut Vec>, @@ -67,6 +163,10 @@ fn add_keybinding_lines_for_keys( for (key, actions) in keybindings.iter() { for action in actions.as_slice() { // Filter out NoOp actions (unbound keys) + // Filter out actions not relevant for current mode + if matches!(action, Action::NoOp) + || !is_action_relevant_for_mode(action, mode) + { continue; } @@ -104,9 +204,14 @@ fn generate_help_content( debug!("Generating help content for mode: {:?}", mode); - // Global keybindings section header + // Mode-specific keybindings section header + let mode_name = match mode { + Mode::Channel => "Channel Mode", + Mode::RemoteControl => "Remote Control Mode", + }; + lines.push(Line::from(vec![Span::styled( - "Global", + mode_name, Style::default() .fg(colorscheme.help.metadata_field_name_fg) .bold() @@ -118,7 +223,7 @@ fn generate_help_content( &config.keybindings, mode, colorscheme, - "Global", + mode_name, ); debug!("Generated help content with {} total lines", lines.len());