"Ctrl + P and O more or less do the same thing as Ctrl + Right and left

Also remove a warning about a useless mut"
This commit is contained in:
Justine
2023-02-22 16:03:51 +01:00
parent d903bb4bc8
commit 6f63294857
3 changed files with 43 additions and 2 deletions

View File

@ -314,6 +314,27 @@ pub mod shell {
};
}
fn find_next_space(current_pos: &usize, max_pos: &usize, command: &String) -> usize {
let mut steps: usize = 0;
if *current_pos == *max_pos { return steps; }
for letter in command.chars().skip(*current_pos) {
//println!("L : {:?}, S : {:?} C: {:?} M {:?}", letter, steps, current_pos, max_pos);
//Skip if we start on a space
if steps == 0 && (letter == ' ' || letter == ',' || letter == ';') {
continue;
} else if letter != ' ' && *current_pos + steps < *max_pos {
steps += 1;
} else {
return steps;
}
}
let max: usize = (0 + max_pos) - current_pos;
return max;
}
pub fn run_raw() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
@ -523,6 +544,25 @@ pub mod shell {
current_pos += 1;
}
},
Key::Ctrl('p') => {
let steps = find_next_space(&current_pos, &max_pos, &mycommand);
//println!("steps: {:?} cur {:?} max {:?}", steps, current_pos, max_pos);
if steps > 0 {
print!("{}", cursor::Right(steps as u16));
current_pos += steps;
}
},
Key::Ctrl('o') => {
let command_rev = mycommand.chars().rev().collect::<String>();
let curr_rev = max_pos - current_pos + 1;
let steps = find_next_space(&curr_rev, &max_pos, &command_rev);
if steps > 0 {
print!("{}", cursor::Left(steps as u16));
current_pos -= steps;
}
},
Key::Alt(x) => {
match x {

View File

@ -94,7 +94,7 @@ 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);
let mystring = String::from(line);
let temp = mystring.split_whitespace().collect::<Vec<&str>>();
let mystring = temp.first().unwrap_or(&line);
let mut chars = mystring.chars();