diff options
author | Rory Dudley | 2024-09-30 21:55:40 -0600 |
---|---|---|
committer | Rory Dudley | 2024-09-30 23:02:14 -0600 |
commit | 15245cb72d205f967e67518d7cded26ef42ec3a7 (patch) | |
tree | 1ee2016566b0f41744d058f6eadbc6281702eb9c | |
parent | a513f1ec2036f8f52fb4d5bd720974a8e06d1074 (diff) | |
download | dwarvish-15245cb72d205f967e67518d7cded26ef42ec3a7.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.
Signed-off-by: Rory Dudley <rory@netc.lu>
-rw-r--r-- | src/buffer.rs | 49 |
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(); |