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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -53,6 +53,7 @@ pub fn get_history() -> Result<String, std::io::Error> {
|
||||
let myline = format!("\r\n{}", line.unwrap());
|
||||
res.push_str(&myline);
|
||||
}
|
||||
res.push_str("\r\n");
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
|
42
src/shell/prompt.rs
Normal file
42
src/shell/prompt.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use users::{get_user_by_uid, get_current_uid};
|
||||
use termion::color;
|
||||
use std::env;
|
||||
|
||||
pub fn build_prompt(curr_number: &i32) -> String {
|
||||
|
||||
let user = String::from(
|
||||
get_user_by_uid(get_current_uid())
|
||||
.unwrap()
|
||||
.name()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let host = String::from(
|
||||
gethostname::gethostname()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let current_dir = String::from(
|
||||
env::current_dir()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let s = current_dir.split('/');
|
||||
let dir_last = String::from(
|
||||
s.last()
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let prompt = String::from(format!("{}{}{}[{}@{} in {}]{} ",
|
||||
color::Fg(color::LightBlack),
|
||||
curr_number,
|
||||
color::Fg(color::LightCyan),
|
||||
user, host, dir_last,
|
||||
color::Fg(color::Reset)));
|
||||
return prompt;
|
||||
}
|
||||
|
Reference in New Issue
Block a user