summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRory Dudley2024-09-21 21:40:54 -0600
committerRory Dudley2024-09-21 21:40:54 -0600
commit2590315b9e5280ca0c69cce35b4f4bea794790d4 (patch)
treea15e5fa57b5f7107c40a47ecbb5e04faac36d82b
parentda7aa5dbeb5e1c98c83fba10648b68962b614353 (diff)
downloaddwarvish-2590315b9e5280ca0c69cce35b4f4bea794790d4.tar.gz
Don't panic if autcomplete() fails
If, for whatever reason, the autocomplete() functions fails, don't panic and quit. Instead, return an empty string.
-rw-r--r--src/buffer.rs49
1 files changed, 4 insertions, 45 deletions
diff --git a/src/buffer.rs b/src/buffer.rs
index d41f883..c27946f 100644
--- a/src/buffer.rs
+++ b/src/buffer.rs
@@ -210,7 +210,8 @@ pub fn getline(buffer: &mut Arc<Mutex<Vec<u8>>>, pos: &mut Arc<Mutex<usize>>) ->
*pos.lock().unwrap() -= 1;
aulen -= 1;
}
- let (path, len) = autocomplete(buffer, auindex, &pwd).unwrap();
+ let (path, len) =
+ autocomplete(buffer, auindex, &pwd).unwrap_or(("".to_string(), 0));
for c in path.into_bytes().iter() {
buffer.lock().unwrap().insert(*pos.lock().unwrap(), *c);
*pos.lock().unwrap() += 1;
@@ -228,7 +229,8 @@ pub fn getline(buffer: &mut Arc<Mutex<Vec<u8>>>, pos: &mut Arc<Mutex<usize>>) ->
*pos.lock().unwrap() -= 1;
aulen -= 1;
}
- let (path, len) = autocomplete(buffer, auindex, &pwd).unwrap();
+ let (path, len) =
+ autocomplete(buffer, auindex, &pwd).unwrap_or(("".to_string(), 0));
for c in path.into_bytes().iter() {
buffer.lock().unwrap().insert(*pos.lock().unwrap(), *c);
*pos.lock().unwrap() += 1;
@@ -284,49 +286,6 @@ pub fn getline(buffer: &mut Arc<Mutex<Vec<u8>>>, pos: &mut Arc<Mutex<usize>>) ->
aulen = 0;
}
- // forward slash
- // b'/' => {
- // let mut buffer = buffer.lock().unwrap();
- //
- // match buffer.last() {
- // Some(c) if *c == b'/' => {}
- // Some(_) | None => {
- // buffer.insert(*pos.lock().unwrap(), b'/');
- // *pos.lock().unwrap() += 1;
- // print!("/");
- // }
- // }
- //
- // let word = match buffer.last() {
- // Some(c) if *c == b' ' => "".to_string(),
- // None => "".to_string(),
- // _ => {
- // let mut word: Vec<u8> = vec![];
- // for c in buffer.iter().rev() {
- // if *c == b' ' {
- // break;
- // }
- // word.push(*c);
- // }
- // word.reverse();
- // String::from_utf8_lossy(&mut word).to_string()
- // }
- // };
- //
- // // Check for the ~ character (used to represent $HOME)
- // let word = if word.starts_with("~") {
- // let home = env!("HOME");
- // format!("{}{}", home, &word[1..]).to_string()
- // } else {
- // word
- // };
- //
- // // Reset autocomplete variables
- // pwd = PathBuf::from(word);
- // auindex = 0;
- // aulen = 0;
- // }
-
// everything else
_ => {
let mut buffer = buffer.lock().unwrap();