fix warnings

This commit is contained in:
rabite 2019-02-26 10:17:51 +01:00
parent d0029949ea
commit 4c1e75c058
7 changed files with 12 additions and 73 deletions

View File

@ -1,6 +1,5 @@
use failure;
use failure::Error;
use failure::{Fail, ResultExt};
use failure::Fail;
pub type HResult<T> = Result<T, HError>;

View File

@ -2,7 +2,6 @@ use termion::event::{Event, Key};
use unicode_width::UnicodeWidthStr;
use std::path::{Path, PathBuf};
use std::io::Write;
use crate::coordinates::{Coordinates, Position, Size};
use crate::files::{File, Files};

View File

@ -7,7 +7,6 @@ extern crate unicode_width;
#[macro_use]
extern crate lazy_static;
extern crate failure;
#[macro_use]
extern crate failure_derive;
extern crate alphanumeric_sort;
extern crate dirs_2;

View File

@ -1,7 +1,5 @@
use termion::event::Key;
use std::sync::{Arc, Mutex};
use crate::coordinates::{Coordinates, Position, Size};
use crate::preview::Previewer;
use crate::widget::Widget;

View File

@ -1,7 +1,4 @@
use failure::Error;
use std::sync::Mutex;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use crate::coordinates::{Coordinates};
use crate::files::{File, Files, Kind};
@ -36,31 +33,28 @@ pub fn is_stale(stale: &Arc<Mutex<bool>>) -> HResult<bool> {
enum State {
Is,
Becoming,
Fail
Fail(HError)
}
struct WillBe<T: Send> {
pub state: Arc<Mutex<State>>,
pub thing: Arc<Mutex<Option<T>>>,
on_ready: Arc<Mutex<Option<Box<Fn(Arc<Mutex<Option<T>>>) -> HResult<()> + Send>>>>,
rx: Option<std::sync::mpsc::Receiver<T>>,
stale: Arc<Mutex<bool>>
}
impl<T: Send + 'static> WillBe<T> where {
pub fn new_become(closure: HClosure<T>)
-> WillBe<T> {
let (tx,rx) = std::sync::mpsc::channel();
let mut willbe = WillBe { state: Arc::new(Mutex::new(State::Becoming)),
thing: Arc::new(Mutex::new(None)),
on_ready: Arc::new(Mutex::new(None)),
rx: Some(rx),
stale: Arc::new(Mutex::new(false)) };
willbe.run(closure, tx);
willbe.run(closure);
willbe
}
fn run(&mut self, closure: HClosure<T>, tx: std::sync::mpsc::Sender<T>) {
fn run(&mut self, closure: HClosure<T>) {
let state = self.state.clone();
let stale = self.stale.clone();
let thing = self.thing.clone();
@ -72,11 +66,11 @@ impl<T: Send + 'static> WillBe<T> where {
*thing.try_lock().unwrap() = Some(got_thing);
*state.try_lock().unwrap() = State::Is;
match *on_ready_fn.lock().unwrap() {
Some(ref on_ready) => { on_ready(thing.clone()); },
Some(ref on_ready) => { on_ready(thing.clone()).ok(); },
None => {}
}
},
Err(err) => { dbg!(err); }
Err(err) => *state.lock().unwrap() = State::Fail(err)
}
});
}
@ -97,7 +91,7 @@ impl<T: Send + 'static> WillBe<T> where {
fun: Box<Fn(Arc<Mutex<Option<T>>>) -> HResult<()> + Send>)
-> HResult<()> {
if self.check().is_ok() {
fun(self.thing.clone());
fun(self.thing.clone())?;
} else {
*self.on_ready.try_lock()? = Some(fun);
}
@ -124,8 +118,8 @@ impl<T: Widget + Send + 'static> WillBeWidget<T> {
pub fn new(closure: HClosure<T>) -> WillBeWidget<T> {
let mut willbe = WillBe::new_become(Box::new(move |stale| closure(stale)));
willbe.on_ready(Box::new(|_| {
crate::window::send_event(crate::window::Events::WidgetReady);
Ok(()) }));
crate::window::send_event(crate::window::Events::WidgetReady)?;
Ok(()) })).ok();
WillBeWidget {
willbe: willbe,

View File

@ -79,7 +79,7 @@ impl<T> Widget for TabView<T> where T: Widget, TabView<T>: Tabbable {
fn render_header(&self) -> String {
let xsize = self.get_coordinates().xsize();
let header = self.active_tab_().render_header();
let mut tab_names = self.get_tab_names();
let tab_names = self.get_tab_names();
let mut nums_length = 0;
let tabnums = (0..self.widgets.len()).map(|num| {
nums_length += format!("{}:{} ",

View File

@ -2,7 +2,7 @@ use std::io::{stdin, stdout, Stdout, Write};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Sender, Receiver, channel};
use termion::event::{Event, Key};
use termion::event::Event;
use termion::input::TermRead;
use termion::screen::AlternateScreen;
@ -206,53 +206,3 @@ pub fn show_status(status: &str) {
pub fn minibuffer(query: &str) -> HResult<String> {
MINIBUFFER.lock()?.query(query)
}
pub fn find_bins(comp_name: &str) -> Vec<String> {
let paths = std::env::var_os("PATH").unwrap()
.to_string_lossy()
.split(":")
.map(|s| s.to_string())
.collect::<Vec<String>>();
paths.iter().map(|path| {
std::fs::read_dir(path).unwrap().flat_map(|file| {
let file = file.unwrap();
let name = file.file_name().into_string().unwrap();
if name.starts_with(comp_name) {
Some(name)
} else {
None
}
}).collect::<Vec<String>>()
}).flatten().collect::<Vec<String>>()
}
pub fn find_files(mut comp_name: String) -> Vec<String> {
let mut path = std::path::PathBuf::from(&comp_name);
let dir = if comp_name.starts_with("/") {
comp_name = path.file_name().unwrap().to_string_lossy().to_string();
path.pop();
path.to_string_lossy().to_string()
} else {
std::env::current_dir().unwrap().to_string_lossy().to_string()
};
let reader = std::fs::read_dir(dir.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) {
if file.file_type().unwrap().is_dir() {
Some(format!("{}/{}/", &dir, name))
} else {
Some(format!("/{}/", name))
}
} else {
None
}
}).collect::<Vec<String>>()
}