diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2024-03-15 18:50:19 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2024-03-15 18:50:19 -0400 |
commit | 0dd87e2ec4385adb97a33e2b595fa8d674f46ae5 (patch) | |
tree | 4587c3d9f75881f97b166cc7a17241fdf7f4c08f /src/key_command | |
parent | cbb062d15b5d2a03f2872063f0af0c560d47db0b (diff) | |
parent | 2536838ce31955ec55561aabb4b86fdd4bc984df (diff) |
Merge branch 'main' of github.com:kamiyaa/joshuto
Diffstat (limited to 'src/key_command')
-rw-r--r-- | src/key_command/command.rs | 5 | ||||
-rw-r--r-- | src/key_command/impl_appcommand.rs | 2 | ||||
-rw-r--r-- | src/key_command/impl_appexecute.rs | 2 | ||||
-rw-r--r-- | src/key_command/impl_comment.rs | 2 | ||||
-rw-r--r-- | src/key_command/impl_display.rs | 12 | ||||
-rw-r--r-- | src/key_command/impl_from_str.rs | 28 |
6 files changed, 39 insertions, 12 deletions
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)?)) |