summaryrefslogtreecommitdiffstats
path: root/src/preview.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-29 18:22:44 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-30 11:05:47 -0400
commit36d8299f224b044139d52c0f65eb66be4c25a5d0 (patch)
tree5f99fdfff153ab9f39c1d3ed77f9f18ef3c2d5d3 /src/preview.rs
parent4bbe0969006eab7cfe3a47231d5e002b5259e19b (diff)
cargo clippy
Diffstat (limited to 'src/preview.rs')
-rw-r--r--src/preview.rs73
1 files changed, 34 insertions, 39 deletions
diff --git a/src/preview.rs b/src/preview.rs
index 71e7a83..6002c99 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -21,22 +21,19 @@ pub fn preview_parent(curr_tab: &mut JoshutoTab, win: &JoshutoPanel, config_t: &
pub fn preview_entry(curr_tab: &mut JoshutoTab, win: &JoshutoPanel, config_t: &JoshutoConfig) {
ncurses::werase(win.win);
- match curr_tab.curr_list.get_curr_ref() {
- Some(s) => {
- if s.path.is_dir() {
- preview_directory(&mut curr_tab.history, s.path.as_path(), win, config_t);
- } else if s.metadata.file_type.is_file() {
- if s.metadata.len <= config_t.max_preview_size {
- preview_file(s, win);
- } else {
- ui::wprint_err(win, "File size exceeds max preview size");
- }
+ if let Some(s) = curr_tab.curr_list.get_curr_ref() {
+ if s.path.is_dir() {
+ preview_directory(&mut curr_tab.history, s.path.as_path(), win, config_t);
+ } else if s.metadata.file_type.is_file() {
+ if s.metadata.len <= config_t.max_preview_size {
+ preview_file(s, win);
} else {
- ui::wprint_err(win, "Not a regular file");
+ ui::wprint_err(win, "File size exceeds max preview size");
}
+ } else {
+ ui::wprint_err(win, "Not a regular file");
}
- None => {}
- };
+ }
win.queue_for_refresh();
}
@@ -46,12 +43,12 @@ fn preview_directory(
win: &JoshutoPanel,
config_t: &JoshutoConfig,
) {
- match history.entry(path.clone().to_path_buf()) {
+ match history.entry(path.to_path_buf().clone()) {
Entry::Occupied(mut entry) => {
win.display_contents(entry.get_mut(), config_t.scroll_offset);
}
Entry::Vacant(entry) => {
- if let Ok(s) = JoshutoDirList::new(path.clone().to_path_buf(), &config_t.sort_option) {
+ if let Ok(s) = JoshutoDirList::new(path.to_path_buf().clone(), &config_t.sort_option) {
win.display_contents(entry.insert(s), config_t.scroll_offset);
}
}
@@ -64,41 +61,39 @@ fn preview_file(entry: &JoshutoDirEntry, win: &JoshutoPanel) {
match path.extension() {
Some(file_ext) => match PREVIEW_T.extension.get(file_ext.to_str().unwrap()) {
Some(s) => preview_with(path, win, &s),
- None => {
- let mimetype_str = tree_magic::from_filepath(&path);
- match PREVIEW_T.mimetype.get(mimetype_str.as_str()) {
+ None => {},
+/*
+ None => if let Some(mimetype) = tree_magic::from_filepath(&path) {
+ match PREVIEW_T.mimetype.get(mimetype.as_str()) {
Some(s) => preview_with(path, win, &s),
- None => match mimetype_str.find('/') {
- Some(ind) => {
- let supertype = &mimetype_str[..ind];
- if supertype == "text" {
- preview_text(path, win);
- } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) {
- preview_with(path, win, &s);
- }
+ None => if let Some(ind) = mimetype.find('/') {
+ let supertype = &mimetype[..ind];
+ if supertype == "text" {
+ preview_text(path, win);
+ } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) {
+ preview_with(path, win, &s);
}
- None => {}
},
}
}
+*/
},
- None => {
- let mimetype_str = tree_magic::from_filepath(&path);
- match PREVIEW_T.mimetype.get(mimetype_str.as_str()) {
+ None => {},
+/*
+ if let Some(mimetype) = tree_magic::from_filepath(&path) {
+ match PREVIEW_T.mimetype.get(mimetype.as_str()) {
Some(s) => preview_with(path, win, &s),
- None => match mimetype_str.find('/') {
- Some(ind) => {
- let supertype = &mimetype_str[..ind];
- if supertype == "text" {
- preview_text(path, win);
- } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) {
- preview_with(path, win, &s);
- }
+ None => if let Some(ind) = mimetype.find('/') {
+ let supertype = &mimetype[..ind];
+ if supertype == "text" {
+ preview_text(path, win);
+ } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) {
+ preview_with(path, win, &s);
}
- None => {}
},
}
}
+*/
}
}