diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/io.rs | 39 | ||||
| -rw-r--r-- | src/config/keybinds.rs | 15 | ||||
| -rw-r--r-- | src/config/model.rs | 7 |
3 files changed, 37 insertions, 24 deletions
diff --git a/src/config/io.rs b/src/config/io.rs index 12176815..3b483ba6 100644 --- a/src/config/io.rs +++ b/src/config/io.rs @@ -92,17 +92,22 @@ pub fn config_path() -> PathBuf { } pub fn config_diagnostic_summary(diagnostics: &[String]) -> Option<String> { + const MAX_VISIBLE_DIAGNOSTICS: usize = 4; + if diagnostics.is_empty() { - None - } else if diagnostics.len() == 1 { - Some(diagnostics[0].clone()) - } else { - Some(format!( - "{} (and {} more)", - diagnostics[0], - diagnostics.len() - 1 - )) + return None; + } + + let mut lines: Vec<String> = diagnostics + .iter() + .take(MAX_VISIBLE_DIAGNOSTICS) + .map(|diagnostic| diagnostic.split_whitespace().collect::<Vec<_>>().join(" ")) + .collect(); + let hidden = diagnostics.len().saturating_sub(MAX_VISIBLE_DIAGNOSTICS); + if hidden > 0 { + lines.push(format!("and {hidden} more config warnings")); } + Some(lines.join("\n")) } pub fn load_live_config() -> Result<LoadedConfig, Vec<String>> { @@ -435,6 +440,22 @@ mod tests { } #[test] + fn config_diagnostic_summary_keeps_multiple_warnings_visible() { + let diagnostics = vec![ + "one".to_string(), + "two".to_string(), + "three".to_string(), + "four".to_string(), + "five".to_string(), + ]; + + assert_eq!( + config_diagnostic_summary(&diagnostics).as_deref(), + Some("one\ntwo\nthree\nfour\nand 1 more config warnings") + ); + } + + #[test] fn remove_keybinding_config_sections_removes_keys_tables_only() { let content = r#"onboarding = false diff --git a/src/config/keybinds.rs b/src/config/keybinds.rs index 58c26020..3a4cf754 100644 --- a/src/config/keybinds.rs +++ b/src/config/keybinds.rs @@ -245,7 +245,6 @@ pub struct CustomCommandKeybind { pub struct Keybinds { pub help: ActionKeybinds, pub settings: ActionKeybinds, - pub quit: ActionKeybinds, pub new_workspace: ActionKeybinds, pub rename_workspace: ActionKeybinds, pub close_workspace: ActionKeybinds, @@ -375,7 +374,6 @@ impl Config { let mut keybinds = Keybinds { help: action!("keys.help", &self.keys.help), settings: action!("keys.settings", &self.keys.settings), - quit: action!("keys.quit", &self.keys.quit), new_workspace: action!("keys.new_workspace", &self.keys.new_workspace), rename_workspace: action!("keys.rename_workspace", &self.keys.rename_workspace), close_workspace: action!("keys.close_workspace", &self.keys.close_workspace), @@ -619,10 +617,7 @@ fn reject_binding( } if let Some(first_field) = registry.conflict(binding) { - let diag = format!( - "duplicate keybinding: {field} = {:?} conflicts with {}; disabling binding", - binding.label, first_field - ); + let diag = format!("{}: kept {first_field}, disabled {field}", binding.label); warn!(message = %diag, "config diagnostic"); diagnostics.push(diag); return true; @@ -1232,7 +1227,7 @@ command = "echo no" assert!(!keybinds.new_tab.bindings.is_empty()); assert!(keybinds.custom_commands.is_empty()); assert!(diagnostics.iter().any(|diag| { - diag.contains("duplicate keybinding") && diag.contains("keys.command[0].key") + diag.contains("kept keys.new_tab") && diag.contains("disabled keys.command[0].key") })); } @@ -1296,8 +1291,8 @@ new_workspace = "prefix+n" let diagnostics = config.collect_diagnostics(); let kb = config.keybinds(); assert!(kb.next_tab.bindings.is_empty() || kb.new_workspace.bindings.is_empty()); - assert!(diagnostics - .iter() - .any(|diag| diag.contains("duplicate keybinding"))); + assert!(diagnostics.iter().any(|diag| { + diag.contains("kept keys.new_workspace") && diag.contains("disabled keys.next_tab") + })); } } diff --git a/src/config/model.rs b/src/config/model.rs index 10e80417..f0557072 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -98,8 +98,6 @@ pub struct KeysConfig { pub help: BindingConfig, /// Open settings. Default: "prefix+s" pub settings: BindingConfig, - /// Quit or detach. Default: "prefix+q" - pub quit: BindingConfig, /// Create a new workspace. Default: "prefix+shift+n" pub new_workspace: BindingConfig, /// Rename the selected workspace. Default: "prefix+shift+w" @@ -108,7 +106,7 @@ pub struct KeysConfig { pub close_workspace: BindingConfig, /// Open the workspace navigation surface. Default: "prefix+w" pub workspace_picker: BindingConfig, - /// Optional explicit detach shortcut in server/client mode. Default: "prefix+d". + /// Detach from server/client mode, or exit --no-session mode. Default: "prefix+q". pub detach: BindingConfig, /// Reload config.toml in the running app/server. Default: "prefix+shift+r". pub reload_config: BindingConfig, @@ -234,12 +232,11 @@ impl Default for KeysConfig { prefix: "ctrl+b".into(), help: BindingConfig::one("prefix+?"), settings: BindingConfig::one("prefix+s"), - quit: BindingConfig::one("prefix+q"), new_workspace: BindingConfig::one("prefix+shift+n"), rename_workspace: BindingConfig::one("prefix+shift+w"), close_workspace: BindingConfig::one("prefix+shift+d"), workspace_picker: BindingConfig::one("prefix+w"), - detach: BindingConfig::one("prefix+d"), + detach: BindingConfig::one("prefix+q"), reload_config: BindingConfig::one("prefix+shift+r"), open_notification_target: BindingConfig::one("prefix+o"), previous_workspace: BindingConfig::empty(), |
