diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-02-20 19:51:06 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-02-20 19:51:54 -0500 |
commit | f75182734a5bec0987b424aff28e2ed0acf2fe38 (patch) | |
tree | cb483f5a020057f1856fcf6c507337be6775f2bf | |
parent | c829e7849a44922cb55149f3874a82cda1040c89 (diff) |
reduce eprintln
-rw-r--r-- | src/commands/open_file.rs | 18 | ||||
-rw-r--r-- | src/history.rs | 17 | ||||
-rw-r--r-- | src/preview.rs | 15 | ||||
-rw-r--r-- | src/sort.rs | 10 |
4 files changed, 30 insertions, 30 deletions
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 507ad07..e27f588 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -49,15 +49,12 @@ impl OpenFile { fn enter_directory(path: &Path, context: &mut JoshutoContext) { let curr_tab = &mut context.tabs[context.curr_tab_index]; - match env::set_current_dir(path) { - Ok(_) => {} - Err(e) => { - ui::wprint_err( - &context.views.bot_win, - format!("{}: {:?}", e, path).as_str(), - ); - return; - } + if let Err(e) = env::set_current_dir(path) { + ui::wprint_err( + &context.views.bot_win, + format!("{}: {:?}", e, path).as_str(), + ); + return; } { @@ -135,7 +132,6 @@ impl JoshutoRunnable for OpenFile { ); preview::preview_file(curr_tab, &context.views, &context.config_t); } - ncurses::doupdate(); } else { let paths: Option<Vec<PathBuf>> = match context.tabs[context.curr_tab_index].curr_list.as_ref() { @@ -151,8 +147,8 @@ impl JoshutoRunnable for OpenFile { } else { ui::wprint_msg(&context.views.bot_win, "No files selected: None"); } - ncurses::doupdate(); } + ncurses::doupdate(); } } diff --git a/src/history.rs b/src/history.rs index fc69338..78e3b64 100644 --- a/src/history.rs +++ b/src/history.rs @@ -29,7 +29,7 @@ impl DirHistory { } self.map.insert(curr.to_path_buf(), s); } - Err(e) => eprintln!("{}", e), + Err(e) => eprintln!("populate_to_root: {}", e), }; ancestor = curr; } @@ -59,7 +59,7 @@ impl DirHistory { &mut self, path: &Path, sort_type: &sort::SortType, - ) -> Option<&mut structs::JoshutoDirList> { + ) -> Result<&mut structs::JoshutoDirList, std::io::Error> { let pathbuf = path.to_path_buf(); match self.map.entry(pathbuf.clone()) { Entry::Occupied(mut entry) => { @@ -69,12 +69,17 @@ impl DirHistory { } } Entry::Vacant(entry) => { - if let Ok(s) = structs::JoshutoDirList::new(path.to_path_buf(), &sort_type) { - entry.insert(s); - } + let s = structs::JoshutoDirList::new(path.to_path_buf(), &sort_type)?; + entry.insert(s); } }; - self.map.get_mut(&pathbuf) + match self.map.get_mut(&pathbuf) { + Some(s) => Ok(s), + None => Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Can't find file", + )), + } } pub fn put_back(&mut self, dirlist: Option<structs::JoshutoDirList>) { diff --git a/src/preview.rs b/src/preview.rs index 6ea3ea3..6e88d32 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -10,11 +10,14 @@ pub fn preview_file(curr_tab: &mut JoshutoTab, views: &JoshutoView, config_t: &J if let Some(ref curr_list) = curr_tab.curr_list { if let Some(entry) = curr_list.get_curr_ref() { if entry.path.is_dir() { - if let Some(dirlist) = curr_tab.history.get_mut_or_create(&entry.path, &config_t.sort_type) { - views.right_win.display_contents(dirlist, config_t.scroll_offset); - views.right_win.queue_for_refresh(); - } else { - ui::wprint_err(&views.right_win, "Can't find directory"); + match curr_tab.history.get_mut_or_create(&entry.path, &config_t.sort_type) { + Ok(dirlist) => { + views.right_win.display_contents(dirlist, config_t.scroll_offset); + views.right_win.queue_for_refresh(); + } + Err(e) => { + ui::wprint_err(&views.right_win, &e.to_string()); + } } } else { ncurses::werase(views.right_win.win); @@ -65,6 +68,7 @@ pub fn preview_file(curr_tab: &mut JoshutoTab, views: &JoshutoView, config_t: &J } } +/* pub fn text_preview(win: &JoshutoPanel, path: &PathBuf) { let mut command = process::Command::new("head"); command.arg("-n"); @@ -89,3 +93,4 @@ pub fn text_preview(win: &JoshutoPanel, path: &PathBuf) { } // bat joshuto.rs --terminal-width 20 --wrap=never --line-range 0:26 --style='numbers' } +*/ diff --git a/src/sort.rs b/src/sort.rs index cbfc635..084ae57 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -88,10 +88,7 @@ fn filter_default( match result { Ok(direntry) => match structs::JoshutoDirEntry::from(&direntry) { Ok(s) => Some(s), - Err(e) => { - eprintln!("error: {:?}", e); - None - } + Err(e) => None, }, Err(_) => None, } @@ -108,10 +105,7 @@ fn filter_hidden_files( } else { match structs::JoshutoDirEntry::from(&direntry) { Ok(s) => Some(s), - Err(e) => { - eprintln!("error: {:?}", e); - None - } + Err(e) => None, } } } |