summaryrefslogtreecommitdiffstats
path: root/src/preview.rs
blob: 6e88d323acba7ad26bdf190dd6e5f41e4243f64b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::path::PathBuf;
use std::process;

use crate::config::JoshutoConfig;
use crate::tab::JoshutoTab;
use crate::ui;
use crate::window::{panel::JoshutoPanel, view::JoshutoView};

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() {
                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);
                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());
                                    },
                                }
                            }
                        }
                    }
                }

                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: &JoshutoPanel, path: &PathBuf) {
    let mut command = process::Command::new("head");
    command.arg("-n");
    command.arg(win.cols.to_string());
    command.arg(path.as_os_str());
    command.stdin(std::process::Stdio::piped());
    command.stdout(std::process::Stdio::piped());
    command.stderr(std::process::Stdio::piped());

    match command.spawn() {
        Ok(child) => {
            if let Some(output) = child.stdout {
                let mut reader = std::io::BufReader::new(output);
                let mut buffer = String::new();

                // reader.read_line(&mut buffer);
            }
        }
        Err(e) => {
            ncurses::waddstr(win.win, e.to_string().as_str());
        }
    }
    // bat joshuto.rs --terminal-width 20 --wrap=never --line-range 0:26 --style='numbers'
}
*/