Added history callback
This commit is contained in:
28
src/main.rs
28
src/main.rs
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user