summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-02-26 10:17:51 +0100
committerrabite <rabite@posteo.de>2019-02-26 10:17:51 +0100
commit4c1e75c0580e763b66047423cdcd51d18b954e7f (patch)
treeeed51ea8cd46683a2b2645479ee0b84694bf99a4
parentd0029949ea1d137525564ce3eb5dae3f18ea011e (diff)
fix warnings
-rw-r--r--src/fail.rs3
-rw-r--r--src/listview.rs1
-rw-r--r--src/main.rs1
-rw-r--r--src/miller_columns.rs2
-rw-r--r--src/preview.rs24
-rw-r--r--src/tabview.rs2
-rw-r--r--src/window.rs52
7 files changed, 12 insertions, 73 deletions
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<T> = Result<T, HError>;
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<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,
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<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!("{}:{} ",
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<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>>()
-}