Autocomplete works for files

This commit is contained in:
Justine Pelletreau
2023-02-02 16:51:52 +01:00
parent f7e6063778
commit 4e27fe3106
2 changed files with 84 additions and 3 deletions

View File

@ -236,6 +236,12 @@ pub mod shell {
let mut current_pos: usize = 0;
let mut max_pos: usize = 0;
//Used to keep the result of the last autocomplete
//Next time we press tab we get a different result so that we can
//rotate between files in the dir for example
//Resetted by pressing enter
let mut prev_autocomplete = String::new();
//Initialize
write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", prompt);
stdout.flush();
@ -244,7 +250,13 @@ pub mod shell {
match c.unwrap() {
Key::Char('\t') => {
let (res, list) = autocomplete(&mycommand);
//Do NOT search on an empty command
if *&mycommand.len() == 0 {
continue;
}
//Search
let (res, list) = autocomplete(&mycommand, &prev_autocomplete);
*&mut prev_autocomplete = String::from(res.as_str());
write!(stdout, "\r\n{}\r\n", list);
mycommand.clear();
mycommand.push_str(&res);
@ -255,6 +267,7 @@ pub mod shell {
}
Key::Char('\n') => {
*&mut prev_autocomplete = String::new();
current_number = get_curr_history_number();
prompt = build_prompt(&current_number);
current_pos = 0;