mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
fix: runtime opts
This commit is contained in:
parent
4323926c77
commit
3ce7918e35
2 changed files with 19 additions and 4 deletions
|
|
@ -1,5 +1,9 @@
|
|||
use crate::suggestions::*;
|
||||
|
||||
fn tag(name: &str, x: i32) -> String {
|
||||
format!("{{{}{}}}", name, x)
|
||||
}
|
||||
|
||||
pub fn eval_placeholder(
|
||||
string: &str,
|
||||
start: &str,
|
||||
|
|
@ -15,15 +19,21 @@ pub fn eval_placeholder(
|
|||
(placeholder, args)
|
||||
}
|
||||
|
||||
pub fn opts(suggest: &mut String, last_command: &mut String) {
|
||||
pub fn opts(suggest: &mut String, last_command: &mut String, opt_list: &mut Vec<(String, String)>) {
|
||||
let mut replace_tag = 0;
|
||||
let tag_name = "opts";
|
||||
|
||||
while suggest.contains("{{opt::") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{opt::", "}}");
|
||||
|
||||
let opt = &suggest[args.to_owned()];
|
||||
let regex = opt.trim();
|
||||
let current_tag = tag(tag_name, replace_tag);
|
||||
|
||||
let command = opt_regex(regex, last_command);
|
||||
suggest.replace_range(placeholder, &command)
|
||||
opt_list.push((current_tag.clone(), opt_regex(regex, last_command)));
|
||||
suggest.replace_range(placeholder, ¤t_tag);
|
||||
|
||||
replace_tag += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -164,13 +164,18 @@ fn eval_suggest(
|
|||
}
|
||||
|
||||
let mut last_command = last_command.to_owned();
|
||||
let mut opt_list = Vec::new();
|
||||
|
||||
replaces::opts(&mut suggest, &mut last_command);
|
||||
replaces::opts(&mut suggest, &mut last_command, &mut opt_list);
|
||||
replaces::cmd_reg(&mut suggest, &mut last_command);
|
||||
replaces::err(&mut suggest, error_msg);
|
||||
replaces::command(&mut suggest, split_command);
|
||||
replaces::shell(&mut suggest, shell);
|
||||
replaces::typo(&mut suggest, split_command, shell);
|
||||
|
||||
for (tag, value) in opt_list {
|
||||
suggest = suggest.replace(&tag, &value);
|
||||
}
|
||||
|
||||
Some(suggest)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue