Autocomplete fonctionne
This commit is contained in:
@ -1,8 +1,50 @@
|
||||
pub fn autocomplete(input: &String) -> String {
|
||||
use which::which_re;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn autocomplete(input: &String) -> (String, String) {
|
||||
let faketab = format!(" --This is a fake output for autocomplete from {input}-- ");
|
||||
//In reality, we would keep the input and append to it
|
||||
let aaa = String::from(faketab);
|
||||
return aaa;
|
||||
|
||||
let found_bins = find_bin(input);
|
||||
if found_bins.len() == 1 {
|
||||
let aaa = found_bins.clone();
|
||||
let bbb = &aaa[0]
|
||||
.iter()
|
||||
.last()
|
||||
.unwrap();
|
||||
let res_string = String::from(bbb.to_str().unwrap());
|
||||
let res_list = res_string.clone();
|
||||
return (res_string, res_list);
|
||||
} else if found_bins.len() == 0 {
|
||||
let list = String::from("Nothing adequate.");
|
||||
let res = String::from(input);
|
||||
return (res, list);
|
||||
} else {
|
||||
let mut all_res = String::new();
|
||||
for path in found_bins {
|
||||
let buff = String::from(path
|
||||
.iter()
|
||||
.last()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap());
|
||||
let res_line = format!("* {}\r\n", buff);
|
||||
all_res.push_str(&res_line);
|
||||
}
|
||||
let first_res = String::from(input);
|
||||
return(first_res, all_res)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
///Takes a string and returns a Vector of PathBuf containing all matchings
|
||||
///commands
|
||||
fn find_bin(command: &String) -> Vec<PathBuf> {
|
||||
let re = format!("^{}.*", command);
|
||||
let re = Regex::new(&re).unwrap();
|
||||
let binaries: Vec<PathBuf> = which_re(re).unwrap().collect();
|
||||
return binaries;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user