From 4c1e75c0580e763b66047423cdcd51d18b954e7f Mon Sep 17 00:00:00 2001 From: rabite Date: Tue, 26 Feb 2019 10:17:51 +0100 Subject: fix warnings --- src/fail.rs | 3 +-- src/listview.rs | 1 - src/main.rs | 1 - src/miller_columns.rs | 2 -- src/preview.rs | 24 +++++++++--------------- src/tabview.rs | 2 +- src/window.rs | 52 +-------------------------------------------------- 7 files changed, 12 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/fail.rs b/src/fail.rs index 0b9b0b3..9e3c5da 100644 --- a/src/fail.rs +++ b/src/fail.rs @@ -1,6 +1,5 @@ use failure; -use failure::Error; -use failure::{Fail, ResultExt}; +use failure::Fail; pub type HResult = Result; diff --git a/src/listview.rs b/src/listview.rs index 271631a..f32cc92 100644 --- a/src/listview.rs +++ b/src/listview.rs @@ -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}; diff --git a/src/main.rs b/src/main.rs index 2e1cfb1..1d92fba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/miller_columns.rs b/src/miller_columns.rs index c550541..c56bd0e 100644 --- a/src/miller_columns.rs +++ b/src/miller_columns.rs @@ -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; diff --git a/src/preview.rs b/src/preview.rs index f9e0f84..0e7ab82 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -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>) -> HResult { enum State { Is, Becoming, - Fail + Fail(HError) } struct WillBe { pub state: Arc>, pub thing: Arc>>, on_ready: Arc>>) -> HResult<()> + Send>>>>, - rx: Option>, stale: Arc> } impl WillBe where { pub fn new_become(closure: HClosure) -> WillBe { - 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, tx: std::sync::mpsc::Sender) { + fn run(&mut self, closure: HClosure) { let state = self.state.clone(); let stale = self.stale.clone(); let thing = self.thing.clone(); @@ -72,11 +66,11 @@ impl WillBe 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 WillBe where { fun: Box>>) -> 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 WillBeWidget { pub fn new(closure: HClosure) -> WillBeWidget { 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, diff --git a/src/tabview.rs b/src/tabview.rs index b16a251..22ef78f 100644 --- a/src/tabview.rs +++ b/src/tabview.rs @@ -79,7 +79,7 @@ impl Widget for TabView where T: Widget, TabView: 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!("{}:{} ", diff --git a/src/window.rs b/src/window.rs index fc08b47..f974208 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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 { MINIBUFFER.lock()?.query(query) } - -pub fn find_bins(comp_name: &str) -> Vec { - let paths = std::env::var_os("PATH").unwrap() - .to_string_lossy() - .split(":") - .map(|s| s.to_string()) - .collect::>(); - - 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::>() - }).flatten().collect::>() -} - -pub fn find_files(mut comp_name: String) -> Vec { - 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::>() -} -- cgit v1.2.3