[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 09/11] Don't panic if autcomplete() fails


If, for whatever reason, the autocomplete() functions fails, don't panic
and quit. Instead, return an empty string.
---
 src/buffer.rs | 49 ++++---------------------------------------------
 1 file 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();
-- 
2.46.2




References:
[PATCH 00/11] Add filepath autcompleteRory Dudley <rory@xxxxxxx>
Archive administrator: postmaster AT dwarvish DOT org