diff options
author | DLFW <daniel@llin.info> | 2022-10-20 17:17:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 11:17:02 -0400 |
commit | 7d89ec31a0028957bbbcb47cabc67d47523820dc (patch) | |
tree | ac9d1d3c770531d00caab2a6ccea612ce78ff01e /src/config | |
parent | e59ed84f5ac3ba864b6c0d2bcdb6a014d2d46e73 (diff) |
Add linemode feature and first simple linemodes (#206)
This adds the basic ability to change the representation of files in the
TUI detailed dir list by letting the user choose a certain "linemode".
As of now, there are only three simple linemodes, all showing the
filename on the left side and a preceding symlink indicator in the
beginning of the right label as usual.
The "size" linemode shows the right label as it has been up to now.
The "mtime" linemode shows the mtime of the file or directory.
The "sizemtime" linemodes combines both meta-data.
The user can change the linemode like so:
```
:linemode [size|mtime|sizemtime]
```
Default keybindings have been added:
``ms`` for *size*, ``mm`` for *mtime*, and ``mM`` for *sizemtime*.
The selected linemode is specific for each tab.
A new tab always starts with the *size* linemode.
Possible enhancements:
* Move the code for factoring a label out of the
``tui_dirlist_detailed`` module to some UI-independent module
* Add a configuration option for the default linemode for new tabs
* Add further simple linemodes
* Generic support for linemodes with only one “full line label”
* Add support for custom linemodes where a label is constructed by an
external script
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::*; |