diff options
author | rabite <rabite@posteo.de> | 2019-02-09 12:49:57 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-02-09 13:04:04 +0100 |
commit | 528f7251452782b4b2bc24fedfd3f34e80575283 (patch) | |
tree | 34c5de8ed5b7c50207b60580218ddb288e4668b7 | |
parent | 95291e94084205347089f8457eeb0fec98fe34b3 (diff) |
don't throw crap at screen when preview-process is kill
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/preview.rs | 16 | ||||
-rw-r--r-- | src/window.rs | 15 |
3 files changed, 24 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 6c61f5c..2798311 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(vec_remove_item)] + extern crate termion; extern crate unicode_width; #[macro_use] diff --git a/src/preview.rs b/src/preview.rs index 15638aa..d6bf31d 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -10,14 +10,14 @@ use crate::widget::Widget; lazy_static! { - static ref PIDS: Arc<Mutex<Vec<i32>>> = { Arc::new(Mutex::new(vec![])) }; + static ref PIDS: Arc<Mutex<Vec<u32>>> = { Arc::new(Mutex::new(vec![])) }; static ref CURFILE: Arc<Mutex<Option<File>>> = { Arc::new(Mutex::new(None)) }; } fn kill_procs() { let mut pids = PIDS.lock().unwrap(); for pid in &*pids { - unsafe { libc::kill(*pid, 9); } + unsafe { libc::kill(*pid as i32, 9); } } pids.clear(); } @@ -92,13 +92,17 @@ impl Previewer { .spawn().unwrap(); let pid = process.id(); - PIDS.lock().unwrap().push(pid as i32); + PIDS.lock().unwrap().push(pid); if !is_current(&file) { return } - let output = process.wait_with_output().unwrap(); + let output = process.wait_with_output(); + if output.is_err() { return } + let output = output.unwrap(); - let status = output.status.code().unwrap(); + let status = output.status.code(); + if status.is_none() { return } + let status = status.unwrap(); if status == 0 || status == 5 && is_current(&file) { let output = std::str::from_utf8(&output.stdout) @@ -116,7 +120,7 @@ impl Previewer { { write!(std::io::stdout(), "{}", redraw).unwrap(); } - PIDS.lock().unwrap().pop(); + PIDS.lock().unwrap().remove_item(&pid); } } } diff --git a/src/window.rs b/src/window.rs index 58742d5..49a401f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -160,12 +160,18 @@ pub fn minibuffer(query: &str) -> Option<String> { let part = buffer.rsplitn(2, " ").take(1) .map(|s| s.to_string()).collect::<String>(); - - let completions = find_files(&part); + let completions = find_bins(&part); if !completions.is_empty() { buffer = buffer[..buffer.len() - part.len()].to_string(); buffer.push_str(&completions[0]); pos += &completions[0].len() - part.len(); + } else { + let completions = find_files(&part); + if !completions.is_empty() { + buffer = buffer[..buffer.len() - part.len()].to_string(); + buffer.push_str(&completions[0]); + pos += &completions[0].len() - part.len(); + } } } else { buffer += "$s"; @@ -243,7 +249,10 @@ pub fn find_files(comp_name: &str) -> Vec<String> { cwd.push(comp_name); } - std::fs::read_dir(cwd.clone()).unwrap().flat_map(|file| { + let reader = std::fs::read_dir(cwd.clone()); + if reader.is_err() { return vec![]; } + let reader = reader.unwrap(); + reader.flat_map(|file| { let file = file.unwrap(); let name = file.file_name().into_string().unwrap(); if name.starts_with(comp_name) { |