diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-12 11:12:16 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-12 11:12:16 -0500 |
commit | 8d0f371ae5f0a1a51d5b73969cc837ecfa3adce1 (patch) | |
tree | e03a2bc2073d4de3ace17efdc57eb8f47da1c9ad | |
parent | c43d20bb002f90136ce63390bd3ee30dbf1a38d6 (diff) |
add support for custom color themes
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | config/keymap.toml | 21 | ||||
-rw-r--r-- | config/theme.toml | 105 | ||||
-rw-r--r-- | src/joshuto.rs | 39 | ||||
-rw-r--r-- | src/joshuto/command/change_directory.rs | 15 | ||||
-rw-r--r-- | src/joshuto/command/cursor_move.rs | 9 | ||||
-rw-r--r-- | src/joshuto/command/file_operation.rs | 67 | ||||
-rw-r--r-- | src/joshuto/command/new_directory.rs | 10 | ||||
-rw-r--r-- | src/joshuto/command/open_file.rs | 15 | ||||
-rw-r--r-- | src/joshuto/command/parent_directory.rs | 22 | ||||
-rw-r--r-- | src/joshuto/command/reload_dir.rs | 21 | ||||
-rw-r--r-- | src/joshuto/command/show_hidden.rs | 10 | ||||
-rw-r--r-- | src/joshuto/command/tab_switch.rs | 11 | ||||
-rw-r--r-- | src/joshuto/config/mimetype.rs | 26 | ||||
-rw-r--r-- | src/joshuto/config/theme.rs | 159 | ||||
-rw-r--r-- | src/joshuto/structs.rs | 8 | ||||
-rw-r--r-- | src/joshuto/ui.rs | 217 |
17 files changed, 422 insertions, 334 deletions
@@ -32,7 +32,6 @@ xdg = "2.2.0" # whoami = "*" # xdg = "*" - [dependencies.ncurses] version = "5.98.0" features = [ "extended_colors", "panel" ] diff --git a/config/keymap.toml b/config/keymap.toml index de5dccd..48f5ac3 100644 --- a/config/keymap.toml +++ b/config/keymap.toml @@ -111,24 +111,24 @@ command = "mkdir" [[mapcommand]] -keys = [ "g", "d" ] +keys = [ "g", "r" ] command = "cd" -args = [ "~/Downloads" ] +args = [ "/" ] [[mapcommand]] -keys = [ "g", "h" ] +keys = [ "g", "e" ] command = "cd" -args = [ "~/" ] +args = [ "/etc" ] [[mapcommand]] -keys = [ "g", "r" ] +keys = [ "g", "h" ] command = "cd" -args = [ "/" ] +args = [ "~/" ] [[mapcommand]] -keys = [ "g", "e" ] +keys = [ "g", "b" ] command = "cd" -args = [ "/etc" ] +args = [ "~/builds" ] [[mapcommand]] keys = [ "/" ] @@ -153,6 +153,11 @@ keys = [ "]" ] command = "tab_switch" args = [ "1" ] +[[mapcommand]] +keys = [ "Tab" ] +command = "tab_switch" +args = [ "1" ] + ## Features not yet implemented [[mapcommand]] diff --git a/config/theme.toml b/config/theme.toml new file mode 100644 index 0000000..045f0d8 --- /dev/null +++ b/config/theme.toml @@ -0,0 +1,105 @@ +# 0 -> black +# 1 -> red +# 2 -> green +# 3 -> yellow +# 4 -> blue +# 5 -> magenta +# 6 -> cyan +# 7 -> white +# -1 -> default (transparent) + +[[colorpair]] +id = 2 +fg = 2 +bg = -1 + +[[colorpair]] +id = 3 +fg = 3 +bg = -1 + +[[colorpair]] +id = 4 +fg = 4 +bg = -1 + +[[colorpair]] +id = 5 +fg = 5 +bg = -1 + +[[colorpair]] +id = 6 +fg = 6 +bg = -1 + +[executable] +colorpair = 2 +bold = true +underline = false + +[selection] +colorpair = 3 +bold = true +underline = false + +[directory] +colorpair = 4 +bold = true +underline = false + +[link] +colorpair = 6 +bold = true +underline = false + +[socket] +colorpair = 6 +bold = true +underline = false + +[ext] + [ext.jpg] + colorpair = 3 + bold = false + underline = true + + [ext.jpeg] + colorpair = 3 + bold = false + underline = true + + [ext.png] + colorpair = 3 + bold = false + underline = true + + [ext.wav] + colorpair = 5 + bold = false + underline = true + + [ext.flac] + colorpair = 5 + bold = false + underline = true + + [ext.mp3] + colorpair = 5 + bold = false + underline = true + + [ext.mp4] + colorpair = 5 + bold = false + underline = true + + [ext.m4a] + colorpair = 5 + bold = false + underline = true + + [ext.webm] + colorpair = 5 + bold = false + underline = true diff --git a/src/joshuto.rs b/src/joshuto.rs index aa32590..2e44735 100644 --- a/src/joshuto.rs +++ b/src/joshuto.rs @@ -25,8 +25,8 @@ use self::command::JoshutoCommand; pub struct JoshutoTab { pub history: history::DirHistory, pub curr_path: path::PathBuf, - pub curr_list: Option<structs::JoshutoDirList>, pub parent_list: Option<structs::JoshutoDirList>, + pub curr_list: Option<structs::JoshutoDirList>, pub preview_list: Option<structs::JoshutoDirList>, } @@ -223,21 +223,8 @@ pub fn resize_handler(context: &mut JoshutoContext) { context.views.redraw_views(); ncurses::refresh(); - - let parent_list = context.tabs[context.tab_index].parent_list.as_ref(); - let curr_list = context.tabs[context.tab_index].curr_list.as_ref(); - let preview_list = context.tabs[context.tab_index].preview_list.as_ref(); - let curr_path = &context.tabs[context.tab_index].curr_path; - - ui::redraw_view(&context.views.left_win, parent_list); - ui::redraw_view(&context.views.mid_win, curr_list); - ui::redraw_view(&context.views.right_win, preview_list); - - ui::redraw_status(&context.views, curr_list, curr_path, - &context.username, &context.hostname); - + ui::refresh(&context); ui::redraw_tab_view(&context.views.tab_win, &context); - ncurses::doupdate(); } @@ -246,7 +233,7 @@ pub fn run(mut config_t: config::JoshutoConfig, mimetype_t: config::JoshutoMimetype, theme_t: config::JoshutoTheme) { - ui::init_ncurses(); + ui::init_ncurses(&theme_t); ncurses::doupdate(); @@ -281,7 +268,7 @@ pub fn run(mut config_t: config::JoshutoConfig, ncurses::werase(context.views.bot_win.win); let curr_list = context.tabs[context.tab_index].curr_list.as_ref(); let curr_path = &context.tabs[context.tab_index].curr_path; - ui::redraw_status(&context.views, curr_list, curr_path, + ui::redraw_status(&context.theme_t, &context.views, curr_list, curr_path, &context.username, &context.hostname); ncurses::doupdate(); something_finished = true; @@ -289,7 +276,7 @@ pub fn run(mut config_t: config::JoshutoConfig, } else { let percent = (progress_info.bytes_finished as f64 / progress_info.total_bytes as f64) as f32; - ui::draw_loading_bar(&context.views.bot_win, percent); + ui::draw_loading_bar(&context.theme_t, &context.views.bot_win, percent); ncurses::wnoutrefresh(context.views.bot_win.win); ncurses::doupdate(); } @@ -297,21 +284,7 @@ pub fn run(mut config_t: config::JoshutoConfig, } if something_finished { - context.reload_dirlists(); - - let parent_list = context.tabs[context.tab_index].parent_list.as_ref(); - let curr_list = context.tabs[context.tab_index].curr_list.as_ref(); - let preview_list = context.tabs[context.tab_index].preview_list.as_ref(); - let curr_path = &context.tabs[context.tab_index].curr_path; - - ui::redraw_view(&context.views.left_win, parent_list); - ui::redraw_view(&context.views.mid_win, curr_list); - ui::redraw_view(&context.views.right_win, preview_list); - - ui::redraw_status(&context.views, curr_list, curr_path, - &context.username, &context.hostname); - - ncurses::doupdate(); + command::ReloadDirList::reload(&mut context); } } diff --git a/src/joshuto/command/change_directory.rs b/src/joshuto/command/change_directory.rs index 30e6938..14bd192 100644 --- a/src/joshuto/command/change_directory.rs +++ b/src/joshuto/command/change_directory.rs @@ -102,11 +102,16 @@ impl command::Runnable for ChangeDirectory { }; } - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), &curr_tab.curr_path, + ui::redraw_view(&context.theme_t, &context.views.left_win, + curr_tab.parent_list.as_ref()); + ui::redraw_view_detailed(&context.theme_t, &context.views.mid_win, + curr_tab.curr_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.right_win, + curr_tab.preview_list.as_ref()); + + ui::redraw_status(&context.theme_t, &context.views, + curr_tab.curr_list.as_ref(), + &curr_tab.curr_path, &context.username, &context.hostname); ncurses::doupdate(); diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs index 27fd6e4..f8496ee 100644 --- a/src/joshuto/command/cursor_move.rs +++ b/src/joshuto/command/cursor_move.rs @@ -56,7 +56,7 @@ impl CursorMove { let curr_index = curr_list.index as usize; let new_path = &curr_list.contents[curr_index].path; - curr_list.display_contents(&context.views.mid_win); + ui::display_contents(&context.theme_t, &context.views.mid_win, curr_list); ncurses::wnoutrefresh(context.views.mid_win.win); if new_path.is_dir() { @@ -64,7 +64,8 @@ impl CursorMove { &context.config_t.sort_type) { Ok(s) => { curr_tab.preview_list = Some(s); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.right_win, + curr_tab.preview_list.as_ref()); }, Err(e) => ui::wprint_err(&context.views.right_win, e.to_string().as_str()), } @@ -73,7 +74,9 @@ impl CursorMove { ncurses::wnoutrefresh(context.views.right_win.win); } - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), &curr_tab.curr_path, + ui::redraw_status(&context.theme_t, &context.views, + curr_tab.curr_list.as_ref(), + &curr_tab.curr_path, &context.username, &context.hostname); ncurses::doupdate(); diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs index 69d5557..a67547c 100644 --- a/src/joshuto/command/file_operation.rs +++ b/src/joshuto/command/file_operation.rs @@ -246,13 +246,7 @@ impl command::Runnable for PasteFiles { ncurses::timeout(0); - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), - &curr_tab.curr_path, - &context.username, &context.hostname); + ui::refresh(&context); ncurses::doupdate(); } @@ -265,37 +259,16 @@ impl DeleteFiles { pub fn new() -> Self { DeleteFiles } pub fn command() -> &'static str { "delete_files" } - pub fn remove_files(paths: Vec<path::PathBuf>, win: &window::JoshutoPanel) + pub fn remove_files(paths: Vec<path::PathBuf>) { - let (tx, rx) = sync::mpsc::channel(); - let total = paths.len(); - - let _child = thread::spawn(move || { - let mut deleted = 0; - for path in &paths { - if let Ok(metadata) = std::fs::symlink_metadata(path) { - if metadata.is_dir() { - std::fs::remove_dir_all(&path).unwrap(); - } else { - std::fs::remove_file(&path).unwrap(); - } + for path in &paths { + if let Ok(metadata) = std::fs::symlink_metadata(path) { + if metadata.is_dir() { + std::fs::remove_dir_all(&path).unwrap(); + } else { + std::fs::remove_file(&path).unwrap(); } - deleted = deleted + 1; - tx.send(deleted).unwrap(); - } - }); - - while let Ok(deleted) = rx.recv() { - if deleted == total { - ncurses::werase(win.win); - ncurses::wnoutrefresh(win.win); - ncurses::doupdate(); - break; } - let percent = (deleted as f64 / total as f64) as f32; - ui::draw_loading_bar(win, percent); - ncurses::wnoutrefresh(win.win); - ncurses::doupdate(); } } } @@ -320,7 +293,7 @@ impl command::Runnable for DeleteFiles { if ch == 'y' as i32 || ch == keymap::ENTER as i32 { if let Some(s) = context.tabs[context.tab_index].curr_list.as_ref() { if let Some(paths) = command::collect_selected_paths(s) { - Self::remove_files(paths, &context.views.bot_win); + Self::remove_files(paths); } } context.reload_dirlists(); @@ -328,12 +301,16 @@ impl command::Runnable for DeleteFiles { ui::wprint_msg(&context.views.bot_win, "Deleted files"); let curr_tab = &context.tabs[context.tab_index]; - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.left_win, + curr_tab.parent_list.as_ref()); + ui::redraw_view_detailed(&context.theme_t, &context.views.mid_win, + curr_tab.curr_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.right_win, + curr_tab.preview_list.as_ref()); } else { let curr_tab = &context.tabs[context.tab_index]; - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), + ui::redraw_status(&context.theme_t, &context.views, + curr_tab.curr_list.as_ref(), &curr_tab.curr_path, &context.username, &context.hostname); } @@ -390,15 +367,7 @@ impl RenameFile { match fs::rename(&path, &new_path) { Ok(_) => { context.reload_dirlists(); - - let curr_tab = &context.tabs[context.tab_index]; - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), - &curr_tab.curr_path, - &context.username, &context.hostname); + ui::refresh(&context); }, Err(e) => { ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); diff --git a/src/joshuto/command/new_directory.rs b/src/joshuto/command/new_directory.rs index 94ce880..0cdd407 100644 --- a/src/joshuto/command/new_directory.rs +++ b/src/joshuto/command/new_directory.rs @@ -50,15 +50,7 @@ impl command::Runnable for NewDirectory { match std::fs::create_dir_all(&path) { Ok(_) => { context.reload_dirlists(); - - let curr_tab = &context.tabs[context.tab_index]; - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), - &curr_tab.curr_path, - &context.username, &context.hostname); + ui::refresh(&context); }, Err(e) => { ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); diff --git a/src/joshuto/command/open_file.rs b/src/joshuto/command/open_file.rs index 683bf36..27b5cf5 100644 --- a/src/joshuto/command/open_file.rs +++ b/src/joshuto/command/open_file.rs @@ -112,11 +112,16 @@ impl OpenFile { } } - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), &curr_tab.curr_path, + ui::redraw_view(&context.theme_t, &context.views.left_win, + curr_tab.parent_list.as_ref()); + ui::redraw_view_detailed(&context.theme_t, &context.views.mid_win, + curr_tab.curr_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.right_win, + curr_tab.preview_list.as_ref()); + + ui::redraw_status(&context.theme_t, &context.views, + curr_tab.curr_list.as_ref(), + &curr_tab.curr_path, &context.username, &context.hostname); ncurses::doupdate(); diff --git a/src/joshuto/command/parent_directory.rs b/src/joshuto/command/parent_directory.rs index c854910..c11eac7 100644 --- a/src/joshuto/command/parent_directory.rs +++ b/src/joshuto/command/parent_directory.rs @@ -29,6 +29,7 @@ impl std::fmt::Display for ParentDirectory { impl command::Runnable for ParentDirectory { fn execute(&self, context: &mut joshuto::JoshutoContext) { + let curr_tab = &mut context.tabs[context.tab_index]; if curr_tab.curr_path.pop() == false { @@ -51,10 +52,7 @@ impl command::Runnable for ParentDirectory { match curr_tab.curr_path.parent() { Some(parent) => { curr_tab.parent_list = match curr_tab.history.pop_or_create(&parent, &context.config_t.sort_type) { - Ok(s) => { - s.display_contents(&context.views.left_win); - Some(s) - }, + Ok(s) => Some(s), Err(e) => { ui::wprint_err(&context.views.left_win, e.to_string().as_str()); None @@ -66,12 +64,18 @@ impl command::Runnable for ParentDirectory { ncurses::wnoutrefresh(context.views.left_win.win); }, } - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), &curr_tab.curr_path, - &context.username, &&context.hostname); + ui::redraw_view(&context.theme_t, &context.views.left_win, + curr_tab.parent_list.as_ref()); + ui::redraw_view_detailed(&context.theme_t, &context.views.mid_win, + curr_tab.curr_list.as_ref()); + ui::redraw_view(&context.theme_t, &context.views.right_win, + curr_tab.preview_list.as_ref()); + + ui::redraw_status(&context.theme_t, &context.views, + curr_tab.curr_list.as_ref(), + &curr_tab.curr_path, + &context.username, &context.hostname); }, Err(e) => { ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); diff --git a/src/joshuto/command/reload_dir.rs b/src/joshuto/command/reload_dir.rs index 834667e..c262359 100644 --- a/src/joshuto/command/reload_dir.rs +++ b/src/joshuto/command/reload_dir.rs @@ -15,6 +15,13 @@ pub struct ReloadDirList; impl ReloadDirList { pub fn new() -> Self { ReloadDirList } pub fn command() -> &'static str { "reload_dir_list" } + + pub fn reload(context: &mut joshuto::JoshutoContext) + { + context.reload_dirlists(); + ui::refresh(&context); + ncurses::doupdate(); + } } impl command::JoshutoCommand for ReloadDirList {} @@ -29,18 +36,6 @@ impl std::fmt::Display for ReloadDirList { impl command::Runnable for ReloadDirList { fn execute(&self, context: &mut joshuto::JoshutoContext) { - context.reload_dirlists(); - - let curr_tab = &mut context.tabs[context.tab_index]; - - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), - &curr_tab.curr_path, - &context.username, &context.hostname); - - ncurses::doupdate(); + Self::reload(context); } } diff --git a/src/joshuto/command/show_hidden.rs b/src/joshuto/command/show_hidden.rs index e0a2e15..853c7b7 100644 --- a/src/joshuto/command/show_hidden.rs +++ b/src/joshuto/command/show_hidden.rs @@ -48,15 +48,7 @@ impl command::Runnable for ToggleHiddenFiles { } } - let curr_tab = &context.tabs[context.tab_index]; - - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), - &curr_tab.curr_path, - &context.username, &context.hostname); + ui::refresh(&context); ncurses::doupdate(); } diff --git a/src/joshuto/command/tab_switch.rs b/src/joshuto/command/tab_switch.rs index f44fa4b..4c38fa0 100644 --- a/src/joshuto/command/tab_switch.rs +++ b/src/joshuto/command/tab_switch.rs @@ -21,16 +21,7 @@ impl TabSwitch { pub fn tab_switch(new_index: i32, context: &mut joshuto::JoshutoContext) { context.tab_index = new_index as usize; - - let curr_tab = &context.tabs[context.tab_index]; - - ui::redraw_view(&context.views.left_win, curr_tab.parent_list.as_ref()); - ui::redraw_view(&context.views.mid_win, curr_tab.curr_list.as_ref()); - ui::redraw_view(&context.views.right_win, curr_tab.preview_list.as_ref()); - - ui::redraw_status(&context.views, curr_tab.curr_list.as_ref(), &curr_tab.curr_path, - &context.username, &context.hostname); - + ui::refresh(&context); ui::redraw_tab_view(&context.views.tab_win, &context); ncurses::doupdate(); diff --git a/src/joshuto/config/mimetype.rs b/src/joshuto/config/mimetype.rs index 991103e..5b0bc94 100644 --- a/src/joshuto/config/mimetype.rs +++ b/src/joshuto/config/mimetype.rs @@ -17,16 +17,24 @@ pub struct JoshutoMimetypeEntry { impl std::fmt::Display for JoshutoMimetypeEntry { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut fmt_result = f.write_str(self.program.as_str()); - match self.args.as_ref() { - Some(s) => { - for arg in s { - fmt_result = write!(f, " {}", arg); - } - }, - None => {}, + f.write_str(self.program.as_str()).unwrap(); + if let Some(s) = self.args.as_ref() { + for arg in s { + write!(f, " {}", arg).unwrap(); + } + } + f.write_str("\t[").unwrap(); + if let Some(s) = self.fork { + if s { + f.write_str("fork,").unwrap(); + } + } + if let Some(s) = self.silent { + if s { + f.write_str("silent").unwrap(); + } } - fmt_result + f.write_str("]") } } diff --git a/src/joshuto/config/theme.rs b/src/joshuto/config/theme.rs index cf15d4a..350da3d 100644 --- a/src/joshuto/config/theme.rs +++ b/src/joshuto/config/theme.rs @@ -6,80 +6,96 @@ use std::fs; use std::process; #[derive(Debug, Deserialize, Clone)] +pub struct JoshutoColorPair { + pub id: i16, + pub fg: i16, + pub bg: i16, +} + +impl JoshutoColorPair { + pub fn new(id: i16, fg: i16, bg: i16) -> Self + { + JoshutoColorPair { + id, + fg, + bg, + } + } +} + +#[derive(Debug, Deserialize, Clone)] pub struct JoshutoColorTheme { - fg: i16, - bg: i16, - bold: bool, - underline: bool, + pub colorpair: i16, + pub bold: bool, + pub underline: bool, } #[derive(Debug, Deserialize)] pub struct JoshutoRawTheme { + colorpair: Option<Vec<JoshutoColorPair>>, selection: Option<JoshutoColorTheme>, directory: Option<JoshutoColorTheme>, executable: Option<JoshutoColorTheme>, link: Option<JoshutoColorTheme>, + socket: Option<JoshutoColorTheme>, ext: Option<HashMap<String, JoshutoColorTheme>>, } impl JoshutoRawTheme { - #[allow(dead_code)] - pub fn new() -> Self - { - JoshutoRawTheme { - selection: None, - directory: None, - executable: None, - link: None, - ext: None, - } - } - pub fn flatten(self) -> JoshutoTheme { - let selection = self.selection.unwrap_or( - JoshutoColorTheme { - fg: ncurses::COLOR_YELLOW, - bg: -1, - bold: true, - underline: false, + let colorpair = match self.colorpair { + Some(s) => s, + None => { + let mut colorpair: Vec<JoshutoColorPair> = Vec::with_capacity(10); + colorpair.push(JoshutoColorPair::new(2, 2, -1)); + colorpair.push(JoshutoColorPair::new(3, 3, -1)); + colorpair.push(JoshutoColorPair::new(4, 4, -1)); + colorpair.push(JoshutoColorPair::new(5, 5, -1)); + colorpair.push(JoshutoColorPair::new(6, 6, -1)); + colorpair } - ); - - let directory = self.directory.unwrap_or( - JoshutoColorTheme { - fg: ncurses::COLOR_BLUE, - bg: -1, - bold: true, - underline: false, - } - ); - - let executable = self.executable.unwrap_or( - JoshutoColorTheme { - fg: ncurses::COLOR_GREEN, - bg: -1, - bold: true, - underline: false, - } - ); - - let link = self.link.unwrap_or( - JoshutoColorTheme { - fg: ncurses::COLOR_CYAN, - bg: -1, - bold: true, - underline: false, - } - ); + }; + + let executable = JoshutoColorTheme { + colorpair: 2, + bold: true, + underline: false, + }; + + let selection = JoshutoColorTheme { + colorpair: 3, + bold: true, + underline: false, + }; + + let directory = JoshutoColorTheme { + colorpair: 4, + bold: true, + underline: false, + }; + + let link = JoshutoColorTheme { + colorpair: 6, + bold: true, + underline: false, + }; + + let socket = JoshutoColorTheme { + colorpair: 6, + bold: true, + underline: false, + }; let ext = self.ext.unwrap_or(HashMap::new()); JoshutoTheme { + colorpair, directory, selection, executable, link, + socket, ext, } } @@ -87,49 +103,62 @@ impl JoshutoRawTheme { #[derive(Debug, Clone)] pub struct JoshutoTheme { - selection: JoshutoColorTheme, - directory: JoshutoColorTheme, - executable: JoshutoColorTheme, - link: JoshutoColorTheme, - ext: HashMap<String, JoshutoColorTheme> + pub colorpair: Vec<JoshutoColorPair>, + pub selection: JoshutoColorTheme, + pub directory: JoshutoColorTheme, + pub executable: JoshutoColorTheme, + pub link: JoshutoColorTheme, + pub socket: JoshutoColorTheme, + pub ext: HashMap<String, JoshutoColorTheme> } impl JoshutoTheme { pub fn new() -> Self { + let mut colorpair: Vec<JoshutoColorPair> = Vec::with_capacity(10); + colorpair.push(JoshutoColorPair::new(2, 2, -1)); + colorpair.push(JoshutoColorPair::new(3, 3, -1)); + colorpair.push(JoshutoColorPair::new(4, 4, -1)); + colorpair.push(JoshutoColorPair::new(5, 5, -1)); + colorpair.push(JoshutoColorPair::new(6, 6, -1)); + + let executable = JoshutoColorTheme { + colorpair: 2, + bold: true, + underline: false, + }; + let selection = JoshutoColorTheme { - fg: ncurses::COLOR_YELLOW, - bg: -1, + colorpair: 3, bold: true, underline: false, }; let directory = JoshutoColorTheme { - fg: ncurses::COLOR_BLUE, - bg: -1, + colorpair: 4, bold: true, underline: false, }; - let executable = JoshutoColorTheme { - fg: ncurses::COLOR_GREEN, - bg: -1, + let link = JoshutoColorTheme { + colorpair: 6, bold: true, underline: false, }; - let link = JoshutoColorTheme { - fg: ncurses::COLOR_CYAN, - bg: -1, + let socket = JoshutoColorTheme { + colorpair: 6, bold: true, underline: false, }; JoshutoTheme { + colorpair, directory, selection, executable, link, + socket, ext: HashMap::new(), } |