Added history callback

This commit is contained in:
Justine
2022-12-07 17:37:39 +01:00
parent 8a2b1f7cce
commit 2cbe00a98b
2 changed files with 26 additions and 5 deletions

View File

@ -149,18 +149,38 @@ fn get_hist_from_number(number: &i32) -> Option<String> {
}
}
fn treat_history_callback(line: &str) -> Option<String> {
let mut mystring = String::from(line);
mystring = mystring.trim().to_string();
let mut chars = mystring.chars();
//Skip the !
chars.next();
let mynbr: i32 = chars.as_str().parse().unwrap();
get_hist_from_number(&mynbr)
}
fn main(){
loop {
print!("> ");
stdout().flush();
//stdout().flush();
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
write_to_history(&input);
if process_line(input) {
return
if input.starts_with("!") {
let command_found = treat_history_callback(&input);
match command_found {
Some(c) => {
write_to_history(&c);
process_line(c);
},
None => ()
};
} else {
write_to_history(&input);
if process_line(input) {
return
}
}
}
}