fix: opts spacing

This commit is contained in:
iff 2025-01-07 01:16:54 +01:00
parent e53c61cb59
commit 87be5ffacb
5 changed files with 26 additions and 7 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- Wrong starting distance when including all candidates
- Spacings for `opt` placeholder
## [0.6.9] - 2025-01-06 ## [0.6.9] - 2025-01-06
### Added ### Added

View file

@ -30,7 +30,14 @@ pub fn opts(suggest: &mut String, last_command: &mut String, opt_list: &mut Vec<
let regex = opt.trim(); let regex = opt.trim();
let current_tag = tag(tag_name, replace_tag); let current_tag = tag(tag_name, replace_tag);
let opts = format!(" {}", opt_regex(regex, last_command)); let opts = {
let caps = opt_regex(regex, last_command);
if caps.is_empty() {
"".to_string()
} else {
format!(" {}", caps)
}
};
opt_list.push((current_tag.clone(), opts)); opt_list.push((current_tag.clone(), opts));
suggest.replace_range(placeholder, &current_tag); suggest.replace_range(placeholder, &current_tag);

View file

@ -42,10 +42,17 @@ pub fn opts(
let regex = opt.trim(); let regex = opt.trim();
let current_tag = tag(tag_name, replace_tag); let current_tag = tag(tag_name, replace_tag);
let token_tag: TokenStream2 = format!("{}{}", tag_name, replace_tag).parse().unwrap(); let token_tag: TokenStream2 = format!("{}{}", tag_name, replace_tag).parse().unwrap();
let command = quote! { let opts = quote! {
let #token_tag = format!(" {}", opt_regex(#regex, &mut last_command)); let caps = opt_regex(#regex, &mut last_command);
let #token_tag = {
if caps.is_empty() {
"".to_string()
} else {
format!(" {}", caps)
}
};
}; };
opt_list.push(command); opt_list.push(opts);
replace_list.push(rtag(tag_name, replace_tag, &current_tag)); replace_list.push(rtag(tag_name, replace_tag, &current_tag));
suggest.replace_range(placeholder, &current_tag); suggest.replace_range(placeholder, &current_tag);

View file

@ -17,6 +17,6 @@ suggest = [
''' '''
#[err_contains(no such file or directory)] #[err_contains(no such file or directory)]
mkdir -p {{cmd::(?m)\s(\S+[\\\/])\S*\s*$}} && \ mkdir -p {{cmd::(?m)\s(\S+[\\\/])\S*\s*$}} && \
{{command[0]}} {{opt::\s(-[\w]+)}} {{command[1:]}} ''' {{command[0]}} {{opt::(?:\s)(-[\w]+)}} {{command[1:]}} '''
] ]

View file

@ -3,8 +3,8 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::files::*; use crate::files::*;
use regex_lite::Regex;
use itertools::Itertools; use itertools::Itertools;
use regex_lite::Regex;
fn regex_captures(regex: &str, string: &str) -> Vec<String> { fn regex_captures(regex: &str, string: &str) -> Vec<String> {
let regex = Regex::new(regex).unwrap(); let regex = Regex::new(regex).unwrap();
@ -158,7 +158,7 @@ pub fn find_similars(
if !min_distance_index.is_empty() { if !min_distance_index.is_empty() {
min_distance_index.push(i) min_distance_index.push(i)
} }
}, }
Less => { Less => {
min_distance = distance; min_distance = distance;
min_distance_index.clear(); min_distance_index.clear();