diff options
author | Canop <cano.petrole@gmail.com> | 2021-08-12 16:46:10 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-08-12 16:46:10 +0200 |
commit | ee354f9a7a2684783456b10707462f71045b1c3e (patch) | |
tree | b9618e61403db32d331d98e7c88fd0f0d01181c0 /src/verb/verb_store.rs | |
parent | c9b840fd85e7eb6393dbb52f4ba3b35cf2f831e7 (diff) |
allow a verb in configuration to refer to a builtin
Fix #432
Diffstat (limited to 'src/verb/verb_store.rs')
-rw-r--r-- | src/verb/verb_store.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/verb/verb_store.rs b/src/verb/verb_store.rs index ff139e6..b7db794 100644 --- a/src/verb/verb_store.rs +++ b/src/verb/verb_store.rs @@ -11,7 +11,6 @@ use { keys, }, crossterm::event::KeyEvent, - std::convert::TryFrom, }; /// Provide access to the verbs: @@ -21,7 +20,6 @@ use { /// When the user types some keys, we select a verb /// - if the input exactly matches a shortcut or the name /// - if only one verb name starts with the input -#[derive(Default)] pub struct VerbStore { pub verbs: Vec<Verb>, } @@ -34,14 +32,22 @@ pub enum PrefixSearchResult<'v, T> { } impl VerbStore { - pub fn init(&mut self, conf: &mut Conf) -> Result<(), ConfError> { - // We first add the verbs coming from configuration, as we'll search in order. - // This way, a user can overload a standard verb. + pub fn new(conf: &mut Conf) -> Result<Self, ConfError> { + // we start with the builtin verbs so that a verb from configuration + // can refer to a built-in + let mut verbs = builtin_verbs(); + for vc in &conf.verbs { - self.verbs.push(Verb::try_from(vc)?); + let verb = vc.make_verb(&verbs)?; + verbs.push(verb); } - self.verbs.extend(builtin_verbs()); - Ok(()) + + // We reverse the array as we'll search in order. + // This way, a user can overload a standard verb, or a standard + // shortcut. + verbs.reverse(); + + Ok(Self { verbs }) } pub fn search_sel_info<'v>( |