diff options
author | Canop <cano.petrole@gmail.com> | 2024-05-31 17:11:34 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2024-05-31 17:11:34 +0200 |
commit | 7b892afb448e60fe698b3fb441d6ce469d2d5c6c (patch) | |
tree | 4d8baead521f079e1cd5eb6d75c6ecc10d1fc2ba | |
parent | 205015c2f3632466f137ec5fa17cc78dd6495423 (diff) | |
parent | 7cbd2d85a635a3ed80fb3ff8bbcd81ca3826cf95 (diff) |
Merge remote-tracking branch 'origin/main'
-rw-r--r-- | src/app/panel_state.rs | 3 | ||||
-rw-r--r-- | src/verb/verb_invocation.rs | 6 | ||||
-rw-r--r-- | src/verb/verb_store.rs | 67 |
3 files changed, 51 insertions, 25 deletions
diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index b003dc2..094c321 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -112,7 +112,7 @@ pub trait PanelState { .unwrap_or(internal_exec.bang); Ok(match internal_exec.internal { Internal::apply_flags => { - info!("applying flags input_invocation: {:#?}", input_invocation); + debug!("applying flags input_invocation: {:#?}", input_invocation); let flags = input_invocation.and_then(|inv| inv.args.as_ref()); if let Some(flags) = flags { self.with_new_options( @@ -1040,7 +1040,6 @@ pub trait PanelState { ) } else { let sel_info = self.sel_info(app_state); - info!("invocation: {:#?}", invocation); match cc.app.con.verb_store.search_sel_info( &invocation.name, sel_info, diff --git a/src/verb/verb_invocation.rs b/src/verb/verb_invocation.rs index 3831787..9e2b9bb 100644 --- a/src/verb/verb_invocation.rs +++ b/src/verb/verb_invocation.rs @@ -120,10 +120,8 @@ impl From<&str> for VerbInvocation { continue; } if name.is_empty() { - if c.is_alphabetic() { - name.push(c); - } else { - name.push(c); + name.push(c); + if !c.is_alphabetic() { name_is_special = true; } continue; diff --git a/src/verb/verb_store.rs b/src/verb/verb_store.rs index 4908b21..692d4e8 100644 --- a/src/verb/verb_store.rs +++ b/src/verb/verb_store.rs @@ -25,6 +25,7 @@ use { /// - if only one verb name starts with the input pub struct VerbStore { verbs: Vec<Verb>, + unbound_keys: Vec<KeyCombination>, } #[derive(Debug, Clone, PartialEq)] @@ -36,7 +37,7 @@ pub enum PrefixSearchResult<'v, T> { impl VerbStore { pub fn new(conf: &mut Conf) -> Result<Self, ConfError> { - let mut store = Self { verbs: Vec::new() }; + let mut store = Self { verbs: Vec::new(), unbound_keys: Vec::new() }; for vc in &conf.verbs { if let Err(e) = store.add_from_conf(vc) { eprintln!("Invalid verb configuration: {}", e); @@ -51,6 +52,9 @@ impl VerbStore { } } store.add_builtin_verbs()?; // at the end so that we can override them + for key in store.unbound_keys.clone() { + store.unbind_key(key)?; + } Ok(store) } @@ -402,6 +406,23 @@ impl VerbStore { details: "You can't simultaneously have leave_broot=false and from_shell=true".to_string(), }); } + + // we accept both key and keys. We merge both here + let mut unchecked_keys = vc.keys.clone(); + if let Some(key) = &vc.key { + unchecked_keys.push(key.clone()); + } + let mut checked_keys = Vec::new(); + for key in &unchecked_keys { + let key = crokey::parse(key)?; + if keys::is_reserved(key) { + return Err(ConfError::ReservedKey { + key: keys::KEY_FORMAT.to_string(key) + }); + } + checked_keys.push(key); + } + let invocation = vc.invocation.clone().filter(|i| !i.is_empty()); let internal = vc.internal.as_ref().filter(|i| !i.is_empty()); let external = vc.external.as_ref().filter(|i| !i.is_empty()); @@ -456,9 +477,12 @@ impl VerbStore { sequence: Sequence::new(s, cmd_separator), }), _ => { - return Err(ConfError::InvalidVerbConf { - details: "You must define either internal, external or cmd".to_string(), - }); + // there's no execution, this 'verbconf' is supposed to be dedicated to + // unbind keys + for key in checked_keys { + self.unbound_keys.push(key); + } + return Ok(()); } }; let description = vc @@ -471,21 +495,6 @@ impl VerbStore { execution, description, )?; - // we accept both key and keys. We merge both here - let mut unchecked_keys = vc.keys.clone(); - if let Some(key) = &vc.key { - unchecked_keys.push(key.clone()); - } - let mut checked_keys = Vec::new(); - for key in &unchecked_keys { - let key = crokey::parse(key)?; - if keys::is_reserved(key) { - return Err(ConfError::ReservedKey { - key: keys::KEY_FORMAT.to_string(key) - }); - } - checked_keys.push(key); - } for extension in &vc.extensions { verb.file_extensions.push(extension.clone()); } @@ -505,6 +514,26 @@ impl VerbStore { Ok(()) } + pub fn unbind_key( + &mut self, + key: KeyCombination, + ) -> Result<(), ConfError> { + debug!("unbinding key {:?}", key); + for verb in &mut self.verbs { + verb.keys.retain(|&k| k != key); + } + Ok(()) + } + pub fn unbind_name( + &mut self, + name: &str, + ) -> Result<(), ConfError> { + for verb in &mut self.verbs { + verb.names.retain(|n| n != name); + } + Ok(()) + } + pub fn search_sel_info<'v>( &'v self, prefix: &str, |