History callbacks now allow piping

This commit is contained in:
Justine Pelletreau
2023-02-21 16:44:31 +01:00
parent 6fa2788161
commit c06afb410c
3 changed files with 16 additions and 5 deletions

View File

@ -20,6 +20,8 @@ pub fn write_to_history(command: &str) -> Result<(), std::io::Error> {
Err(_) => 1
};
let command = command.replace('\n', "\\n");
writeln!(file, "{} {}", number, command.trim())?;
return Ok(())
}
@ -93,12 +95,17 @@ pub fn get_hist_from_number(number: &i32) -> Option<String> {
pub fn treat_history_callback(line: &str) -> Option<String> {
let mut mystring = String::from(line);
mystring = mystring.trim().to_string();
let temp = mystring.split_whitespace().collect::<Vec<&str>>();
let mystring = temp.first().unwrap_or(&line);
let mut chars = mystring.chars();
let args = &temp[1..];
//Skip the !
chars.next();
let mynbr: i32 = chars.as_str().parse().unwrap();
get_hist_from_number(&mynbr)
match get_hist_from_number(&mynbr) {
Some(h) => return Some(format!("{} {}", h, args.join(" "))),
None => return None,
}
}
pub fn get_prev_arg() -> Option<String> {