diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/joshuto.rs | 22 | ||||
-rw-r--r-- | src/joshuto/command/change_directory.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/cursor_move.rs | 4 | ||||
-rw-r--r-- | src/joshuto/command/delete_file.rs | 4 | ||||
-rw-r--r-- | src/joshuto/command/file_operation.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/open_file.rs | 18 | ||||
-rw-r--r-- | src/joshuto/command/parent_directory.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/reload_dir.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/rename_file.rs | 5 | ||||
-rw-r--r-- | src/joshuto/command/set_mode.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/show_hidden.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/tab_switch.rs | 2 | ||||
-rw-r--r-- | src/joshuto/context.rs | 37 | ||||
-rw-r--r-- | src/joshuto/structs.rs | 11 | ||||
-rw-r--r-- | src/joshuto/ui.rs | 15 | ||||
-rw-r--r-- | src/joshuto/window.rs | 25 | ||||
-rw-r--r-- | src/main.rs | 8 |
17 files changed, 72 insertions, 91 deletions
diff --git a/src/joshuto.rs b/src/joshuto.rs index b6ea64e..d87503d 100644 --- a/src/joshuto.rs +++ b/src/joshuto.rs @@ -18,10 +18,17 @@ mod ui; mod unix; mod window; +use self::config::JoshutoTheme; +use self::config::JoshutoMimetype; use self::context::JoshutoContext; use self::command::CommandKeybind; use self::command::JoshutoCommand; +lazy_static! { + static ref theme_t: JoshutoTheme = JoshutoTheme::get_config(); + static ref mimetype_t: JoshutoMimetype = JoshutoMimetype::get_config(); +} + fn recurse_get_keycommand<'a>(keymap: &'a HashMap<i32, CommandKeybind>) -> Option<&Box<dyn JoshutoCommand>> { @@ -79,7 +86,7 @@ fn process_threads(context: &mut JoshutoContext) } else { let percent = (progress_info.bytes_finished as f64 / progress_info.total_bytes as f64) as f32; - ui::draw_progress_bar(&context.theme_t, &context.views.bot_win, percent); + ui::draw_progress_bar(&context.views.bot_win, percent); ncurses::wnoutrefresh(context.views.bot_win.win); ncurses::doupdate(); } @@ -99,24 +106,21 @@ fn resize_handler(context: &mut JoshutoContext) { let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } preview::preview_file(context); ncurses::doupdate(); } -pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap, - mimetype_t: config::JoshutoMimetype, theme_t: config::JoshutoTheme) +pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap) { - ui::init_ncurses(&theme_t); + ui::init_ncurses(); ncurses::doupdate(); - let mut context = context::JoshutoContext::new(config_t, mimetype_t, theme_t); + let mut context = context::JoshutoContext::new(config_t); command::NewTab::new_tab(&mut context); - ncurses::refresh(); - - resize_handler(&mut context); + ncurses::doupdate(); while let Some(ch) = ncurses::get_wch() { let ch = match ch { diff --git a/src/joshuto/command/change_directory.rs b/src/joshuto/command/change_directory.rs index 67096be..b989dbe 100644 --- a/src/joshuto/command/change_directory.rs +++ b/src/joshuto/command/change_directory.rs @@ -70,7 +70,7 @@ impl ChangeDirectory { }; } - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } } diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs index 3f567e4..e08638a 100644 --- a/src/joshuto/command/cursor_move.rs +++ b/src/joshuto/command/cursor_move.rs @@ -45,9 +45,9 @@ impl CursorMove { curr_list.index = new_index; } - curr_tab.refresh_curr(&context.views.mid_win, &context.theme_t, context.config_t.scroll_offset); + curr_tab.refresh_curr(&context.views.mid_win, context.config_t.scroll_offset); curr_tab.refresh_file_status(&context.views.bot_win); - curr_tab.refresh_path_status(&context.views.top_win, &context.theme_t, &context.username, &context.hostname); + curr_tab.refresh_path_status(&context.views.top_win, &context.username, &context.hostname); } preview::preview_file(context); ncurses::doupdate(); diff --git a/src/joshuto/command/delete_file.rs b/src/joshuto/command/delete_file.rs index 0cb3c68..0a7afca 100644 --- a/src/joshuto/command/delete_file.rs +++ b/src/joshuto/command/delete_file.rs @@ -59,13 +59,13 @@ impl JoshutoRunnable for DeleteFiles { let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } else { let curr_tab = &context.tabs[context.curr_tab_index]; curr_tab.refresh_file_status(&context.views.bot_win); curr_tab.refresh_path_status(&context.views.top_win, - &context.theme_t, &context.username, &context.hostname); + &context.username, &context.hostname); } ncurses::doupdate(); } diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs index c159258..a0a01db 100644 --- a/src/joshuto/command/file_operation.rs +++ b/src/joshuto/command/file_operation.rs @@ -239,7 +239,7 @@ impl JoshutoRunnable for PasteFiles { context.threads.push(cprocess); curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); ncurses::timeout(0); ncurses::doupdate(); diff --git a/src/joshuto/command/open_file.rs b/src/joshuto/command/open_file.rs index c88af5e..317017e 100644 --- a/src/joshuto/command/open_file.rs +++ b/src/joshuto/command/open_file.rs @@ -17,6 +17,8 @@ use joshuto::ui; use joshuto::unix; use joshuto::window; +use joshuto::mimetype_t; + #[derive(Clone, Debug)] pub struct OpenFile; @@ -24,7 +26,7 @@ impl OpenFile { pub fn new() -> Self { OpenFile } pub const fn command() -> &'static str { "open_file" } - pub fn get_options<'a>(path: &path::PathBuf, mimetype_t: &'a mimetype::JoshutoMimetype) + pub fn get_options<'a>(path: &path::PathBuf) -> Vec<&'a mimetype::JoshutoMimetypeEntry> { let mut mimetype_options: Vec<&mimetype::JoshutoMimetypeEntry> = Vec::new(); @@ -99,9 +101,9 @@ impl OpenFile { } } - fn into_file(paths: &Vec<path::PathBuf>, context: &JoshutoContext) + fn into_file(paths: &Vec<path::PathBuf>) { - let mimetype_options = Self::get_options(&paths[0], &context.mimetype_t); + let mimetype_options = Self::get_options(&paths[0]); ncurses::savetty(); ncurses::endwin(); @@ -140,7 +142,7 @@ impl JoshutoRunnable for OpenFile { Self::into_directory(&path, context); { let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } preview::preview_file(context); @@ -152,7 +154,7 @@ impl JoshutoRunnable for OpenFile { }; if let Some(paths) = paths { if paths.len() > 0 { - Self::into_file(&paths, context); + Self::into_file(&paths); } else { ui::wprint_msg(&context.views.bot_win, "No files selected: 0"); } @@ -171,9 +173,9 @@ impl OpenFileWith { pub fn new() -> Self { OpenFileWith } pub const fn command() -> &'static str { "open_file_with" } - pub fn open_with(paths: &Vec<path::PathBuf>, mimetype_t: &mimetype::JoshutoMimetype) + pub fn open_with(paths: &Vec<path::PathBuf>) { - let mimetype_options: Vec<&mimetype::JoshutoMimetypeEntry> = OpenFile::get_options(&paths[0], mimetype_t); + let mimetype_options: Vec<&mimetype::JoshutoMimetypeEntry> = OpenFile::get_options(&paths[0]); let user_input: Option<String>; { let mut term_rows: i32 = 0; @@ -244,7 +246,7 @@ impl JoshutoRunnable for OpenFileWith { { if let Some(s) = context.tabs[context.curr_tab_index].curr_list.as_ref() { if let Some(paths) = command::collect_selected_paths(s) { - Self::open_with(&paths, &context.mimetype_t); + Self::open_with(&paths); } } } diff --git a/src/joshuto/command/parent_directory.rs b/src/joshuto/command/parent_directory.rs index 0a7be0e..d28a203 100644 --- a/src/joshuto/command/parent_directory.rs +++ b/src/joshuto/command/parent_directory.rs @@ -46,7 +46,7 @@ impl ParentDirectory { ncurses::wnoutrefresh(context.views.left_win.win); }, } - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } preview::preview_file(context); diff --git a/src/joshuto/command/reload_dir.rs b/src/joshuto/command/reload_dir.rs index a62485c..ab1cecd 100644 --- a/src/joshuto/command/reload_dir.rs +++ b/src/joshuto/command/reload_dir.rs @@ -18,7 +18,7 @@ impl ReloadDirList { { let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } } diff --git a/src/joshuto/command/rename_file.rs b/src/joshuto/command/rename_file.rs index a07e2ae..168e753 100644 --- a/src/joshuto/command/rename_file.rs +++ b/src/joshuto/command/rename_file.rs @@ -7,11 +7,9 @@ use joshuto::command::JoshutoCommand; use joshuto::command::JoshutoRunnable; use joshuto::context::JoshutoContext; use joshuto::preview; -use joshuto::structs::JoshutoDirList; use joshuto::textfield::JoshutoTextField; use joshuto::ui; - #[derive(Clone, Debug)] pub enum RenameFileMethod { Append, @@ -73,8 +71,7 @@ impl RenameFile { if let Some(ref mut s) = curr_tab.curr_list { s.update_contents(&context.config_t.sort_type).unwrap(); } - curr_tab.refresh_curr(&context.views.mid_win, - &context.theme_t, context.config_t.scroll_offset); + curr_tab.refresh_curr(&context.views.mid_win, context.config_t.scroll_offset); }, Err(e) => { ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); diff --git a/src/joshuto/command/set_mode.rs b/src/joshuto/command/set_mode.rs index a59ba82..ab16f68 100644 --- a/src/joshuto/command/set_mode.rs +++ b/src/joshuto/command/set_mode.rs @@ -89,7 +89,7 @@ impl JoshutoRunnable for SetMode { } if ok { let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.refresh_curr(&context.views.mid_win, &context.theme_t, context.config_t.scroll_offset); + curr_tab.refresh_curr(&context.views.mid_win, context.config_t.scroll_offset); curr_tab.refresh_file_status(&context.views.bot_win); } } diff --git a/src/joshuto/command/show_hidden.rs b/src/joshuto/command/show_hidden.rs index 5fb0629..9bfa1cf 100644 --- a/src/joshuto/command/show_hidden.rs +++ b/src/joshuto/command/show_hidden.rs @@ -39,7 +39,7 @@ impl JoshutoRunnable for ToggleHiddenFiles { Self::toggle_hidden(context); let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); ncurses::doupdate(); diff --git a/src/joshuto/command/tab_switch.rs b/src/joshuto/command/tab_switch.rs index 5202759..1562f02 100644 --- a/src/joshuto/command/tab_switch.rs +++ b/src/joshuto/command/tab_switch.rs @@ -24,7 +24,7 @@ impl TabSwitch { { let curr_tab = &mut context.tabs[context.curr_tab_index]; curr_tab.reload_contents(&context.config_t.sort_type); - curr_tab.refresh(&context.views, &context.theme_t, &context.config_t, + curr_tab.refresh(&context.views, &context.config_t, &context.username, &context.hostname); } diff --git a/src/joshuto/context.rs b/src/joshuto/context.rs index 156dc15..9d76806 100644 --- a/src/joshuto/context.rs +++ b/src/joshuto/context.rs @@ -14,6 +14,8 @@ use joshuto::ui; use joshuto::window::JoshutoView; use joshuto::window::JoshutoPanel; +use joshuto::theme_t; + pub struct JoshutoContext { pub username: String, pub hostname: String, @@ -23,14 +25,10 @@ pub struct JoshutoContext { pub tabs: Vec<JoshutoTab>, pub config_t: config::JoshutoConfig, - pub mimetype_t: config::JoshutoMimetype, - pub theme_t: config::JoshutoTheme, } impl<'a> JoshutoContext { - pub fn new(config_t: config::JoshutoConfig, - mimetype_t: config::JoshutoMimetype, - theme_t: config::JoshutoTheme) -> Self + pub fn new(config_t: config::JoshutoConfig) -> Self { let username: String = whoami::username(); let hostname: String = whoami::hostname(); @@ -46,8 +44,6 @@ impl<'a> JoshutoContext { curr_tab_index: 0, tabs: Vec::new(), config_t, - mimetype_t, - theme_t } } pub fn curr_tab_ref(&'a self) -> &'a JoshutoTab @@ -118,37 +114,33 @@ impl JoshutoTab { self.parent_list = list; } - pub fn refresh(&mut self, views: &JoshutoView, - theme_t: &config::JoshutoTheme, config_t: &config::JoshutoConfig, + pub fn refresh(&mut self, views: &JoshutoView, config_t: &config::JoshutoConfig, username: &str, hostname: &str) { - self.refresh_(views, theme_t, config_t.scroll_offset, username, hostname); + self.refresh_(views, config_t.scroll_offset, username, hostname); } - pub fn refresh_(&mut self, views: &JoshutoView, - theme_t: &config::JoshutoTheme, scroll_offset: usize, + pub fn refresh_(&mut self, views: &JoshutoView, scroll_offset: usize, username: &str, hostname: &str) { - self.refresh_curr(&views.mid_win, theme_t, scroll_offset); - self.refresh_parent(&views.left_win, theme_t, scroll_offset); - self.refresh_path_status(&views.top_win, theme_t, username, hostname); + self.refresh_curr(&views.mid_win, scroll_offset); + self.refresh_parent(&views.left_win, scroll_offset); + self.refresh_path_status(&views.top_win, username, hostname); self.refresh_file_status(&views.bot_win); } - pub fn refresh_curr(&mut self, win: &JoshutoPanel, - theme_t: &config::JoshutoTheme, scroll_offset: usize) + pub fn refresh_curr(&mut self, win: &JoshutoPanel, scroll_offset: usize) { if let Some(ref mut s) = self.curr_list { - win.display_contents_detailed(theme_t, s, scroll_offset); + win.display_contents_detailed(s, scroll_offset); win.queue_for_refresh(); } } - pub fn refresh_parent(&mut self, win: &JoshutoPanel, - theme_t: &config::JoshutoTheme, scroll_offset: usize) + pub fn refresh_parent(&mut self, win: &JoshutoPanel, scroll_offset: usize) { if let Some(ref mut s) = self.parent_list { - win.display_contents(theme_t, s, scroll_offset); + win.display_contents(s, scroll_offset); win.queue_for_refresh(); } } @@ -170,8 +162,7 @@ impl JoshutoTab { } } - pub fn refresh_path_status(&self, win: &JoshutoPanel, - theme_t: &config::JoshutoTheme, username: &str, hostname: &str) + pub fn refresh_path_status(&self, win: &JoshutoPanel, username: &str, hostname: &str) { let path_str: &str = self.curr_path.to_str().unwrap(); diff --git a/src/joshuto/structs.rs b/src/joshuto/structs.rs index a68e587..d2aba45 100644 --- a/src/joshuto/structs.rs +++ b/src/joshuto/structs.rs @@ -6,7 +6,6 @@ use std::time; use joshuto::sort; use joshuto::window::JoshutoPageState; -use joshuto::window::JoshutoPanel; #[derive(Clone, Debug)] pub struct JoshutoMetadata { @@ -49,7 +48,9 @@ impl JoshutoDirEntry { let file_name = direntry.file_name(); let file_name_as_string: String = match file_name.clone().into_string() { Ok(s) => s, - Err(_) => return Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Failed to get file_name")), + Err(_) => return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Failed to get file_name")), }; let path = direntry.path(); @@ -112,14 +113,12 @@ impl JoshutoDirList { }) } - fn read_dir_list(path : &path::Path, sort_type: &sort::SortType) + fn read_dir_list(path: &path::Path, sort_type: &sort::SortType) -> Result<Vec<JoshutoDirEntry>, std::io::Error> { let filter_func = sort_type.filter_func(); - let results: fs::ReadDir = fs::read_dir(path)?; - - let result_vec : Vec<JoshutoDirEntry> = results + let result_vec: Vec<JoshutoDirEntry> = results .filter_map(filter_func) .collect(); Ok(result_vec) diff --git a/src/joshuto/ui.rs b/src/joshuto/ui.rs index 4de3fa1..222561b 100644 --- a/src/joshuto/ui.rs +++ b/src/joshuto/ui.rs @@ -6,14 +6,15 @@ use std::time; use joshuto::context::JoshutoContext; use joshuto::structs; -use joshuto::config; use joshuto::unix; use joshuto::window; +use joshuto::theme_t; + pub const ERR_COLOR: i16 = 240; pub const EMPTY_COLOR: i16 = 241; -pub fn init_ncurses(theme_t: &config::JoshutoTheme) +pub fn init_ncurses() { let locale_conf = ncurses::LcCategory::all; @@ -28,7 +29,7 @@ pub fn init_ncurses(theme_t: &config::JoshutoTheme) ncurses::noecho(); ncurses::set_escdelay(0); - process_theme(&theme_t); + process_theme(); ncurses::printw("Loading..."); ncurses::curs_set(ncurses::CURSOR_VISIBILITY::CURSOR_INVISIBLE); @@ -36,7 +37,7 @@ pub fn init_ncurses(theme_t: &config::JoshutoTheme) ncurses::refresh(); } -fn process_theme(theme_t: &config::JoshutoTheme) +fn process_theme() { for pair in theme_t.colorpair.iter() { ncurses::init_pair(pair.id, pair.fg, pair.bg); @@ -217,16 +218,14 @@ pub fn redraw_tab_view(win: &window::JoshutoPanel, context: &JoshutoContext) ncurses::wnoutrefresh(win.win); } -pub fn draw_progress_bar(theme_t: &config::JoshutoTheme, - win: &window::JoshutoPanel, percentage: f32) +pub fn draw_progress_bar(win: &window::JoshutoPanel, percentage: f32) { let cols: i32 = (win.cols as f32 * percentage) as i32; ncurses::mvwchgat(win.win, 0, 0, cols, ncurses::A_STANDOUT(), theme_t.selection.colorpair); } -pub fn file_attr_apply(theme_t: &config::JoshutoTheme, - win: ncurses::WINDOW, coord: (i32, i32), mode: u32, +pub fn file_attr_apply(win: ncurses::WINDOW, coord: (i32, i32), mode: u32, extension: &str, attr: ncurses::attr_t) { match mode & unix::BITMASK { diff --git a/src/joshuto/window.rs b/src/joshuto/window.rs index fe82f08..3c2e959 100644 --- a/src/joshuto/window.rs +++ b/src/joshuto/window.rs @@ -1,17 +1,13 @@ extern crate ncurses; -use joshuto::config; use joshuto::structs; use joshuto::ui; +use joshuto::theme_t; + #[cfg(test)] mod test; -/* -lazy_static! { - static ref -} -*/ #[derive(Clone, Debug)] pub struct JoshutoPageState { @@ -123,24 +119,23 @@ impl JoshutoPanel { ncurses::wnoutrefresh(self.win); } - pub fn display_contents(&self, theme_t: &config::JoshutoTheme, - dirlist: &mut structs::JoshutoDirList, scroll_offset: usize) + pub fn display_contents(&self, dirlist: &mut structs::JoshutoDirList, + scroll_offset: usize) { if self.non_empty_dir_checks(dirlist, scroll_offset) { - Self::draw_dir_list(self, theme_t, dirlist, ui::wprint_entry); + Self::draw_dir_list(self, dirlist, ui::wprint_entry); } } - pub fn display_contents_detailed(&self, theme_t: &config::JoshutoTheme, - dirlist: &mut structs::JoshutoDirList, scroll_offset: usize) + pub fn display_contents_detailed(&self, dirlist: &mut structs::JoshutoDirList, + scroll_offset: usize) { if self.non_empty_dir_checks(dirlist, scroll_offset) { - Self::draw_dir_list(self, theme_t, dirlist, ui::wprint_entry_detailed); + Self::draw_dir_list(self, dirlist, ui::wprint_entry_detailed); } } - pub fn draw_dir_list(win: &JoshutoPanel, - theme_t: &config::JoshutoTheme, dirlist: &structs::JoshutoDirList, + pub fn draw_dir_list(win: &JoshutoPanel, dirlist: &structs::JoshutoDirList, draw_func: fn (&JoshutoPanel, &structs::JoshutoDirEntry, (i32, i32))) { use std::os::unix::fs::PermissionsExt; @@ -167,7 +162,7 @@ impl JoshutoPanel { extension = &file_name[ext+1..]; } - ui::file_attr_apply(theme_t, win.win, coord, mode, extension, attr); + ui::file_attr_apply(win.win, coord, mode, extension, attr); } } } diff --git a/src/main.rs b/src/main.rs index 4490e00..9ecfbf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,14 +28,8 @@ fn main() let config = joshuto::config::JoshutoConfig::get_config(); // println!("{:#?}", config); - let mimetype = joshuto::config::JoshutoMimetype::get_config(); -// println!("{:#?}", mimetype); - let keymap = joshuto::config::JoshutoKeymap::get_config(); // println!("{:#?}", keymap); - let theme = joshuto::config::JoshutoTheme::get_config(); -// println!("{:#?}", theme); - - joshuto::run(config, keymap, mimetype, theme); + joshuto::run(config, keymap); } |