From 2590315b9e5280ca0c69cce35b4f4bea794790d4 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Sat, 21 Sep 2024 21:40:54 -0600 Subject: 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(-) (limited to 'src/buffer.rs') 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>>, pos: &mut Arc>) -> *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>>, pos: &mut Arc>) -> *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>>, pos: &mut Arc>) -> 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 = 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(); -- cgit v1.2.3