Skip to content

Commit 0dd87e2

Browse files
committed
Merge branch 'main' of github.com:kamiyaa/joshuto
2 parents cbb062d + 2536838 commit 0dd87e2

8 files changed

Lines changed: 51 additions & 13 deletions

File tree

docs/configuration/keymap.toml.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ function joshuto() {
152152
- `sort lexical`: sort lexically (`10.txt` comes before `2.txt`)
153153
- `sort natural`: sort naturally (`2.txt` comes before `10.txt`)
154154
- `sort mtime`: sort via last modified time
155+
- `sort size`: sort by file size
156+
- `sort ext`: sort by extension
155157
- `sort reverse`: reverse the sorting
156158

159+
All methods (except `reverse`) support the `--reverse` flag:
160+
- `--reverse=true` applies sort method and sets reverse to `true`
161+
- `--reverse=false` applies sort method and sets reverse to `false`
162+
157163
### `linemode`: change the line-mode (textual representation of files and directories in the “current view”)
158164

159165
- `linemode size`: show the entry’s size (bytes for files, number of entries for directories) (default) <sup>✻</sup>

src/commands/sort.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ use crate::history::DirectoryHistory;
55

66
use super::reload;
77

8-
pub fn set_sort(context: &mut AppContext, method: SortType) -> AppResult {
8+
pub fn set_sort(context: &mut AppContext, method: SortType, reverse: Option<bool>) -> AppResult {
99
let curr_tab = context.tab_context_mut().curr_tab_mut();
1010
curr_tab
1111
.option_mut()
1212
.sort_options_mut()
1313
.set_sort_method(method);
1414
curr_tab.history_mut().depreciate_all_entries();
15+
16+
if let Some(r) = reverse {
17+
curr_tab.option_mut().sort_options_mut().reverse = r;
18+
}
19+
1520
refresh(context)
1621
}
1722

src/key_command/command.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ pub enum Command {
153153
initial: char,
154154
},
155155

156-
Sort(SortType),
156+
Sort {
157+
sort_type: SortType,
158+
reverse: Option<bool>,
159+
},
157160
SortReverse,
158161

159162
FilterGlob {

src/key_command/impl_appcommand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl AppCommand for Command {
7979
Self::Flat { .. } => CMD_FLAT,
8080
Self::NumberedCommand { .. } => CMD_NUMBERED_COMMAND,
8181

82-
Self::Sort(_) => CMD_SORT,
82+
Self::Sort { .. } => CMD_SORT,
8383
Self::SortReverse => CMD_SORT_REVERSE,
8484

8585
Self::FilterGlob { .. } => CMD_FILTER_GLOB,

src/key_command/impl_appexecute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl AppExecute for Command {
135135
} => case_sensitivity::set_case_sensitivity(context, *case_sensitivity, *set_type),
136136
Self::SetMode => set_mode::set_mode(context, backend),
137137
Self::ShowTasks => show_tasks::show_tasks(context, backend, keymap_t),
138-
Self::Sort(t) => sort::set_sort(context, *t),
138+
Self::Sort { sort_type, reverse } => sort::set_sort(context, *sort_type, *reverse),
139139
Self::SetLineMode(mode) => linemode::set_linemode(context, *mode),
140140
Self::SortReverse => sort::toggle_reverse(context),
141141
Self::SubProcess { words, mode } => {

src/key_command/impl_comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl CommandComment for Command {
119119
Self::Flat { .. } => "Flattern directory list",
120120
Self::NumberedCommand { .. } => "Jump via input number",
121121

122-
Self::Sort(sort_type) => match sort_type {
122+
Self::Sort { sort_type, .. } => match sort_type {
123123
SortType::Lexical => "Sort lexically",
124124
SortType::Mtime => "Sort by modification time",
125125
SortType::Natural => "Sort naturally",

src/key_command/impl_display.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ impl std::fmt::Display for Command {
4949
Self::SearchRegex { pattern } => write!(f, "{} {}", self.command(), pattern),
5050
Self::SearchString { pattern } => write!(f, "{} {}", self.command(), pattern),
5151
Self::SubProcess { words, .. } => write!(f, "{} {:?}", self.command(), words),
52-
Self::Sort(t) => write!(f, "{} {}", self.command(), t),
52+
Self::Sort { sort_type, reverse } => write!(
53+
f,
54+
"{} {}{}",
55+
self.command(),
56+
sort_type,
57+
match reverse {
58+
Some(true) => " --reverse=true",
59+
Some(false) => " --reverse=false",
60+
None => "",
61+
},
62+
),
5363
Self::TabSwitch { offset } => write!(f, "{} {}", self.command(), offset),
5464
Self::TabSwitchIndex { index } => write!(f, "{} {}", self.command(), index),
5565
_ => write!(f, "{}", self.command()),

src/key_command/impl_from_str.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,27 @@ impl std::str::FromStr for Command {
510510
} else if command == CMD_SORT {
511511
match arg {
512512
"reverse" => Ok(Self::SortReverse),
513-
arg => match SortType::from_str(arg) {
514-
Some(s) => Ok(Self::Sort(s)),
515-
None => Err(AppError::new(
516-
AppErrorKind::InvalidParameters,
517-
format!("{}: Unknown option '{}'", command, arg),
518-
)),
519-
},
513+
arg => {
514+
let (sort, reverse) = match arg.split_once(' ') {
515+
Some((s, "--reverse=true")) => (s, Some(true)),
516+
Some((s, "--reverse=false")) => (s, Some(false)),
517+
Some((_, opt)) => {
518+
return Err(AppError::new(
519+
AppErrorKind::InvalidParameters,
520+
format!("{}: Unknown option '{}'", command, opt),
521+
))
522+
}
523+
None => (arg, None),
524+
};
525+
526+
match SortType::from_str(sort) {
527+
Some(sort_type) => Ok(Self::Sort { sort_type, reverse }),
528+
None => Err(AppError::new(
529+
AppErrorKind::InvalidParameters,
530+
format!("{}: Unknown option '{}'", command, sort),
531+
)),
532+
}
533+
}
520534
}
521535
} else if command == CMD_SET_LINEMODE {
522536
Ok(Self::SetLineMode(LineMode::from_string(arg)?))

0 commit comments

Comments
 (0)