mirror of https://github.com/bobwen-dev/hunter
don't throw crap at screen when preview-process is kill
This commit is contained in:
parent
95291e9408
commit
528f725145
|
@ -1,3 +1,5 @@
|
|||
#![feature(vec_remove_item)]
|
||||
|
||||
extern crate termion;
|
||||
extern crate unicode_width;
|
||||
#[macro_use]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue