diff options
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/general/display_raw.rs | 8 | ||||
-rw-r--r-- | src/config/option/display_option.rs | 11 | ||||
-rw-r--r-- | src/config/option/linemodes.rs | 22 | ||||
-rw-r--r-- | src/config/option/mod.rs | 2 |
4 files changed, 37 insertions, 6 deletions
diff --git a/src/config/general/display_raw.rs b/src/config/general/display_raw.rs index c594e5c..84836f6 100644 --- a/src/config/general/display_raw.rs +++ b/src/config/general/display_raw.rs @@ -3,7 +3,9 @@ use std::convert::From; use serde_derive::Deserialize; use tui::layout::Constraint; -use crate::config::option::{DisplayMode, DisplayOption, LineNumberStyle, TabDisplayOption}; +use crate::config::option::{ + DisplayMode, DisplayOption, LineMode, LineNumberStyle, TabDisplayOption, +}; use super::sort_raw::SortOptionRaw; @@ -124,8 +126,10 @@ impl From<DisplayOptionRaw> for DisplayOption { default_layout, no_preview_layout, default_tab_display_option: TabDisplayOption { - _sort_options: raw.sort_options.into(), filter_string: "".to_owned(), + sort_options: raw.sort_options.into(), + // todo: make default line mode configurable + linemode: LineMode::Size, }, } } diff --git a/src/config/option/display_option.rs b/src/config/option/display_option.rs index a076db8..e213236 100644 --- a/src/config/option/display_option.rs +++ b/src/config/option/display_option.rs @@ -2,6 +2,7 @@ use std::fs; use tui::layout::Constraint; +use crate::config::option::LineMode; use crate::config::option::SortOption; #[derive(Clone, Copy, Debug)] @@ -35,8 +36,9 @@ pub struct DisplayOption { /// Display options valid per JoshutoTab #[derive(Clone, Debug)] pub struct TabDisplayOption { - pub _sort_options: SortOption, pub filter_string: String, + pub sort_options: SortOption, + pub linemode: LineMode, } #[derive(Clone, Copy, Debug)] @@ -48,11 +50,11 @@ pub enum LineNumberStyle { impl TabDisplayOption { pub fn sort_options_ref(&self) -> &SortOption { - &self._sort_options + &self.sort_options } pub fn sort_options_mut(&mut self) -> &mut SortOption { - &mut self._sort_options + &mut self.sort_options } pub fn set_filter_string(&mut self, pattern: &str) { @@ -146,8 +148,9 @@ impl std::default::Default for DisplayOption { default_layout, no_preview_layout, default_tab_display_option: TabDisplayOption { - _sort_options: SortOption::default(), filter_string: "".to_owned(), + sort_options: SortOption::default(), + linemode: LineMode::Size, }, } } diff --git a/src/config/option/linemodes.rs b/src/config/option/linemodes.rs new file mode 100644 index 0000000..405bb6b --- /dev/null +++ b/src/config/option/linemodes.rs @@ -0,0 +1,22 @@ +use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; + +#[derive(Clone, Debug, Copy)] +pub enum LineMode { + Size, + MTime, + SizeMTime, +} + +impl LineMode { + pub fn from_string(name: &str) -> JoshutoResult<LineMode> { + match name { + "size" => Ok(LineMode::Size), + "mtime" => Ok(LineMode::MTime), + "sizemtime" => Ok(LineMode::SizeMTime), + _ => Err(JoshutoError::new( + JoshutoErrorKind::InvalidParameters, + format!("Linemode '{}' unknown.", name), + )), + } + } +} diff --git a/src/config/option/mod.rs b/src/config/option/mod.rs index a81bd06..cf90f1b 100644 --- a/src/config/option/mod.rs +++ b/src/config/option/mod.rs @@ -1,4 +1,5 @@ pub mod display_option; +pub mod linemodes; pub mod preview_option; pub mod select_option; pub mod sort_option; @@ -6,6 +7,7 @@ pub mod sort_type; pub mod tab_option; pub use self::display_option::*; +pub use self::linemodes::*; pub use self::preview_option::*; pub use self::select_option::*; pub use self::sort_option::*; |