diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-04-29 19:43:07 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-04-29 19:46:17 -0400 |
commit | 065ef4d5a1f5443de5726343323403477b0263b5 (patch) | |
tree | 5f9178bb33229b068c7e9b346d5b7e1c046b989b | |
parent | 10394fd7a2fb41e9eb6bea36e57b5270d50e5cbf (diff) |
rework config structure
- sort options is now nested under display options which
holds a lot of previously general options
- fix glob search not searching backwards
34 files changed, 469 insertions, 342 deletions
@@ -145,9 +145,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "crossbeam-utils" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -289,9 +289,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "log" @@ -553,9 +553,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" +checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" dependencies = [ "bitflags", ] @@ -566,7 +566,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" dependencies = [ - "redox_syscall 0.2.6", + "redox_syscall 0.2.7", ] [[package]] @@ -587,7 +587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom 0.2.2", - "redox_syscall 0.2.6", + "redox_syscall 0.2.7", ] [[package]] @@ -725,9 +725,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" +checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373" dependencies = [ "proc-macro2", "quote", @@ -742,7 +742,7 @@ checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" dependencies = [ "libc", "numtoa", - "redox_syscall 0.2.6", + "redox_syscall 0.2.7", "redox_termios", ] @@ -810,9 +810,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "users" @@ -33,12 +33,6 @@ xdg = "^2" phf = { version = "^0", features = ["macros"], optional = true } trash = { version = "^1", optional = true } -# [dependencies.wordexp] -# version = "^0" -# git = "https://github.com/kamiyaa/wordexp-rs" -# branch="dev" -# path = "lib/wordexp-rs" - [features] devicons = [ "phf" ] file_mimetype = [] diff --git a/config/joshuto.toml b/config/joshuto.toml index c6c9db5..7d8f6ce 100644 --- a/config/joshuto.toml +++ b/config/joshuto.toml @@ -1,26 +1,25 @@ -tilde_in_titlebar = true - -# ratios for parent view, current view and preview -column_ratio = [1, 4, 4] -collapse_preview = true - # currently does not work scroll_offset = 6 -show_borders = true -show_preview = true xdg_open = false use_trash = true # currently does not work max_preview_size = 2097152 # 2MB -# lexical, mtime, natural -sort_method = "natural" - -[sort_option] -show_icons = true +[display] +# ratios for parent view, current view and preview +collapse_preview = true +column_ratio = [1, 4, 4] +show_borders = true show_hidden = false +show_icons = true +show_preview = true +tilde_in_titlebar = true + +[display.sort] +# lexical, mtime, natural +method = "natural" case_sensitive = false directories_first = true reverse = false diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 49cf5b6..1e4ad06 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -13,12 +13,12 @@ pub fn cd(path: &path::Path, context: &mut JoshutoContext) -> std::io::Result<() fn _change_directory(path: &path::Path, context: &mut JoshutoContext) -> std::io::Result<()> { cd(path, context)?; - let sort_options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); context .tab_context_mut() .curr_tab_mut() .history_mut() - .populate_to_root(&path, &sort_options)?; + .populate_to_root(&path, &options)?; Ok(()) } diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 1a7f1ea..ef0401e 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -24,12 +24,12 @@ pub fn cursor_move(new_index: usize, context: &mut JoshutoContext) -> JoshutoRes // get preview if let Some(path) = path { if path.is_dir() { - let sort_options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); context .tab_context_mut() .curr_tab_mut() .history_mut() - .create_or_soft_update(path.as_path(), &sort_options)?; + .create_or_soft_update(path.as_path(), &options)?; } } Ok(()) diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index 443875e..7a20886 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -111,7 +111,7 @@ pub fn delete_selected_files( ) -> std::io::Result<()> { delete_files(context, backend)?; - let options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); for tab in context.tab_context_mut().iter_mut() { tab.history_mut().reload(&curr_path, &options)?; diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs index 6b17817..fcd44ac 100644 --- a/src/commands/new_directory.rs +++ b/src/commands/new_directory.rs @@ -7,7 +7,7 @@ use crate::util::load_child::LoadChild; pub fn new_directory(context: &mut JoshutoContext, p: &path::Path) -> JoshutoResult<()> { std::fs::create_dir_all(p)?; - let options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); for tab in context.tab_context_mut().iter_mut() { tab.history_mut().reload(&curr_path, &options)?; diff --git a/src/commands/parent_cursor_move.rs b/src/commands/parent_cursor_move.rs index 9656ad8..afc65d9 100644 --- a/src/commands/parent_cursor_move.rs +++ b/src/commands/parent_cursor_move.rs @@ -30,12 +30,12 @@ pub fn parent_cursor_move(new_index: usize, context: &mut JoshutoContext) -> Jos // get preview if let Some(path) = path { if path.is_dir() { - let sort_options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); context .tab_context_mut() .curr_tab_mut() .history_mut() - .create_or_soft_update(path.as_path(), &sort_options)?; + .create_or_soft_update(path.as_path(), &options)?; } } Ok(()) diff --git a/src/commands/reload.rs b/src/commands/reload.rs index fbd17ec..84e94d8 100644 --- a/src/commands/reload.rs +++ b/src/commands/reload.rs @@ -3,21 +3,21 @@ use crate::error::JoshutoResult; use crate::util::load_child::LoadChild; pub fn soft_reload(index: usize, context: &mut JoshutoContext) -> std::io::Result<()> { - let sort_option = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); if let Some(curr_tab) = context.tab_context_mut().tab_mut(index) { if let Some(curr_list) = curr_tab.curr_list_mut() { if curr_list.need_update() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } } if let Some(curr_list) = curr_tab.parent_list_mut() { if curr_list.need_update() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } } if let Some(curr_list) = curr_tab.child_list_mut() { if curr_list.need_update() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } } } @@ -25,16 +25,16 @@ pub fn soft_reload(index: usize, context: &mut JoshutoContext) -> std::io::Resul } pub fn reload(context: &mut JoshutoContext, index: usize) -> std::io::Result<()> { - let sort_option = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); if let Some(curr_tab) = context.tab_context_mut().tab_mut(index) { if let Some(curr_list) = curr_tab.curr_list_mut() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } if let Some(curr_list) = curr_tab.parent_list_mut() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } if let Some(curr_list) = curr_tab.child_list_mut() { - curr_list.reload_contents(&sort_option)?; + curr_list.reload_contents(&options)?; } } Ok(()) diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index 790068b..b67afef 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -18,7 +18,7 @@ pub fn _rename_file( return Err(err); } std::fs::rename(&src, &dest)?; - let options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); if let Some(curr_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() { curr_list.reload_contents(&options)?; } diff --git a/src/commands/search.rs b/src/commands/search.rs index 8bade96..ba18779 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -1,8 +1,7 @@ -use globset::{GlobBuilder, GlobMatcher}; +use globset::GlobMatcher; use crate::context::JoshutoContext; -use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::tab::JoshutoTab; +use crate::error::JoshutoResult; use super::cursor_move; use super::search_glob; @@ -35,7 +34,7 @@ pub fn search_prev(context: &mut JoshutoContext) -> JoshutoResult<()> { if let Some(s) = context.get_search_state() { let index = match s { SearchPattern::Glob(s) => { - search_glob::search_glob_fwd(context.tab_context_ref().curr_tab_ref(), s) + search_glob::search_glob_rev(context.tab_context_ref().curr_tab_ref(), s) } SearchPattern::String(s) => { search_string::search_string_rev(context.tab_context_ref().curr_tab_ref(), s) diff --git a/src/commands/show_hidden.rs b/src/commands/show_hidden.rs index f2c9c02..937c708 100644 --- a/src/commands/show_hidden.rs +++ b/src/commands/show_hidden.rs @@ -5,8 +5,8 @@ use crate::history::DirectoryHistory; use super::reload; pub fn _toggle_hidden(context: &mut JoshutoContext) { - let opposite = !context.config_ref().sort_option.show_hidden; - context.config_mut().sort_option.show_hidden = opposite; + let opposite = !context.display_options_ref().show_hidden(); + context.display_options_mut().set_show_hidden(opposite); for tab in context.tab_context_mut().iter_mut() { tab.history_mut().depreciate_all_entries(); diff --git a/src/commands/sort.rs b/src/commands/sort.rs index dff0fd3..ab255f3 100644 --- a/src/commands/sort.rs +++ b/src/commands/sort.rs @@ -8,17 +8,19 @@ use crate::util::sort::SortType; use super::reload; pub fn set_sort(context: &mut JoshutoContext, method: SortType) -> JoshutoResult<()> { - context.config_mut().sort_option.sort_method = method; + context.sort_options_mut().sort_method = method; + for tab in context.tab_context_mut().iter_mut() { tab.history_mut().depreciate_all_entries(); } + reload::soft_reload(context.tab_context_ref().get_index(), context)?; LoadChild::load_child(context)?; Ok(()) } pub fn toggle_reverse(context: &mut JoshutoContext) -> JoshutoResult<()> { - context.config_mut().sort_option.reverse = !context.config_ref().sort_option.reverse; + context.sort_options_mut().reverse = !context.sort_options_ref().reverse; for tab in context.tab_context_mut().iter_mut() { tab.history_mut().depreciate_all_entries(); } diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs index a1815a4..2683a07 100644 --- a/src/commands/tab_ops.rs +++ b/src/commands/tab_ops.rs @@ -15,7 +15,7 @@ fn _tab_switch(new_index: usize, context: &mut JoshutoContext) -> std::io::Resul let path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); std::env::set_current_dir(path.as_path())?; - let options = context.config_ref().sort_option.clone(); + let options = context.display_options_ref().clone(); context .tab_context_mut() .curr_tab_mut() @@ -39,7 +39,7 @@ pub fn new_tab(context: &mut JoshutoContext) -> JoshutoResult<()> { None => path::PathBuf::from("/"), }; - let tab = JoshutoTab::new(curr_path, &context.config_ref().sort_option)?; + let tab = JoshutoTab::new(curr_path, context.display_options_ref())?; context.tab_context_mut().push_tab(tab); let new_index = context.tab_context_ref().len() - 1; context.tab_context_mut().set_index(new_index); diff --git a/src/config/config.rs b/src/config/config.rs deleted file mode 100644 index e7b2e87..0000000 --- a/src/config/config.rs +++ /dev/null @@ -1,188 +0,0 @@ -use serde_derive::Deserialize; - -use tui::layout::Constraint; - -use super::{parse_to_config_file, ConfigStructure, Flattenable}; -use crate::util::sort; - -use crate::CONFIG_FILE; - -const fn default_true() -> bool { - true -} -const fn default_scroll_offset() -> usize { - 6 -} -const fn default_max_preview_size() -> u64 { - 2 * 1024 * 1024 // 2 MB -} -const fn default_column_ratio() -> (usize, usize, usize) { - (1, 3, 4) -} - -#[derive(Clone, Debug, Deserialize)] -struct SortRawOption { - #[serde(default)] - show_icons: bool, - #[serde(default)] - show_hidden: bool, - #[serde(default = "default_true")] - directories_first: bool, - #[serde(default)] - case_sensitive: bool, - #[serde(default)] - reverse: bool, -} - -impl SortRawOption { - pub fn into_sort_option(self, sort_method: sort::SortType) -> sort::SortOption { - sort::SortOption { - show_icons: self.show_icons, - show_hidden: self.show_hidden, - directories_first: self.directories_first, - case_sensitive: self.case_sensitive, - reverse: self.reverse, - sort_method, - } - } -} - -impl std::default::Default for SortRawOption { - fn default() -> Self { - Self { - show_icons: bool::default(), - show_hidden: bool::default(), - directories_first: default_true(), - case_sensitive: bool::default(), - reverse: bool::default(), - } - } -} - -#[derive(Clone, Debug, Deserialize)] -pub struct JoshutoRawConfig { - #[serde(default = "default_true")] - collapse_preview: bool, - #[serde(default = "default_scroll_offset")] - scroll_offset: usize, - #[serde(default = "default_true")] - show_borders: bool, - #[serde(default = "default_true")] - show_preview: bool, - #[serde(default = "default_true")] - tilde_in_titlebar: bool, - #[serde(default = "default_true")] - use_trash: bool, - #[serde(default)] - xdg_open: bool, - #[serde(default = "default_max_preview_size")] - max_preview_size: u64, - column_ratio: Option<[usize; 3]>, - sort_method: Option<String>, - #[serde(default)] - sort_option: SortRawOption, -} - -impl Flattenable<JoshutoConfig> for JoshutoRawConfig { - fn flatten(self) -> JoshutoConfig { - let column_ratio = match self.column_ratio { - Some(s) => (s[0], s[1], s[2]), - _ => default_column_ratio(), - }; - - let sort_method = match self.sort_method { - Some(s) => match sort::SortType::parse(s.as_str()) { - Some(s) => s, - None => sort::SortType::Natural, - }, - None => sort::SortType::Natural, - }; - let sort_option = self.sort_option.into_sort_option(sort_method); - - let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32; - - let default_layout = [ - Constraint::Ratio(column_ratio.0 as u32, total), - Constraint::Ratio(column_ratio.1 as u32, total), - Constraint::Ratio(column_ratio.2 as u32, total), - ]; - let no_preview_layout = [ - Constraint::Ratio(column_ratio.0 as u32, total), - Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total), - Constraint::Ratio(0, total), - ]; - - JoshutoConfig { - collapse_preview: self.collapse_preview, - max_preview_size: self.max_preview_size, - scroll_offset: self.scroll_offset, - show_borders: self.show_borders, - show_preview: self.show_preview, - tilde_in_titlebar: self.tilde_in_titlebar, - use_trash: self.use_trash, - xdg_open: self.xdg_open, - column_ratio, - sort_option, - default_layout, - no_preview_layout, - } - } -} - -#[derive(Debug, Clone)] -pub struct JoshutoConfig { - pub collapse_preview: bool, - pub max_preview_size: u64, - pub show_preview: bool, - pub show_borders: bool, - pub scroll_offset: usize, - pub tilde_in_titlebar: bool, - pub use_trash: bool, - pub xdg_open: bool, - pub sort_option: sort::SortOption, - pub column_ratio: (usize, usize, usize), - pub default_layout: [Constraint; 3], - pub no_preview_layout: [Constraint; 3], -} - -impl ConfigStructure for JoshutoConfig { - fn get_config() -> Self { - parse_to_config_file::<JoshutoRawConfig, JoshutoConfig>(CONFIG_FILE) - .unwrap_or_else(Self::default) - } -} - -impl std::default::Default for JoshutoConfig { - fn default() -> Self { - let sort_option = sort::SortOption::default(); - - let column_ratio = default_column_ratio(); - - let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32; - let default_layout = [ - Constraint::Ratio(column_ratio.0 as u32, total), - Constraint::Ratio(column_ratio.1 as u32, total), - Constraint::Ratio(column_ratio.2 as u32, total), - ]; - let no_preview_layout = [ - Constraint::Ratio(column_ratio.0 as u32, total), - Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total), - Constraint::Ratio(0, total), - ]; - - Self { - collapse_preview: true, - max_preview_size: default_max_preview_size(), - show_preview: true, - show_borders: false, - scroll_offset: default_scroll_offset(), - tilde_in_titlebar: true, - use_trash: true, - xdg_open: false, - sort_option, - column_ratio, - default_layout, - no_preview_layout, - } - } -} diff --git a/src/config/default/default.rs b/src/config/default/default.rs new file mode 100644 index 0000000..ce43a12 --- /dev/null +++ b/src/config/default/default.rs @@ -0,0 +1,88 @@ +use serde_derive::Deserialize; + +use super::DisplayRawOption; +use crate::config::{parse_to_config_file, ConfigStructure, Flattenable}; +use crate::util::display::DisplayOption; +use crate::util::sort; + +use crate::CONFIG_FILE; + +const fn default_true() -> bool { + true +} +const fn default_scroll_offset() -> usize { + 6 +} +const fn default_max_preview_size() -> u64 { + 2 * 1024 * 1024 // 2 MB +} + +#[derive(Clone, Debug, Deserialize)] +pub struct JoshutoRawConfig { + #[serde(default = "default_scroll_offset")] + scroll_offset: usize, + #[serde(default = "default_true")] + use_trash: bool, + #[serde(default)] + xdg_open: bool, + #[serde(default = "default_max_preview_size")] + max_preview_size: u64, + #[serde(default, rename = "display")] + display_options: DisplayRawOption, +} + +impl Flattenable<JoshutoConfig> for JoshutoRawConfig { + fn flatten(self) -> JoshutoConfig { + JoshutoConfig { + max_preview_size: self.max_preview_size, + scroll_offset: self.scroll_offset, + use_trash: self.use_trash, + xdg_open: self.xdg_open, + _display_options: self.display_options.into(), + } + } +} + +#[derive(Debug, Clone)] +pub struct JoshutoConfig { + pub max_preview_size: u64, + pub scroll_offset: usize, + pub use_trash: bool, + pub xdg_open: bool, + _display_options: DisplayOption, +} + +impl JoshutoConfig { + pub fn display_options_ref(&self) -> &DisplayOption { + &self._display_options + } + pub fn display_options_mut(&mut self) -> &mut DisplayOption { + &mut self._display_options + } + + pub fn sort_options_ref(&self) -> &sort::SortOption { + self.display_options_ref().sort_options_ref() + } + pub fn sort_options_mut(&mut self) -> &mut sort::SortOption { + self.display_options_mut().sort_options_mut() + } +} + +impl ConfigStructure for JoshutoConfig { + fn get_config() -> Self { + parse_to_config_file::<JoshutoRawConfig, JoshutoConfig>(CONFIG_FILE) + .unwrap_or_else(Self::default) + } +} + +impl std::default::Default for JoshutoConfig { + fn default() -> Self { + Self { + max_preview_size: default_max_preview_size(), + scroll_offset: default_scroll_offset(), + use_trash: true, + xdg_open: false, + _display_options: DisplayOption::default(), + } + } +} diff --git a/src/config/default/display.rs b/src/config/default/display.rs new file mode 100644 index 0000000..fb78147 --- /dev/null +++ b/src/config/default/display.rs @@ -0,0 +1,87 @@ +use serde_derive::Deserialize; + +use tui::layout::Constraint; + +use super::SortRawOption; +use crate::util::display::{default_column_ratio, DisplayOption}; + +const fn default_true() -> bool { + true +} + +#[derive(Clone, Debug, Deserialize)] +pub struct DisplayRawOption { + #[serde(default = "default_true")] + collapse_preview: bool, + + #[serde(default)] + column_ratio: Option<[usize; 3]>, + + #[serde(default = "default_true")] + show_borders: bool, + + #[serde(default)] + show_hidden: bool, + + #[serde(default)] + show_icons: bool, + + #[serde(default = "default_true")] + show_preview: bool, + + #[serde(default = "default_true")] + tilde_in_titlebar: bool, + + #[serde(default, rename = "sort")] + sort_options: SortRawOption, +} + +impl DisplayRawOption { + pub fn into(self) -> DisplayOption { + let column_ratio = match self.column_ratio { + Some(s) => (s[0], s[1], s[2]), + _ => default_column_ratio(), + }; + + let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32; + + let default_layout = [ + Constraint::Ratio(column_ratio.0 as u32, total), + Constraint::Ratio(column_ratio.1 as u32, total), + Constraint::Ratio(column_ratio.2 as u32, total), + ]; + let no_preview_layout = [ + Constraint::Ratio(column_ratio.0 as u32, total), + Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total), + Constraint::Ratio(0, total), + ]; + + DisplayOption { + _collapse_preview: self.collapse_preview, + column_ratio, + _show_borders: self.show_borders, + _show_hidden: self.show_hidden, + _show_icons: self.show_icons, + _show_preview: self.show_preview, + _sort_options: self.sort_options.into(), + _tilde_in_titlebar: self.tilde_in_titlebar, + default_layout, + no_preview_layout, + } + } +} + +impl std::default::Default for DisplayRawOption { + fn default() -> Self { + Self { + collapse_preview: default_true(), + column_ratio: None, + show_borders: true, + show_hidden: false, + show_icons: false, + show_preview: true, + sort_options: SortRawOption::default(), + tilde_in_titlebar: true, + } + } +} diff --git a/src/config/default/mod.rs b/src/config/default/mod.rs |