diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2018-07-17 22:09:05 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2018-07-17 22:15:42 -0400 |
commit | cf94c43b620e05e3428e04946060e6dbf05dd6f6 (patch) | |
tree | a482d5cc41b7597c6850944edc3c77c3273a37d2 | |
parent | 7e566655610fab51df8066ad88478e2c6fe1e6fa (diff) |
major refactoring
add intermediate structs
add methods to structs
remove duplicate code
add support for shortening filenames to fit inside window width
unstable unicode support
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/joshuto.rs | 537 | ||||
-rw-r--r-- | src/joshuto_unix.rs | 3 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 295 insertions, 248 deletions
@@ -1,4 +1,5 @@ /target /test +*~ Cargo.lock **/*.rs.bk diff --git a/src/joshuto.rs b/src/joshuto.rs index f01887f..f513ae4 100644 --- a/src/joshuto.rs +++ b/src/joshuto.rs @@ -22,8 +22,161 @@ const VID_COLOR : i16 = 13; const ERR_COLOR : i16 = 40; +pub struct JoshutoWindow { + win : ncurses::WINDOW, + rows : i32, + cols : i32, + coords : (i32, i32) +} + +impl JoshutoWindow { + pub fn new(rows : i32, cols : i32, coords : (i32, i32)) -> JoshutoWindow + { + let win = ncurses::newwin(rows, cols, coords.0, coords.1); + + ncurses::refresh(); + JoshutoWindow { + win: win, + rows: rows, + cols: cols, + coords: coords, + } + } + + pub fn redraw(&mut self, rows : i32, cols : i32, coords : (i32, i32)) + { + ncurses::delwin(self.win); + self.win = ncurses::newwin(rows, cols, coords.1, coords.0); + self.rows = rows; + self.cols = cols; + self.coords = coords; + ncurses::refresh(); + } + + pub fn display_contents(&self, dir_contents: &Vec<fs::DirEntry>, + index : usize) { + + let vec_len = dir_contents.len(); + + if vec_len == 0 { + win_print_err_msg(self, "empty"); + return; + } + + let offset : usize = 5; + let start : usize; + let end : usize; + + if self.rows as usize >= vec_len { + start = 0; + end = vec_len; + } else if index <= offset { + start = 0; + end = self.rows as usize; + } else if index - offset + self.rows as usize >= vec_len { + start = vec_len - self.rows as usize; + end = vec_len; + } else { + start = index - offset; + end = start + self.rows as usize; + } + + ncurses::wclear(self.win); + ncurses::wmove(self.win, 0, 0); + + for i in start..end { + if index == i { + ncurses::wattron(self.win, ncurses::A_REVERSE()); + print_file(self, &dir_contents[i]); + ncurses::wattroff(self.win, ncurses::A_REVERSE()); + } else { + print_file(self, &dir_contents[i]); + } + } + ncurses::wrefresh(self.win); + } +} + +pub fn win_print_err_msg(win : &JoshutoWindow, err_msg : &str) +{ + ncurses::wclear(win.win); + ncurses::wattron(win.win, ncurses::COLOR_PAIR(ERR_COLOR)); + ncurses::mvwprintw(win.win, 0, 0, err_msg); + ncurses::wattroff(win.win, ncurses::COLOR_PAIR(ERR_COLOR)); + ncurses::wrefresh(win.win); +} + +pub struct JoshutoView { + top_win : JoshutoWindow, + left_win : JoshutoWindow, + mid_win : JoshutoWindow, + right_win : JoshutoWindow, + bot_win : JoshutoWindow, + win_ratio : (i32, i32, i32), +} + +impl JoshutoView { + pub fn new(win_ratio : (i32, i32, i32)) -> JoshutoView + { + let mut term_rows : i32 = 0; + let mut term_cols : i32 = 0; + ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols); + + let term_divide : i32 = term_cols / 7; + let top_win = JoshutoWindow::new(1, term_cols, (0, 0)); + ncurses::scrollok(top_win.win, true); + + let left_win = JoshutoWindow::new(term_rows - 2, + term_divide * win_ratio.0, (1, 0)); + + let mid_win = JoshutoWindow::new(term_rows - 2, + term_divide * win_ratio.1, (1, term_divide * win_ratio.0)); + + let right_win = JoshutoWindow::new(term_rows - 2, + term_divide * 3, (1, term_divide * win_ratio.2)); + let bot_win = JoshutoWindow::new(1, term_cols, (term_rows - 1, 0)); + + ncurses::refresh(); + + JoshutoView { + top_win, + left_win, + mid_win, + right_win, + bot_win, + win_ratio, + } + } + + fn redraw_views(&mut self) { + let mut term_rows : i32 = 0; + let mut term_cols : i32 = 0; + ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols); + + let term_divide : i32 = term_cols / 7; + + self.top_win.redraw(1, term_cols, (0, 0)); + ncurses::scrollok(self.top_win.win, true); + + self.left_win.redraw(term_rows - 2, + term_divide * self.win_ratio.0, (1, 0)); + + self.mid_win.redraw(term_rows - 2, + term_divide * self.win_ratio.1, (1, term_divide * self.win_ratio.0)); + + self.right_win.redraw(term_rows - 2, + term_divide * 3, (1, term_divide * self.win_ratio.2)); + self.bot_win.redraw(1, term_cols, (term_rows - 1, 0)); + } + +} + pub fn init_ncurses() { + let locale_conf = ncurses::LcCategory::all; + + ncurses::setlocale(locale_conf, "en_US.UTF-8"); + ncurses::initscr(); ncurses::raw(); @@ -139,47 +292,9 @@ fn file_ext_attroff(win : ncurses::WINDOW, ext : &str) } } -fn print_file(win : ncurses::WINDOW, file : &fs::DirEntry) { - - use std::os::unix::fs::PermissionsExt; - - let mut mode : u32 = 0; - - if let Ok(metadata) = file.metadata() { - mode = metadata.permissions().mode(); - } - if mode != 0 { - file_attron(win, mode, file.path().extension()); - } - - match file.file_name().into_string() { - Ok(file_name) => { - ncurses::wprintw(win, " "); - ncurses::wprintw(win, &file_name); - }, - Err(e) => { - ncurses::wprintw(win, format!("{:?}", e).as_str()); - }, - }; - if mode != 0 { - file_attroff(win, mode, file.path().extension()); - } - - ncurses::wprintw(win, "\n"); -} - -pub fn win_print_err_msg(win : ncurses::WINDOW, err_msg : &str) +pub fn curr_dirent_list() -> Result<Vec<fs::DirEntry>, std::io::Error> { - ncurses::wclear(win); - ncurses::wattron(win, ncurses::COLOR_PAIR(ERR_COLOR)); - ncurses::mvwprintw(win, 0, 0, err_msg); - ncurses::wattroff(win, ncurses::COLOR_PAIR(ERR_COLOR)); - ncurses::wrefresh(win); -} - -pub fn dirent_list(path : &path::PathBuf) -> Result<Vec<fs::DirEntry>, std::io::Error> -{ - match fs::read_dir(path) { + match fs::read_dir(".") { Ok(results) => { let results : Result<Vec<fs::DirEntry>, _> = results.collect(); results @@ -190,44 +305,56 @@ pub fn dirent_list(path : &path::PathBuf) -> Result<Vec<fs::DirEntry>, std::io:: } } -pub fn win_print_path(win : ncurses::WINDOW, path : &path::PathBuf) +pub fn win_print_path(win : &JoshutoWindow, path : &path::PathBuf) { - ncurses::wclear(win); + ncurses::wclear(win.win); let path_str : &str = match path.to_str() { Some(s) => s, None => "Error", }; - ncurses::mvwprintw(win, 0, 0, path_str); - ncurses::wrefresh(win); + ncurses::mvwprintw(win.win, 0, 0, path_str); + ncurses::wrefresh(win.win); } -pub fn win_contents_refresh(win : ncurses::WINDOW, - dir_contents: &Vec<fs::DirEntry>, win_rows : usize) { +fn print_file(win : &JoshutoWindow, file : &fs::DirEntry) +{ + use std::os::unix::fs::PermissionsExt; - let vec_len = dir_contents.len(); + let mut mode : u32 = 0; - if vec_len == 0 { - win_print_err_msg(win, "empty"); - return; + if let Ok(metadata) = file.metadata() { + mode = metadata.permissions().mode(); + } + if mode != 0 { + file_attron(win.win, mode, file.path().extension()); } - let mut i : usize = 0; - let win_rows : usize = win_rows + i; + match file.file_name().into_string() { + Ok(file_name) => { + ncurses::wprintw(win.win, " "); + if file_name.len() + 1 >= win.cols as usize { + ncurses::wprintw(win.win, &file_name[..win.cols as usize - 5]); +// ncurses::wprintw(win.win, "…"); + ncurses::wprintw(win.win, "..."); + } else { + ncurses::wprintw(win.win, &file_name); + } + }, + Err(e) => { + ncurses::wprintw(win.win, format!("{:?}", e).as_str()); + }, + }; - ncurses::wclear(win); - ncurses::wmove(win, 0, 0); - while i < vec_len && i < win_rows { - print_file(win, &dir_contents[i]); - i += 1; + if mode != 0 { + file_attroff(win.win, mode, file.path().extension()); } - ncurses::wrefresh(win); + ncurses::wprintw(win.win, "\n"); } -pub fn win_contents_refresh_indexed(win : ncurses::WINDOW, - dir_contents: &Vec<fs::DirEntry>, - win_rows : usize, index : usize) { +pub fn win_contents_refresh(win : &JoshutoWindow, + dir_contents: &Vec<fs::DirEntry>) { let vec_len = dir_contents.len(); @@ -236,49 +363,28 @@ pub fn win_contents_refresh_indexed(win : ncurses::WINDOW, return; } - let offset : usize = 5; - let start : usize; - let end : usize; - - if win_rows >= vec_len { - start = 0; - end = vec_len; - } else if index <= offset { - start = 0; - end = win_rows; - } else if index - offset + win_rows >= vec_len { - start = vec_len - win_rows; - end = vec_len; - } else { - start = index - offset; - end = start + win_rows; - } - - ncurses::wclear(win); - ncurses::wmove(win, 0, 0); + let mut i : usize = 0; + let win_rows : usize = i + win.rows as usize; - for i in start..end { - if index == i { - ncurses::wattron(win, ncurses::A_REVERSE()); - print_file(win, &dir_contents[i]); - ncurses::wattroff(win, ncurses::A_REVERSE()); - } else { - print_file(win, &dir_contents[i]); - } + ncurses::wclear(win.win); + ncurses::wmove(win.win, 0, 0); + while i < vec_len && i < win_rows { + print_file(win, &dir_contents[i]); + i += 1; } - ncurses::wrefresh(win); + ncurses::wrefresh(win.win); } -pub fn win_print_parent_dir(win : ncurses::WINDOW, path : &path::PathBuf, index : usize, length : usize) +pub fn win_print_parent_dir(win : &JoshutoWindow, path : &path::PathBuf, index : usize) { - ncurses::wclear(win); + ncurses::wclear(win.win); if let Some(ppath) = path.parent() { match fs::read_dir(ppath) { Ok(results) => { let results : Result<Vec<fs::DirEntry>, _> = results.collect(); if let Ok(mut dir_contents) = results { dir_contents.sort_by(joshuto_sort::alpha_sort); - win_contents_refresh_indexed(win, &dir_contents, length, index); + win.display_contents(&dir_contents, index); } }, Err(e) => { @@ -286,16 +392,15 @@ pub fn win_print_parent_dir(win : ncurses::WINDOW, path : &path::PathBuf, index }, }; } - ncurses::wrefresh(win); + ncurses::wrefresh(win.win); } -pub fn win_print_file_preview(win : ncurses::WINDOW, file : &fs::DirEntry, - length : usize) +pub fn win_print_file_preview(win : &JoshutoWindow, file : &fs::DirEntry) { use std::os::unix::fs::PermissionsExt; use joshuto::joshuto_unix; - ncurses::wclear(win); + ncurses::wclear(win.win); if let Ok(metadata) = file.metadata() { let permissions : fs::Permissions = metadata.permissions(); let mode = permissions.mode(); @@ -307,11 +412,11 @@ pub fn win_print_file_preview(win : ncurses::WINDOW, file : &fs::DirEntry, let results : Result<Vec<fs::DirEntry>, _> = results.collect(); if let Ok(mut dir_contents) = results { dir_contents.sort_by(joshuto_sort::alpha_sort); - win_contents_refresh(win, &dir_contents, length); + win_contents_refresh(&win, &dir_contents); } }, Err(e) => { - win_print_err_msg(win, format!("{}", e).as_str()); + win_print_err_msg(&win, format!("{}", e).as_str()); }, }; }, @@ -327,43 +432,43 @@ pub fn win_print_file_preview(win : ncurses::WINDOW, file : &fs::DirEntry, let results : Result<Vec<fs::DirEntry>, _> = results.collect(); if let Ok(mut dir_contents) = results { dir_contents.sort_by(joshuto_sort::alpha_sort); - win_contents_refresh(win, &dir_contents, length); + win_contents_refresh(&win, &dir_contents); } }, Err(e) => { - win_print_err_msg(win, format!("{}", e).as_str()); + win_print_err_msg(&win, format!("{}", e).as_str()); }, }; } else { - ncurses::wprintw(win, "Symlink pointing to a file"); + ncurses::wprintw(win.win, "Symlink pointing to a file"); } }, Err(e) => { - win_print_err_msg(win, format!("{}", e).as_str()); + win_print_err_msg(&win, format!("{}", e).as_str()); }, }; }, joshuto_unix::S_IFBLK => { - ncurses::wprintw(win, "Block file"); + ncurses::wprintw(win.win, "Block file"); }, joshuto_unix::S_IFSOCK => { - ncurses::wprintw(win, "Socket file"); + ncurses::wprintw(win.win, "Socket file"); }, joshuto_unix::S_IFCHR => { - ncurses::wprintw(win, "Character file"); + ncurses::wprintw(win.win, "Character file"); }, joshuto_unix::S_IFIFO => { - ncurses::wprintw(win, "FIFO file"); + ncurses::wprintw(win.win, "FIFO file"); }, joshuto_unix::S_IFREG => { - ncurses::wprintw(win, "Plain file"); + ncurses::wprintw(win.win, "Plain file"); }, _ => { - ncurses::wprintw(win, "Unknown file"); + ncurses::wprintw(win.win, "Unknown file"); }, } } - ncurses::wrefresh(win); + ncurses::wrefresh(win.win); } @@ -400,71 +505,6 @@ pub fn win_print_file_info(win : ncurses::WINDOW, file : &fs::DirEntry) ncurses::wrefresh(win); } -pub struct JoshutoView { - top_win : ncurses::WINDOW, - left_win : ncurses::WINDOW, - mid_win : ncurses::WINDOW, - right_win : ncurses::WINDOW, - bot_win : ncurses::WINDOW, - win_ratio : (i32, i32, i32), -} - -impl JoshutoView { - pub fn new(term_rows : i32, term_cols : i32, win_ratio : (i32, i32, i32)) -> JoshutoView - { - let term_divide : i32 = term_cols / 7; - let top_win = ncurses::newwin(1, term_cols, 0, 0); - ncurses::scrollok(top_win, true); - - let left_win = ncurses::newwin(term_rows - 2, - term_divide * win_ratio.0, 1, 0); - - let mid_win = ncurses::newwin(term_rows - 2, - term_divide * win_ratio.1, 1, term_divide * win_ratio.0); - - let right_win = ncurses::newwin(term_rows - 2, - term_divide * 3, 1, term_divide * win_ratio.2); - let bot_win = ncurses::newwin(1, term_cols, term_rows - 1, 0); - - ncurses::refresh(); - - JoshutoView { - top_win, - left_win, - mid_win, - right_win, - bot_win, - win_ratio, - } - } - - fn redraw_views(&mut self, term_rows : i32, term_cols : i32) { - let windows : [ncurses::WINDOW ; 5] = [ - self.top_win, - self.mid_win, - self.left_win, - self.right_win, - self.bot_win - ]; - for win in windows.iter() { - ncurses::delwin(*win); - } - - let term_divide : i32 = term_cols / 7; - self.top_win = ncurses::newwin(1, term_cols, 0, 0); - - self.left_win = ncurses::newwin(term_rows - 2, - term_divide * self.win_ratio.0, 1, 0); - - self.mid_win = ncurses::newwin(term_rows - 2, - term_divide * self.win_ratio.1, 1, term_divide * self.win_ratio.0); - - self.right_win = ncurses::newwin(term_rows - 2, - term_divide * 3, 1, term_divide * self.win_ratio.2); - self.bot_win = ncurses::newwin(1, term_cols, term_rows - 1, 0); - } - -} pub fn run(_config : &JoshutoConfig) { @@ -481,8 +521,7 @@ pub fn run(_config : &JoshutoConfig) ncurses::refresh(); /* height, width, y, x */ - let mut joshuto_view : JoshutoView = JoshutoView::new(term_rows, term_cols, - (1, 3, 4)); + let mut joshuto_view : JoshutoView = JoshutoView::new((1, 3, 4)); /* TODO: mutable in the future */ let sort_func : fn(file1 : &std::fs::DirEntry, file2 : &std::fs::DirEntry) -> std::cmp::Ordering @@ -500,7 +539,7 @@ pub fn run(_config : &JoshutoConfig) }; let mut dir_contents : Vec<fs::DirEntry> = - match dirent_list(&curr_path) { + match curr_dirent_list() { Ok(s) => { s } @@ -511,16 +550,15 @@ pub fn run(_config : &JoshutoConfig) }; dir_contents.sort_by(&sort_func); - win_print_path(joshuto_view.top_win, &curr_path); + win_print_path(&joshuto_view.top_win, &curr_path); - win_print_parent_dir(joshuto_view.left_win, &curr_path, pindex, (term_rows - 2) as usize); + win_print_parent_dir(&joshuto_view.left_win, &curr_path, pindex); - win_contents_refresh_indexed(joshuto_view.mid_win, &dir_contents, (term_rows - 2) as usize, index); + joshuto_view.mid_win.display_contents(&dir_contents, index); if dir_contents.len() > 0 { - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); - win_print_file_info(joshuto_view.bot_win, &dir_contents[index]); + win_print_file_preview(&joshuto_view.right_win, &dir_contents[index]); + win_print_file_info(joshuto_view.bot_win.win, &dir_contents[index]); } ncurses::refresh(); @@ -533,20 +571,18 @@ pub fn run(_config : &JoshutoConfig) break; }, ncurses::KEY_RESIZE => { - ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols); - ncurses::clear(); joshuto_view.redraw_views(term_rows, term_cols); ncurses::refresh(); - win_print_path(joshuto_view.top_win, &curr_path); - win_print_parent_dir(joshuto_view.left_win, &curr_path, pindex, (term_rows - 2) as usize); - win_contents_refresh_indexed(joshuto_view.mid_win, &dir_contents, - (term_rows - 2) as usize, index); + win_print_path(&joshuto_view.top_win, &curr_path); + win_print_parent_dir(&joshuto_view.left_win, &curr_path, pindex); + joshuto_view.mid_win.display_contents(&dir_contents, index); if dir_contents.len() > 0 { - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); - win_print_file_info(joshuto_view.bot_win, &dir_contents[index]); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); + win_print_file_info(joshuto_view.bot_win.win, + &dir_contents[index]); } ncurses::refresh(); @@ -555,30 +591,30 @@ pub fn run(_config : &JoshutoConfig) ncurses::KEY_HOME => { if index != 0 { index = 0; - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); } }, ncurses::KEY_END => { let tmp_len = dir_contents.len(); if index + 1 != tmp_len { index = tmp_len - 1; - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); } }, ncurses::KEY_UP => { if index > 0 { index = index - 1; - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); } }, ncurses::KEY_DOWN => { if index + 1 < dir_contents.len() { index = index + 1; - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); } }, ncurses::KEY_NPAGE => { @@ -591,8 +627,8 @@ pub fn run(_config : &JoshutoConfig) } else { index = tmp_len - 1; } - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); }, ncurses::KEY_PPAGE => { if index == 0 { @@ -603,64 +639,75 @@ pub fn run(_config : &JoshutoConfig) } else { index = 0; } - win_print_file_preview(joshuto_view.right_win, &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); }, ncurses::KEY_LEFT => { if curr_path.parent() == None { - ncurses::wclear(joshuto_view.left_win); - ncurses::wrefresh(joshuto_view.left_win); + ncurses::wclear(joshuto_view.left_win.win); + ncurses::wrefresh(joshuto_view.left_win.win); continue; } if curr_path.pop() == false { continue; } - match dirent_list(&curr_path) { + env::set_current_dir(curr_path.as_path()); + match curr_dirent_list() { Ok(s) => { dir_contents = s; dir_contents.sort_by(&sort_func); index = pindex; - win_print_parent_dir(joshuto_view.left_win, &curr_path, pindex, - (term_rows - 2) as usize); + win_print_parent_dir(&joshuto_view.left_win, + &curr_path, pindex); - win_print_path(joshuto_view.top_win, &curr_path); - win_print_file_preview(joshuto_view.right_win, - &dir_contents[index], - (term_rows - 2) as usize); + win_print_path(&joshuto_view.top_win, &curr_path); + win_print_file_preview(&joshuto_view.right_win, + &dir_contents[index]); }, Err(e) => { - win_print_err_msg(joshuto_view.bot_win, format!("{}", e).as_str()); + win_print_err_msg(&joshuto_view.bot_win, + format!("{}", e).as_str()); }, }; }, ncurses::KEY_RIGHT | ENTER => { if let Ok(file_type) = &dir_contents[index as usize].file_type() { if file_type.is_dir() { - let tmp_name : ffi::OsString = dir_contents[index as usize].file_name(); + let tmp_name : ffi::OsString = + dir_contents[index as usize].file_name(); let tmp_name2 = tmp_name.as_os_str().to_str().unwrap(); let file_name = path::Path::new(tmp_name2); curr_path.push(file_name); - match dirent_list(&curr_path) { - Ok(s) => { - dir_contents = s; - dir_contents.sort_by(&sort_func); - } - Err(_e) => { - process::exit(1); + match env::set_current_dir(&curr_path) { + Ok(_s) => { + match curr_dirent_list() { + Ok(s) => { + dir_contents = s; + dir_contents.sort_by(&sort_func); + } + Err(_e) => { + process::exit(1); + } + } + index = 0; + + win_print_path(&joshuto_view.top_win, &curr_path); + win_print_parent_dir(&joshuto_view.left_win, + &curr_path, pindex); + + if dir_contents.len() > 0 { + win_print_file_preview( + &joshuto_view.right_win, + &dir_contents[index]); + } + }, + Err(e) => { + win_print_err_msg(&joshuto_view.bot_win, + format!("{}", e).as_str()); } } - index = 0; - - win_print_path(joshuto_view.top_win, &curr_path); - win_print_parent_dir(joshuto_view.left_win, &curr_path, pindex, - (term_rows - 2) as usize); - if dir_contents.len() > 0 { - win_print_file_preview(joshuto_view.right_win, - &dir_contents[index], - (term_rows - 2) as usize); - } } else if file_type.is_symlink() { let mut file_path : path::PathBuf = dir_contents[index as usize].path(); @@ -673,7 +720,8 @@ pub fn run(_config : &JoshutoConfig) let tmp_name2 = tmp_name.as_os_str().to_str().unwrap(); let file_name = path::Path::new(tmp_name2); curr_path.push(file_name); - match dirent_list(&curr_path) { + env::set_current_dir(&curr_path); + match curr_dirent_list() { Ok(s) => { dir_contents = s; dir_contents.sort_by(&sort_func); @@ -684,22 +732,22 @@ pub fn run(_config : &JoshutoConfig) } index = 0; - win_print_path(joshuto_view.top_win, &curr_path); - win_print_parent_dir(joshuto_view.left_win, &curr_path, pindex, - (term_rows - 2) as usize); + win_print_path(&joshuto_view.top_win, + &curr_path); + win_print_parent_dir(&joshuto_view.left_win, + &curr_path, pindex); if dir_contents.len() > 0 { - win_print_file_preview(joshuto_view.right_win, - &dir_contents[index], - (term_rows - 2) as usize); + win_print_file_preview(&joshuto_view.right_win, &dir_contents[index]); } } }, Err(e) => { - win_print_err_msg(joshuto_view.bot_win, format!("{}", e).as_str()); + win_print_err_msg(&joshuto_view.bot_win, + format!("{}", e).as_str()); }, }; } else { - win_print_err_msg(joshuto_view.right_win, "Nice"); + win_print_err_msg(&joshuto_view.right_win, "Nice"); } } }, @@ -708,9 +756,8 @@ pub fn run(_config : &JoshutoConfig) }, }; - win_contents_refresh_indexed(joshuto_view.mid_win, &dir_contents, - (term_rows - 2) as usize, index); - win_print_file_info(joshuto_view.bot_win, &dir_contents[index]); + joshuto_view.mid_win.display_contents(&dir_contents, index); + win_print_file_info(joshuto_view.bot_win.win, &dir_contents[index]); } ncurses::endwin(); } diff --git a/src/joshuto_unix.rs b/src/joshuto_unix.rs index 1f2e3cb..ef40ea6 100644 --- a/src/joshuto_unix.rs +++ b/src/joshuto_unix.rs @@ -20,12 +20,9 @@ pub fn is_executable(mode : u32) -> bool for val in LIBC_PERMISSION_VALS.iter() { if mode & val != 0 { - eprintln!("true:"); return true; } - eprintln!("mode & val: {}", mode & val); } - eprintln!("false:"); return false; } diff --git a/src/main.rs b/src/main.rs index 3459f38..8bb290c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ extern crate ncurses; extern crate toml; extern crate xdg; +use std::char; use std::env; use std::fs; @@ -72,6 +73,7 @@ fn get_config() -> JoshutoConfig } } +#[cfg(not(feature = "wide"))] fn main() { let args: Vec<String> = env::args().collect(); |