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/key_command | |
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/key_command')
-rw-r--r-- | src/key_command/command.rs | 4 | ||||
-rw-r--r-- | src/key_command/constants.rs | 1 | ||||
-rw-r--r-- | src/key_command/impl_appcommand.rs | 1 | ||||
-rw-r--r-- | src/key_command/impl_appexecute.rs | 1 | ||||
-rw-r--r-- | src/key_command/impl_comment.rs | 7 | ||||
-rw-r--r-- | src/key_command/impl_from_str.rs | 4 |
6 files changed, 15 insertions, 3 deletions
diff --git a/src/key_command/command.rs b/src/key_command/command.rs index bc8fe6d..5da7e27 100644 --- a/src/key_command/command.rs +++ b/src/key_command/command.rs @@ -1,7 +1,7 @@ use std::path; use crate::commands::quit::QuitAction; -use crate::config::option::{LineNumberStyle, SelectOption, SortType}; +use crate::config::option::{LineMode, LineNumberStyle, SelectOption, SortType}; use crate::io::FileOperationOptions; #[derive(Clone, Debug)] @@ -53,6 +53,8 @@ pub enum Command { CursorMovePageMiddle, CursorMovePageEnd, + SetLineMode(LineMode), + ParentCursorMoveUp { offset: usize, }, diff --git a/src/key_command/constants.rs b/src/key_command/constants.rs index c3bddc9..de25d3a 100644 --- a/src/key_command/constants.rs +++ b/src/key_command/constants.rs @@ -71,6 +71,7 @@ cmd_constants![ (CMD_TOGGLE_HIDDEN, "toggle_hidden"), (CMD_TOGGLE_VISUAL, "toggle_visual"), (CMD_SWITCH_LINE_NUMBERS, "line_nums"), + (CMD_SET_LINEMODE, "linemode"), (CMD_TOUCH_FILE, "touch"), (CMD_HELP, "help"), (CMD_SEARCH_FZF, "search_fzf"), diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs index bc509af..6f5c067 100644 --- a/src/key_command/impl_appcommand.rs +++ b/src/key_command/impl_appcommand.rs @@ -79,6 +79,7 @@ impl AppCommand for Command { Self::SubProcess { spawn: false, .. } => CMD_SUBPROCESS_FOREGROUND, Self::SubProcess { spawn: true, .. } => CMD_SUBPROCESS_BACKGROUND, Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS, + Self::SetLineMode(_) => CMD_SET_LINEMODE, Self::TabSwitch { .. } => CMD_TAB_SWITCH, Self::TabSwitchIndex { .. } => CMD_TAB_SWITCH_INDEX, diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs index f72aca3..693ef0c 100644 --- a/src/key_command/impl_appexecute.rs +++ b/src/key_command/impl_appexecute.rs @@ -111,6 +111,7 @@ impl AppExecute for Command { Self::SetMode => set_mode::set_mode(context, backend), Self::ShowTasks => show_tasks::show_tasks(context, backend, keymap_t), Self::Sort(t) => sort::set_sort(context, *t), + Self::SetLineMode(mode) => linemode::set_linemode(context, *mode), Self::SortReverse => sort::toggle_reverse(context), Self::SubProcess { words, spawn } => { sub_process::sub_process(context, backend, words.as_slice(), *spawn) diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs index b74da7a..5fb969f 100644 --- a/src/key_command/impl_comment.rs +++ b/src/key_command/impl_comment.rs @@ -1,4 +1,4 @@ -use crate::config::option::SortType; +use crate::config::option::{LineMode, SortType}; use crate::io::FileOperationOptions; use super::{Command, CommandComment}; @@ -7,6 +7,11 @@ impl CommandComment for Command { // These comments are displayed at the help page fn comment(&self) -> &'static str { match self { + Self::SetLineMode(linemode) => match linemode { + LineMode::Size => "Show files with size", + LineMode::MTime => "Show files with modified time", + LineMode::SizeMTime => "Show files with size and modified time", + }, Self::Escape => "Escape from visual mode (cancel)", Self::BulkRename => "Bulk rename", diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs index 5802573..f7fe4e9 100644 --- a/src/key_command/impl_from_str.rs +++ b/src/key_command/impl_from_str.rs @@ -4,7 +4,7 @@ use dirs_next::home_dir; use shellexpand::tilde_with_context; use crate::commands::quit::QuitAction; -use crate::config::option::{LineNumberStyle, SelectOption, SortType}; +use crate::config::option::{LineMode, LineNumberStyle, SelectOption, SortType}; use crate::error::{JoshutoError, JoshutoErrorKind}; use crate::io::FileOperationOptions; @@ -334,6 +334,8 @@ impl std::str::FromStr for Command { )), }, } + } else if command == CMD_SET_LINEMODE { + Ok(Self::SetLineMode(LineMode::from_string(arg)?)) } else if command == CMD_TAB_SWITCH { match arg.parse::<i32>() { Ok(s) => Ok(Self::TabSwitch { offset: s }), |