diff options
author | rabite <rabite@posteo.de> | 2019-06-19 19:17:25 +0200 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-06-19 19:30:11 +0200 |
commit | fc32c58c9d2128b1337d9604dc5a542f618c9c3e (patch) | |
tree | 7ca8a31481e323e19204dd16d5adb258518054e4 /src | |
parent | 89260e4312e79ac2e0623c6e7f18ee9a55e5bb08 (diff) |
added auto-installer for configs
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks.rs | 2 | ||||
-rw-r--r-- | src/config.rs | 1 | ||||
-rw-r--r-- | src/fail.rs | 7 | ||||
-rw-r--r-- | src/file_browser.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/minibuffer.rs | 4 | ||||
-rw-r--r-- | src/paths.rs | 2 | ||||
-rw-r--r-- | src/tabview.rs | 10 | ||||
-rw-r--r-- | src/term.rs | 11 | ||||
-rw-r--r-- | src/widget.rs | 10 |
10 files changed, 40 insertions, 16 deletions
diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 8f0b649..208ace0 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -15,7 +15,7 @@ pub struct Bookmarks { impl Bookmarks { pub fn new() -> Bookmarks { let mut bm = Bookmarks { mapping: HashMap::new() }; - bm.load().log(); + bm.load().or_else(|_| HError::log("Couldn't load bookmarks!")).ok(); bm } pub fn add(&mut self, key: char, path: &str) -> HResult<()> { diff --git a/src/config.rs b/src/config.rs index 2803e3d..24bc995 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use crate::paths; use crate::fail::{HError, HResult, ErrorLog}; + #[derive(Clone)] // These are options, so we know if they have been set or not struct ArgvConfig { diff --git a/src/fail.rs b/src/fail.rs index 0590ce5..0102fa0 100644 --- a/src/fail.rs +++ b/src/fail.rs @@ -104,8 +104,8 @@ pub enum HError { } impl HError { - pub fn log<T>(log: String) -> HResult<T> { - Err(HError::Log(log)) + pub fn log<T>(log: &str) -> HResult<T> { + Err(HError::Log(String::from(log))).log_and() } pub fn quit() -> HResult<()> { Err(HError::Quit) @@ -243,7 +243,8 @@ impl From<std::io::Error> for HError { impl From<failure::Error> for HError { fn from(error: failure::Error) -> Self { let err = HError::Error(format!("{}", error), - Backtrace::new_arced()); + Backtrace::new_arced() + ); err } } diff --git a/src/file_browser.rs b/src/file_browser.rs index 6d75f7d..019b77f 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -87,6 +87,14 @@ pub struct FileBrowser { } impl Tabbable for TabView<FileBrowser> { + fn on_new(&mut self) -> HResult<()> { + let core = self.core.clone(); + std::thread::spawn(move || { + crate::config_installer::ensure_config(core).log(); + }); + Ok(()) + } + fn new_tab(&mut self) -> HResult<()> { let cur_tab = self.active_tab_(); diff --git a/src/main.rs b/src/main.rs index c067e55..bc949fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ mod stats; mod icon; mod quick_actions; mod trait_ext; +mod config_installer; #[cfg(feature = "img")] mod imgview; diff --git a/src/minibuffer.rs b/src/minibuffer.rs index f7e0229..5c7ffcf 100644 --- a/src/minibuffer.rs +++ b/src/minibuffer.rs @@ -70,7 +70,7 @@ impl History { } fn add(&mut self, htype: &str, input: &str) { - self.load().log(); + self.load().ok(); let history = match self.history.get_mut(htype) { Some(history) => history, None => { @@ -498,7 +498,7 @@ impl Widget for MiniBuffer { } fn after_draw(&self) -> HResult<()> { - let cursor_pos = self.query.len() + + let cursor_pos = crate::term::string_len(&self.query) + ": ".len() + self.position; diff --git a/src/paths.rs b/src/paths.rs index 2818604..fb5ac02 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -24,11 +24,9 @@ pub fn hunter_path() -> HResult<PathBuf> { #[cfg(target_os = "macos")] pub fn hunter_path() -> HResult<PathBuf> { - dbg!("Finding path for macOS"); let mut hunter_path = home_path()?; hunter_path.push(".config/"); hunter_path.push("hunter/"); - dbg!(&hunter_path); Ok(hunter_path) } diff --git a/src/tabview.rs b/src/tabview.rs index 8b87552..6afa10d 100644 --- a/src/tabview.rs +++ b/src/tabview.rs @@ -27,7 +27,7 @@ pub trait Tabbable { } fn on_refresh(&mut self) -> HResult<()> { Ok(()) } fn on_config_loaded(&mut self) -> HResult<()> { Ok(()) } - + fn on_new(&mut self) -> HResult<()> { Ok(()) } } @@ -41,11 +41,15 @@ pub struct TabView<T> where T: Widget, TabView<T>: Tabbable { impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable { pub fn new(core: &WidgetCore) -> TabView<T> { - TabView { + let mut tabview = TabView { widgets: vec![], active: 0, core: core.clone() - } + }; + + Tabbable::on_new(&mut tabview).log(); + + tabview } pub fn push_widget(&mut self, widget: T) -> HResult<()> { diff --git a/src/term.rs b/src/term.rs index 2d32773..088f026 100644 --- a/src/term.rs +++ b/src/term.rs @@ -251,6 +251,17 @@ fn get_tokens(string: &str) -> Vec<Token> { tokens.0 } +pub fn string_len(string: &str) -> usize { + let tokens = get_tokens(&string); + + tokens.iter().fold(0, |len, token| { + match token { + Token::Text(text) => len + text.len(), + _ => len + } + }) +} + pub fn sized_string_u(string: &str, xsize: usize) -> String { let tokens = get_tokens(&string); diff --git a/src/widget.rs b/src/widget.rs index 43c1fdf..6cb19eb 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -75,10 +75,10 @@ impl WidgetCore { let (sender, receiver) = channel(); let status_bar_content = Arc::new(Mutex::new(None)); - let mut config = Async::new(|_| Ok(Config::load()?)); - let confsender = Arc::new(Mutex::new(sender.clone())); + let mut config = Async::new(move |_| Ok(Config::load()?)); + let confsender = sender.clone(); config.on_ready(move |_, _| { - confsender.lock().map(|s| s.send(Events::ConfigLoaded)).ok(); + confsender.send(Events::ConfigLoaded).ok(); Ok(()) }).log(); config.run().log(); @@ -123,7 +123,7 @@ impl WidgetCore { } pub fn show_status(&self, status: &str) -> HResult<()> { - HError::log::<()>(status.to_string()).log(); + HError::log::<()>(status).ok(); { let mut status_content = self.status_bar_content.lock()?; *status_content = Some(status.to_string()); @@ -466,7 +466,7 @@ pub trait Widget { self.get_core()?.screen()?.clear().log(); } Events::ConfigLoaded => { - self.get_core_mut()?.config.write()?.pull_async()?; + self.get_core_mut()?.config.write()?.pull_async().ok(); self.config_loaded().log(); } _ => {} |