mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-28 13:51:41 +00:00
fix(config): simplify debug messages
This commit is contained in:
parent
6bcb1d6579
commit
38e4f0f03d
@ -416,75 +416,40 @@ pub fn merge_bindings<K>(
|
||||
source: BindingSource,
|
||||
) -> (Bindings<K>, 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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user