summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2024-03-15 18:50:19 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2024-03-15 18:50:19 -0400
commit0dd87e2ec4385adb97a33e2b595fa8d674f46ae5 (patch)
tree4587c3d9f75881f97b166cc7a17241fdf7f4c08f
parentcbb062d15b5d2a03f2872063f0af0c560d47db0b (diff)
parent2536838ce31955ec55561aabb4b86fdd4bc984df (diff)
Merge branch 'main' of github.com:kamiyaa/joshuto
-rw-r--r--docs/configuration/keymap.toml.md6
-rw-r--r--src/commands/sort.rs7
-rw-r--r--src/key_command/command.rs5
-rw-r--r--src/key_command/impl_appcommand.rs2
-rw-r--r--src/key_command/impl_appexecute.rs2
-rw-r--r--src/key_command/impl_comment.rs2
-rw-r--r--src/key_command/impl_display.rs12
-rw-r--r--src/key_command/impl_from_str.rs28
8 files changed, 51 insertions, 13 deletions
diff --git a/docs/configuration/keymap.toml.md b/docs/configuration/keymap.toml.md
index d44660f..81069a1 100644
--- a/docs/configuration/keymap.toml.md
+++ b/docs/configuration/keymap.toml.md
@@ -152,8 +152,14 @@ function joshuto() {
- `sort lexical`: sort lexically (`10.txt` comes before `2.txt`)
- `sort natural`: sort naturally (`2.txt` comes before `10.txt`)
- `sort mtime`: sort via last modified time
+- `sort size`: sort by file size
+- `sort ext`: sort by extension
- `sort reverse`: reverse the sorting
+All methods (except `reverse`) support the `--reverse` flag:
+- `--reverse=true` applies sort method and sets reverse to `true`
+- `--reverse=false` applies sort method and sets reverse to `false`
+
### `linemode`: change the line-mode (textual representation of files and directories in the “current view”)
- `linemode size`: show the entry’s size (bytes for files, number of entries for directories) (default) <sup>✻</sup>
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
index 7bea48f..fa597c1 100644
--- a/src/commands/sort.rs
+++ b/src/commands/sort.rs
@@ -5,13 +5,18 @@ use crate::history::DirectoryHistory;
use super::reload;
-pub fn set_sort(context: &mut AppContext, method: SortType) -> AppResult {
+pub fn set_sort(context: &mut AppContext, method: SortType, reverse: Option<bool>) -> AppResult {
let curr_tab = context.tab_context_mut().curr_tab_mut();
curr_tab
.option_mut()
.sort_options_mut()
.set_sort_method(method);
curr_tab.history_mut().depreciate_all_entries();
+
+ if let Some(r) = reverse {
+ curr_tab.option_mut().sort_options_mut().reverse = r;
+ }
+
refresh(context)
}
diff --git a/src/key_command/command.rs b/src/key_command/command.rs
index 0a4736f..c0c575d 100644
--- a/src/key_command/command.rs
+++ b/src/key_command/command.rs
@@ -153,7 +153,10 @@ pub enum Command {
initial: char,
},
- Sort(SortType),
+ Sort {
+ sort_type: SortType,
+ reverse: Option<bool>,
+ },
SortReverse,
FilterGlob {
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index e261391..df9ffcf 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -79,7 +79,7 @@ impl AppCommand for Command {
Self::Flat { .. } => CMD_FLAT,
Self::NumberedCommand { .. } => CMD_NUMBERED_COMMAND,
- Self::Sort(_) => CMD_SORT,
+ Self::Sort { .. } => CMD_SORT,
Self::SortReverse => CMD_SORT_REVERSE,
Self::FilterGlob { .. } => CMD_FILTER_GLOB,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 10ab5e9..3540cd1 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -135,7 +135,7 @@ impl AppExecute for Command {
} => case_sensitivity::set_case_sensitivity(context, *case_sensitivity, *set_type),
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::Sort { sort_type, reverse } => sort::set_sort(context, *sort_type, *reverse),
Self::SetLineMode(mode) => linemode::set_linemode(context, *mode),
Self::SortReverse => sort::toggle_reverse(context),
Self::SubProcess { words, mode } => {
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index bcfd3c9..6fa744d 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -119,7 +119,7 @@ impl CommandComment for Command {
Self::Flat { .. } => "Flattern directory list",
Self::NumberedCommand { .. } => "Jump via input number",
- Self::Sort(sort_type) => match sort_type {
+ Self::Sort { sort_type, .. } => match sort_type {
SortType::Lexical => "Sort lexically",
SortType::Mtime => "Sort by modification time",
SortType::Natural => "Sort naturally",
diff --git a/src/key_command/impl_display.rs b/src/key_command/impl_display.rs
index 50252ed..b219a9a 100644
--- a/src/key_command/impl_display.rs
+++ b/src/key_command/impl_display.rs
@@ -49,7 +49,17 @@ impl std::fmt::Display for Command {
Self::SearchRegex { pattern } => write!(f, "{} {}", self.command(), pattern),
Self::SearchString { pattern } => write!(f, "{} {}", self.command(), pattern),
Self::SubProcess { words, .. } => write!(f, "{} {:?}", self.command(), words),
- Self::Sort(t) => write!(f, "{} {}", self.command(), t),
+ Self::Sort { sort_type, reverse } => write!(
+ f,
+ "{} {}{}",
+ self.command(),
+ sort_type,
+ match reverse {
+ Some(true) => " --reverse=true",
+ Some(false) => " --reverse=false",
+ None => "",
+ },
+ ),
Self::TabSwitch { offset } => write!(f, "{} {}", self.command(), offset),
Self::TabSwitchIndex { index } => write!(f, "{} {}", self.command(), index),
_ => write!(f, "{}", self.command()),
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index 79a7164..d63407d 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -510,13 +510,27 @@ impl std::str::FromStr for Command {
} else if command == CMD_SORT {
match arg {
"reverse" => Ok(Self::SortReverse),
- arg => match SortType::from_str(arg) {
- Some(s) => Ok(Self::Sort(s)),
- None => Err(AppError::new(
- AppErrorKind::InvalidParameters,
- format!("{}: Unknown option '{}'", command, arg),
- )),
- },
+ arg => {
+ let (sort, reverse) = match arg.split_once(' ') {
+ Some((s, "--reverse=true")) => (s, Some(true)),
+ Some((s, "--reverse=false")) => (s, Some(false)),
+ Some((_, opt)) => {
+ return Err(AppError::new(
+ AppErrorKind::InvalidParameters,
+ format!("{}: Unknown option '{}'", command, opt),
+ ))
+ }
+ None => (arg, None),
+ };
+
+ match SortType::from_str(sort) {
+ Some(sort_type) => Ok(Self::Sort { sort_type, reverse }),
+ None => Err(AppError::new(
+ AppErrorKind::InvalidParameters,
+ format!("{}: Unknown option '{}'", command, sort),
+ )),
+ }
+ }
}
} else if command == CMD_SET_LINEMODE {
Ok(Self::SetLineMode(LineMode::from_string(arg)?))