diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-02-20 19:12:10 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-02-20 19:12:52 -0500 |
commit | c829e7849a44922cb55149f3874a82cda1040c89 (patch) | |
tree | e8e167eef9f0d5bb8d1e008c1bc2bb9936646718 /src/preview.rs | |
parent | 412b1ebb44382522084f615d58cb75374bc64778 (diff) |
change how preview works
Diffstat (limited to 'src/preview.rs')
-rw-r--r-- | src/preview.rs | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/src/preview.rs b/src/preview.rs index 45b2fb0..6ea3ea3 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -1,69 +1,71 @@ use std::path::PathBuf; use std::process; -use crate::context::JoshutoContext; -use crate::window; +use crate::config::JoshutoConfig; +use crate::tab::JoshutoTab; +use crate::ui; +use crate::window::{panel::JoshutoPanel, view::JoshutoView}; -pub fn preview_file(context: &mut JoshutoContext) { - /* - let curr_tab = &mut context.tabs[context.tab_index]; - - 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, &context.config_t.sort_type) { - context.views.right_win.display_contents(&context.theme_t, dirlist, context.config_t.scroll_offset); - context.views.right_win.queue_for_refresh(); - } else { - ncurses::werase(context.views.right_win.win); - ncurses::waddstr(context.views.right_win.win, "Can't find direntry"); - context.views.right_win.queue_for_refresh(); - } +pub fn preview_file(curr_tab: &mut JoshutoTab, views: &JoshutoView, config_t: &JoshutoConfig) { + 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 { - ncurses::werase(context.views.right_win.win); + ui::wprint_err(&views.right_win, "Can't find directory"); + } + } else { + ncurses::werase(views.right_win.win); + ncurses::wnoutrefresh(views.right_win.win); + } +/* + else { + ncurses::werase(views.right_win.win); - if let Some(file_ext) = entry.path.extension() { - if let Some(file_ext) = file_ext.to_str() { - match file_ext { - "o" | "a" | "avi" | "mp3" | "mp4" | "wmv" | "wma" | - "mkv" | "flv" | "vob" | "wav" | "mpc" | "flac" | - "divx" | "xcf" | "pdf" | "torrent" | "class" | "so" | - "img" | "pyc" | "dmg" | "png" | "jpg" | "jpeg" | "out" | "svg" => { - ui::wprint_err(&context.views.right_win, "Binary File"); - }, - _ => { - let detective = mime_detective::MimeDetective::new().unwrap(); - match detective.detect_filepath(&entry.path) { - Ok(mime_type) => { - match mime_type.type_() { - mime::TEXT => { - text_preview(&context.views.right_win, &entry.path); - }, - _ => { - ui::wprint_err(&context.views.right_win, mime_type.type_().as_str()); - }, - } - }, - Err(e) => { - ui::wprint_err(&context.views.right_win, e.to_string().as_str()); - }, - } + if let Some(file_ext) = entry.path.extension() { + if let Some(file_ext) = file_ext.to_str() { + match file_ext { + "o" | "a" | "avi" | "mp3" | "mp4" | "wmv" | "wma" | + "mkv" | "flv" | "vob" | "wav" | "mpc" | "flac" | + "divx" | "xcf" | "pdf" | "torrent" | "class" | "so" | + "img" | "pyc" | "dmg" | "png" | "jpg" | "jpeg" | "out" | "svg" => { + ui::wprint_err(&context.views.right_win, "Binary File"); + }, + _ => { + let detective = mime_detective::MimeDetective::new().unwrap(); + match detective.detect_filepath(&entry.path) { + Ok(mime_type) => { + match mime_type.type_() { + mime::TEXT => { + text_preview(&context.views.right_win, &entry.path); + }, + _ => { + ui::wprint_err(&context.views.right_win, mime_type.type_().as_str()); + }, + } + }, + Err(e) => { + ui::wprint_err(&context.views.right_win, e.to_string().as_str()); + }, } } } } - - ncurses::wnoutrefresh(context.views.right_win.win); } - } else { - ncurses::werase(context.views.right_win.win); + ncurses::wnoutrefresh(context.views.right_win.win); } +*/ + } else { + ncurses::werase(views.right_win.win); + ncurses::wnoutrefresh(views.right_win.win); } - */ + } } -pub fn text_preview(win: &window::JoshutoPanel, path: &PathBuf) { +pub fn text_preview(win: &JoshutoPanel, path: &PathBuf) { let mut command = process::Command::new("head"); command.arg("-n"); command.arg(win.cols.to_string()); |