From 38e4f0f03d256dfed7997af56fb5eb675e9d4285 Mon Sep 17 00:00:00 2001 From: lalvarezt Date: Thu, 24 Jul 2025 18:23:29 +0200 Subject: [PATCH] fix(config): simplify debug messages --- television/config/keybindings.rs | 43 +++------------------------- television/config/mod.rs | 48 ++++---------------------------- 2 files changed, 10 insertions(+), 81 deletions(-) diff --git a/television/config/keybindings.rs b/television/config/keybindings.rs index 4ed464c..185cd42 100644 --- a/television/config/keybindings.rs +++ b/television/config/keybindings.rs @@ -416,75 +416,40 @@ pub fn merge_bindings( source: BindingSource, ) -> (Bindings, KeybindingSource) where - K: Display + FromStr + Clone + Eq + Hash, + K: Display + FromStr + Clone + Eq + Hash + std::fmt::Debug, K::Err: Display, { - use tracing::{debug, trace}; - let mut keybinding_source = KeybindingSource::default(); - debug!( - "Starting merge_bindings: {} existing bindings, {} new {} bindings", - bindings.bindings.len(), - new_bindings.bindings.len(), - source.as_str() - ); + debug!("bindings before: {:?}", bindings.bindings); // Mark existing keys as global for key in bindings.bindings.keys() { if let Ok(tv_key) = Key::from_str(&key.to_string()) { keybinding_source.add_global_key(tv_key); - trace!("Marked existing key '{}' as global", key); } } // Merge new bindings and mark them based on source type - let mut merged_count = 0; - let mut override_count = 0; - for (key, actions) in &new_bindings.bindings { - let was_existing = bindings.bindings.contains_key(key); bindings.bindings.insert(key.clone(), actions.clone()); - merged_count += 1; if let Ok(tv_key) = Key::from_str(&key.to_string()) { match source { BindingSource::Channel => { keybinding_source.add_channel_key(tv_key); // Remove from global keys if it was there (override) - if keybinding_source.global_keys.remove(&tv_key) { - override_count += 1; - trace!( - "Channel key '{}' overrode global binding", - key - ); - } else { - trace!("Added new channel key '{}'", key); - } + keybinding_source.global_keys.remove(&tv_key); } BindingSource::Global => { // New bindings are global - add to global keys keybinding_source.add_global_key(tv_key); - if was_existing { - trace!( - "Global key '{}' overrode existing binding", - key - ); - } else { - trace!("Added new global key '{}'", key); - } } } } } - debug!( - "Merge completed: {} keys merged ({} overrides), final tracking: {} global, {} channel", - merged_count, - override_count, - keybinding_source.global_keys.len(), - keybinding_source.channel_keys.len() - ); + debug!("bindings after: {:?}", bindings.bindings); (bindings, keybinding_source) } diff --git a/television/config/mod.rs b/television/config/mod.rs index 4893927..7c24c67 100644 --- a/television/config/mod.rs +++ b/television/config/mod.rs @@ -2,6 +2,7 @@ use crate::{ cable::CABLE_DIR_NAME, channels::prototypes::{DEFAULT_PROTOTYPE_NAME, Template, UiSpec}, cli::PostProcessedCli, + event::Key, history::DEFAULT_HISTORY_SIZE, }; use anyhow::{Context, Result}; @@ -271,23 +272,13 @@ impl Config { /// /// CLI overrides preserve the original source of the key: /// - If overriding a global key → keep it in global list - /// - If overriding a channel key → keep it in channel list + /// - If overriding a channel key → keep it in channel list /// - If adding a new key → add to global list (CLI is user's global preference) pub fn apply_cli_keybinding_overrides( &mut self, cli_keybindings: &KeyBindings, ) { - use tracing::{debug, trace}; - - debug!( - "Applying {} CLI keybinding overrides", - cli_keybindings.len() - ); - - let mut override_count = 0; - let mut new_key_count = 0; - let mut preserved_global = 0; - let mut preserved_channel = 0; + debug!("keybindings before: {:?}", self.keybindings); for (key, actions) in &cli_keybindings.bindings { let was_existing = self.keybindings.contains_key(key); @@ -295,42 +286,15 @@ impl Config { // Update the keybinding self.keybindings.insert(*key, actions.clone()); - if let Ok(tv_key) = crate::event::Key::from_str(&key.to_string()) { - if was_existing { - override_count += 1; - // Preserve existing source categorization - if self.keybinding_source.is_global_key(&tv_key) { - // Key was already global, keep it global - preserved_global += 1; - trace!("CLI override preserved global key: '{}'", key); - } else if self.keybinding_source.is_channel_key(&tv_key) { - // Key was channel-specific, keep it channel-specific - preserved_channel += 1; - trace!( - "CLI override preserved channel key: '{}'", - key - ); - } else { - // Key exists in keybindings but not tracked in source - treat as global - self.keybinding_source.add_global_key(tv_key); - trace!( - "CLI override added untracked existing key '{}' to global", - key - ); - } - } else { + if let Ok(tv_key) = Key::from_str(&key.to_string()) { + if !was_existing { // New key from CLI - add to global (CLI is user's global preference) - new_key_count += 1; self.keybinding_source.add_global_key(tv_key); - trace!("CLI override added new global key: '{}'", key); } } } - debug!( - "CLI override completed: {} overrides ({} preserved global, {} preserved channel), {} new keys", - override_count, preserved_global, preserved_channel, new_key_count - ); + debug!("keybindings after: {:?}", self.keybindings); } pub fn merge_event_bindings(&mut self, other: &EventBindings) {