summaryrefslogtreecommitdiffstats
path: root/src/key_command
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-09-03 12:45:51 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2022-09-03 12:45:51 -0400
commite7755ad0be98540c777d86c67605386ff11522a3 (patch)
tree8b8c6c3b138fea8ded708f64e0a24073b0a1f7ce /src/key_command
parent596ced65ae6ae59f4e1ac2ed60246a4c5943a919 (diff)
add symlink relative
Diffstat (limited to 'src/key_command')
-rw-r--r--src/key_command/command.rs106
-rw-r--r--src/key_command/impl_appcommand.rs48
-rw-r--r--src/key_command/impl_appexecute.rs75
-rw-r--r--src/key_command/impl_comment.rs61
-rw-r--r--src/key_command/impl_display.rs37
-rw-r--r--src/key_command/impl_from_str.rs101
-rw-r--r--src/key_command/impl_interactive.rs2
-rw-r--r--src/key_command/impl_numbered.rs4
8 files changed, 273 insertions, 161 deletions
diff --git a/src/key_command/command.rs b/src/key_command/command.rs
index 30f153f..d345c48 100644
--- a/src/key_command/command.rs
+++ b/src/key_command/command.rs
@@ -11,11 +11,16 @@ pub enum Command {
ToggleVisualMode,
BulkRename,
- ChangeDirectory(path::PathBuf),
+ ChangeDirectory {
+ path: path::PathBuf,
+ },
ParentDirectory,
PreviousDirectory,
- CommandLine(String, String),
+ CommandLine {
+ prefix: String,
+ suffix: String,
+ },
CutFiles,
CopyFiles,
@@ -23,13 +28,23 @@ pub enum Command {
CopyFileNameWithoutExtension,
CopyFilePath,
CopyDirPath,
- SymlinkFiles,
- PasteFiles(FileOperationOptions),
-
- DeleteFiles { background: bool },
-
- CursorMoveUp(usize),
- CursorMoveDown(usize),
+ SymlinkFiles {
+ relative: bool,
+ },
+ PasteFiles {
+ options: FileOperationOptions,
+ },
+
+ DeleteFiles {
+ background: bool,
+ },
+
+ CursorMoveUp {
+ offset: usize,
+ },
+ CursorMoveDown {
+ offset: usize,
+ },
CursorMoveHome,
CursorMoveEnd,
CursorMovePageUp(f64),
@@ -38,50 +53,85 @@ pub enum Command {
CursorMovePageMiddle,
CursorMovePageEnd,
- ParentCursorMoveUp(usize),
- ParentCursorMoveDown(usize),
+ ParentCursorMoveUp {
+ offset: usize,
+ },
+ ParentCursorMoveDown {
+ offset: usize,
+ },
- PreviewCursorMoveUp(usize),
- PreviewCursorMoveDown(usize),
+ PreviewCursorMoveUp {
+ offset: usize,
+ },
+ PreviewCursorMoveDown {
+ offset: usize,
+ },
// ChildCursorMoveUp(usize),
// ChildCursorMoveDown(usize),
- NewDirectory(path::PathBuf),
+ NewDirectory {
+ path: path::PathBuf,
+ },
OpenFile,
- OpenFileWith(Option<usize>),
-
+ OpenFileWith {
+ index: Option<usize>,
+ },
Quit(QuitAction),
ReloadDirList,
- RenameFile(path::PathBuf),
+ RenameFile {
+ new_name: path::PathBuf,
+ },
RenameFileAppend,
RenameFilePrepend,
- TouchFile(String),
-
- SearchGlob(String),
- SearchString(String),
- SearchIncremental(String),
+ TouchFile {
+ file_name: String,
+ },
+
+ SearchGlob {
+ pattern: String,
+ },
+ SearchString {
+ pattern: String,
+ },
+ SearchIncremental {
+ pattern: String,
+ },
SearchNext,
SearchPrev,
- SelectFiles(String, SelectOption),
+ SelectFiles {
+ pattern: String,
+ options: SelectOption,
+ },
SetMode,
- SubProcess(Vec<String>, bool),
+ SubProcess {
+ words: Vec<String>,
+ spawn: bool,
+ },
ShowTasks,
ToggleHiddenFiles,
SwitchLineNums(LineNumberStyle),
- Flat(usize),
- NumberedCommand(char),
+ Flat {
+ depth: usize,
+ },
+ NumberedCommand {
+ initial: char,
+ },
Sort(SortType),
SortReverse,
NewTab,
CloseTab,
- TabSwitch(i32),
- TabSwitchIndex(u32),
+ TabSwitch {
+ offset: i32,
+ },
+ TabSwitchIndex {
+ index: usize,
+ },
Help,
SearchFzf,
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index 1990bbc..7156f43 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -13,13 +13,13 @@ impl AppCommand for Command {
Self::BulkRename => CMD_BULK_RENAME,
- Self::ChangeDirectory(_) => CMD_CHANGE_DIRECTORY,
+ Self::ChangeDirectory { .. } => CMD_CHANGE_DIRECTORY,
Self::ParentDirectory => CMD_PARENT_DIRECTORY,
Self::PreviousDirectory => CMD_PREVIOUS_DIRECTORY,
Self::NewTab => CMD_NEW_TAB,
Self::CloseTab => CMD_CLOSE_TAB,
- Self::CommandLine(_, _) => CMD_COMMAND_LINE,
+ Self::CommandLine { .. } => CMD_COMMAND_LINE,
Self::CutFiles => CMD_CUT_FILES,
Self::CopyFiles => CMD_COPY_FILES,
@@ -27,13 +27,13 @@ impl AppCommand for Command {
Self::CopyFileNameWithoutExtension => CMD_COPY_FILENAME_WITHOUT_EXTENSION,
Self::CopyFilePath => CMD_COPY_FILEPATH,
Self::CopyDirPath => CMD_COPY_DIRECTORY_PATH,
- Self::SymlinkFiles => CMD_SYMLINK_FILES,
- Self::PasteFiles(_) => CMD_PASTE_FILES,
+ Self::SymlinkFiles { .. } => CMD_SYMLINK_FILES,
+ Self::PasteFiles { .. } => CMD_PASTE_FILES,
Self::DeleteFiles { .. } => CMD_DELETE_FILES,
- Self::CursorMoveUp(_) => CMD_CURSOR_MOVE_UP,
- Self::CursorMoveDown(_) => CMD_CURSOR_MOVE_DOWN,
+ Self::CursorMoveUp { .. } => CMD_CURSOR_MOVE_UP,
+ Self::CursorMoveDown { .. } => CMD_CURSOR_MOVE_DOWN,
Self::CursorMoveHome => CMD_CURSOR_MOVE_HOME,
Self::CursorMoveEnd => CMD_CURSOR_MOVE_END,
Self::CursorMovePageUp(_) => CMD_CURSOR_MOVE_PAGEUP,
@@ -42,46 +42,46 @@ impl AppCommand for Command {
Self::CursorMovePageMiddle => CMD_CURSOR_MOVE_PAGEDOWN,
Self::CursorMovePageEnd => CMD_CURSOR_MOVE_PAGEDOWN,
- Self::ParentCursorMoveUp(_) => CMD_PARENT_CURSOR_MOVE_UP,
- Self::ParentCursorMoveDown(_) => CMD_PARENT_CURSOR_MOVE_DOWN,
+ Self::ParentCursorMoveUp { .. } => CMD_PARENT_CURSOR_MOVE_UP,
+ Self::ParentCursorMoveDown { .. } => CMD_PARENT_CURSOR_MOVE_DOWN,
- Self::PreviewCursorMoveUp(_) => CMD_PREVIEW_CURSOR_MOVE_UP,
- Self::PreviewCursorMoveDown(_) => CMD_PREVIEW_CURSOR_MOVE_DOWN,
+ Self::PreviewCursorMoveUp { .. } => CMD_PREVIEW_CURSOR_MOVE_UP,
+ Self::PreviewCursorMoveDown { .. } => CMD_PREVIEW_CURSOR_MOVE_DOWN,
- Self::NewDirectory(_) => CMD_NEW_DIRECTORY,
+ Self::NewDirectory { .. } => CMD_NEW_DIRECTORY,
Self::OpenFile => CMD_OPEN_FILE,
- Self::OpenFileWith(_) => CMD_OPEN_FILE_WITH,
+ Self::OpenFileWith { .. } => CMD_OPEN_FILE_WITH,
Self::ReloadDirList => CMD_RELOAD_DIRECTORY_LIST,
- Self::RenameFile(_) => CMD_RENAME_FILE,
+ Self::RenameFile { .. } => CMD_RENAME_FILE,
Self::RenameFileAppend => CMD_RENAME_FILE_APPEND,
Self::RenameFilePrepend => CMD_RENAME_FILE_PREPEND,
- Self::SearchString(_) => CMD_SEARCH_STRING,
- Self::SearchIncremental(_) => CMD_SEARCH_INCREMENTAL,
- Self::SearchGlob(_) => CMD_SEARCH_GLOB,
+ Self::SearchString { .. } => CMD_SEARCH_STRING,
+ Self::SearchIncremental { .. } => CMD_SEARCH_INCREMENTAL,
+ Self::SearchGlob { .. } => CMD_SEARCH_GLOB,
Self::SearchNext => CMD_SEARCH_NEXT,
Self::SearchPrev => CMD_SEARCH_PREV,
- Self::SelectFiles(_, _) => CMD_SELECT_FILES,
+ Self::SelectFiles { .. } => CMD_SELECT_FILES,
Self::SetMode => CMD_SET_MODE,
Self::ShowTasks => CMD_SHOW_TASKS,
- Self::Flat(_) => CMD_FLAT,
- Self::NumberedCommand(_) => CMD_NUMBERED_COMMAND,
+ Self::Flat { .. } => CMD_FLAT,
+ Self::NumberedCommand { .. } => CMD_NUMBERED_COMMAND,
Self::Sort(_) => CMD_SORT,
Self::SortReverse => CMD_SORT_REVERSE,
- Self::SubProcess(_, false) => CMD_SUBPROCESS_FOREGROUND,
- Self::SubProcess(_, true) => CMD_SUBPROCESS_BACKGROUND,
+ Self::SubProcess { spawn: false, .. } => CMD_SUBPROCESS_FOREGROUND,
+ Self::SubProcess { spawn: true, .. } => CMD_SUBPROCESS_BACKGROUND,
Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS,
- Self::TabSwitch(_) => CMD_TAB_SWITCH,
- Self::TabSwitchIndex(_) => CMD_TAB_SWITCH_INDEX,
+ Self::TabSwitch { .. } => CMD_TAB_SWITCH,
+ Self::TabSwitchIndex { .. } => CMD_TAB_SWITCH_INDEX,
Self::ToggleHiddenFiles => CMD_TOGGLE_HIDDEN,
- Self::TouchFile(_) => CMD_TOUCH_FILE,
+ Self::TouchFile { .. } => CMD_TOUCH_FILE,
Self::SearchFzf => CMD_SEARCH_FZF,
Self::SubdirFzf => CMD_SUBDIR_FZF,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 982825c..0dc9a9d 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -19,8 +19,8 @@ impl AppExecute for Command {
Self::BulkRename => bulk_rename::bulk_rename(context, backend),
- Self::ChangeDirectory(p) => {
- change_directory::change_directory(context, p.as_path())?;
+ Self::ChangeDirectory { path } => {
+ change_directory::change_directory(context, path.as_path())?;
Ok(())
}
Self::ParentDirectory => change_directory::parent_directory(context),
@@ -28,9 +28,13 @@ impl AppExecute for Command {
Self::NewTab => tab_ops::new_tab(context),
Self::CloseTab => tab_ops::close_tab(context),
- Self::CommandLine(p, s) => {
- command_line::read_and_execute(context, backend, keymap_t, p.as_str(), s.as_str())
- }
+ Self::CommandLine { prefix, suffix } => command_line::read_and_execute(
+ context,
+ backend,
+ keymap_t,
+ prefix.as_str(),
+ suffix.as_str(),
+ ),
Self::CutFiles => file_ops::cut(context),
Self::CopyFiles => file_ops::copy(context),
Self::CopyFileName => file_ops::copy_filename(context),
@@ -39,8 +43,9 @@ impl AppExecute for Command {
}
Self::CopyFilePath => file_ops::copy_filepath(context),
Self::CopyDirPath => file_ops::copy_dirpath(context),
- Self::SymlinkFiles => file_ops::link(context),
- Self::PasteFiles(options) => file_ops::paste(context, *options),
+ Self::SymlinkFiles { relative: true } => file_ops::symlink_relative(context),
+ Self::SymlinkFiles { relative: false } => file_ops::symlink_absolute(context),
+ Self::PasteFiles { options } => file_ops::paste(context, *options),
Self::DeleteFiles { background: false } => {
delete_files::delete_selected_files(context, backend)
@@ -49,8 +54,8 @@ impl AppExecute for Command {
delete_files::delete_selected_files_background(context, backend)
}
- Self::CursorMoveUp(u) => cursor_move::up(context, *u),
- Self::CursorMoveDown(u) => cursor_move::down(context, *u),
+ Self::CursorMoveUp { offset } => cursor_move::up(context, *offset),
+ Self::CursorMoveDown { offset } => cursor_move::down(context, *offset),
Self::CursorMoveHome => cursor_move::home(context),
Self::CursorMoveEnd => cursor_move::end(context),
Self::CursorMovePageUp(p) => cursor_move::page_up(context, backend, *p),
@@ -60,60 +65,70 @@ impl AppExecute for Command {
Self::CursorMovePageMiddle => cursor_move::page_middle(context, backend),
Self::CursorMovePageEnd => cursor_move::page_end(context, backend),
- Self::ParentCursorMoveUp(u) => parent_cursor_move::parent_up(context, *u),
- Self::ParentCursorMoveDown(u) => parent_cursor_move::parent_down(context, *u),
+ Self::ParentCursorMoveUp { offset } => parent_cursor_move::parent_up(context, *offset),
+ Self::ParentCursorMoveDown { offset } => {
+ parent_cursor_move::parent_down(context, *offset)
+ }
- Self::PreviewCursorMoveUp(u) => preview_cursor_move::preview_up(context, *u),
- Self::PreviewCursorMoveDown(u) => preview_cursor_move::preview_down(context, *u),
+ Self::PreviewCursorMoveUp { offset } => {
+ preview_cursor_move::preview_up(context, *offset)
+ }
+ Self::PreviewCursorMoveDown { offset } => {
+ preview_cursor_move::preview_down(context, *offset)
+ }
- Self::NewDirectory(p) => new_directory::new_directory(context, p.as_path()),
+ Self::NewDirectory { path } => new_directory::new_directory(context, path.as_path()),
Self::OpenFile => open_file::open(context, backend),
- Self::OpenFileWith(None) => open_file::open_with_interactive(context, backend),
- Self::OpenFileWith(Some(i)) => open_file::open_with_index(context, backend, *i),
+ Self::OpenFileWith { index: None } => {
+ open_file::open_with_interactive(context, backend)
+ }
+ Self::OpenFileWith { index: Some(i) } => {
+ open_file::open_with_index(context, backend, *i)
+ }
Self::Quit(action) => quit::quit_with_action(context, *action),
Self::ReloadDirList => reload::reload_dirlist(context),
- Self::RenameFile(p) => rename_file::rename_file(context, p.as_path()),
+ Self::RenameFile { new_name } => rename_file::rename_file(context, new_name.as_path()),
Self::RenameFileAppend => rename_file::rename_file_append(context, backend, keymap_t),
Self::RenameFilePrepend => rename_file::rename_file_prepend(context, backend, keymap_t),
- Self::TouchFile(arg) => touch_file::touch_file(context, arg.as_str()),
- Self::SearchGlob(pattern) => search_glob::search_glob(context, pattern.as_str()),
- Self::SearchString(pattern) => {
+ Self::TouchFile { file_name } => touch_file::touch_file(context, file_name),
+ Self::SearchGlob { pattern } => search_glob::search_glob(context, pattern.as_str()),
+ Self::SearchString { pattern } => {
search_string::search_string(context, pattern.as_str(), false);
Ok(())
}
// We call `interactive_execute` on each key press, so even before Enter is pressed the
// cursor will be one the selected word. And as `interactive_execute` for
// `SearchIncremental` always starts from index 0, this operation will be a no-op
- Self::SearchIncremental(_) => Ok(()),
+ Self::SearchIncremental { .. } => Ok(()),
Self::SearchNext => search::search_next(context),
Self::SearchPrev => search::search_prev(context),
- Self::SelectFiles(pattern, options) => {
+ Self::SelectFiles { pattern, options } => {
select::select_files(context, pattern.as_str(), options)
}
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::SortReverse => sort::toggle_reverse(context),
- Self::SubProcess(v, spawn) => {
- sub_process::sub_process(context, backend, v.as_slice(), *spawn)
+ Self::SubProcess { words, spawn } => {
+ sub_process::sub_process(context, backend, words.as_slice(), *spawn)
}
Self::SwitchLineNums(d) => line_nums::switch_line_numbering(context, *d),
- Self::Flat(depth) => flat::flatten(*depth, context),
- Self::NumberedCommand(c) => {
- numbered_command::numbered_command(*c, context, backend, keymap_t)
+ Self::Flat { depth } => flat::flatten(context, *depth),
+ Self::NumberedCommand { initial } => {
+ numbered_command::numbered_command(context, backend, keymap_t, *initial)
}
Self::ToggleHiddenFiles => show_hidden::toggle_hidden(context),
- Self::TabSwitch(i) => {
- tab_ops::tab_switch(*i, context)?;
+ Self::TabSwitch { offset } => {
+ tab_ops::tab_switch(context, *offset)?;
Ok(())
}
- Self::TabSwitchIndex(i) => tab_ops::tab_switch_index(*i as usize, context),
+ Self::TabSwitchIndex { index } => tab_ops::tab_switch_index(context, *index),
Self::Help => show_help::help_loop(context, backend, keymap_t),
Self::SearchFzf => search_fzf::search_fzf(context, backend),
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index 76e439b..616dfed 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -12,13 +12,13 @@ impl CommandComment for Command {
Self::ToggleVisualMode => "Toggle visual mode",
- Self::ChangeDirectory(_) => "Change directory",
+ Self::ChangeDirectory { .. } => "Change directory",
Self::ParentDirectory => "CD to parent directory",
Self::PreviousDirectory => "CD to the last dir in history",
Self::NewTab => "Open a new tab",
Self::CloseTab => "Close current tab",
- Self::CommandLine(command, _) => match command.trim() {
+ Self::CommandLine { prefix, .. } => match prefix.trim() {
"cd" => "Change directory",
"search" => "Open a search prompt",
"search_glob" => "Glob search",
@@ -34,21 +34,24 @@ impl CommandComment for Command {
Self::CopyFileNameWithoutExtension => "Copy filename without extension",
Self::CopyFilePath => "Copy path to file",
Self::CopyDirPath => "Copy directory name",
- Self::SymlinkFiles => "Symlink selected files",
-
- Self::PasteFiles(FileOperationOptions {
- overwrite,
- skip_exist,
- ..
- }) => match (overwrite, skip_exist) {
+ Self::SymlinkFiles { .. } => "Symlink selected files",
+
+ Self::PasteFiles {
+ options:
+ FileOperationOptions {
+ overwrite,
+ skip_exist,
+ ..
+ },
+ } => match (overwrite, skip_exist) {
(true, false) => "Paste, overwrite",
(false, true) => "Paste, skip existing files",
_ => "Paste",
},
Self::DeleteFiles { .. } => "Delete selected files",
- Self::CursorMoveUp(_) => "Move cursor up",
- Self::CursorMoveDown(_) => "Move cursor down",
+ Self::CursorMoveUp { .. } => "Move cursor up",
+ Self::CursorMoveDown { .. } => "Move cursor down",
Self::CursorMoveHome => "Move cursor to the very top",
Self::CursorMoveEnd => "Move cursor to the ver bottom",
Self::CursorMovePageUp(_) => "Move cursor one page up",
@@ -58,41 +61,41 @@ impl CommandComment for Command {
Self::CursorMovePageMiddle => "Move cursor to middle of page",
Self::CursorMovePageEnd => "Move cursor to bottom of page",
- Self::ParentCursorMoveUp(_) => "Cursor up in parent list",
- Self::ParentCursorMoveDown(_) => "Cursor down in parent list",
+ Self::ParentCursorMoveUp { .. } => "Cursor up in parent list",
+ Self::ParentCursorMoveDown { .. } => "Cursor down in parent list",
- Self::PreviewCursorMoveUp(_) => "Cursor up in file preview",
- Self::PreviewCursorMoveDown(_) => "Cursor down in file preview",
+ Self::PreviewCursorMoveUp { .. } => "Cursor up in file preview",
+ Self::PreviewCursorMoveDown { .. } => "Cursor down in file preview",
- Self::NewDirectory(_) => "Make a new directory",
+ Self::NewDirectory { .. } => "Make a new directory",
Self::OpenFile => "Open a file",
- Self::OpenFileWith(_) => "Open using selected program",
+ Self::OpenFileWith { .. } => "Open using selected program",
Self::Quit(_) => "Quit the program",
Self::ReloadDirList => "Reload current dir listing",
- Self::RenameFile(_) => "Rename file",
- Self::TouchFile(_) => "Touch file",
+ Self::RenameFile { .. } => "Rename file",
+ Self::TouchFile { .. } => "Touch file",
Self::RenameFileAppend => "Rename a file",
Self::RenameFilePrepend => "Rename a file",
- Self::SearchString(_) => "Search",
- Self::SearchIncremental(_) => "Search as you type",
- Self::SearchGlob(_) => "Search with globbing",
+ Self::SearchString { .. } => "Search",
+ Self::SearchIncremental { .. } => "Search as you type",
+ Self::SearchGlob { .. } => "Search with globbing",
Self::SearchNext => "Next search entry",
Self::SearchPrev => "Previous search entry",
- Self::SelectFiles(_, _) => "Select file",
+ Self::SelectFiles { .. } => "Select file",
Self::SetMode => "Set file permissions",
- Self::SubProcess(_, false) => "Run a shell command",
- Self::SubProcess(_, true) => "Run commmand in background",
+ Self::SubProcess { spawn: false, .. } => "Run a shell command",
+ Self::SubProcess { spawn: true, .. } => "Run commmand in background",
Self::ShowTasks => "Show running background tasks",
Self::ToggleHiddenFiles => "Toggle hidden files displaying",
Self::SwitchLineNums(_) => "Switch line numbering",
- Self::Flat(_) => "Flattern directory list",
- Self::NumberedCommand(_) => "Jump via input number",
+ Self::Flat { .. } => "Flattern directory list",
+ Self::NumberedCommand { .. } => "Jump via input number",
Self::Sort(sort_type) => match sort_type {
SortType::Lexical => "Sort lexically",
@@ -103,8 +106,8 @@ impl CommandComment for Command {
},
Self::SortReverse => "Reverse sort order",
- Self::TabSwitch(_) => "Swith to the next tab",
- Self::TabSwitchIndex(_) => "Swith to a given tab",
+ Self::TabSwitch { .. } => "Swith to the next tab",
+ Self::TabSwitchIndex { .. } => "Swith to a given tab",
Self::Help => "Open this help page",
Self::SearchFzf => "Search via fzf",
diff --git a/src/key_command/impl_display.rs b/src/key_command/impl_display.rs
index c414486..05b7206 100644
--- a/src/key_command/impl_display.rs
+++ b/src/key_command/impl_display.rs
@@ -3,29 +3,40 @@ use super::{AppCommand, Command};
impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
- Self::ChangeDirectory(p) => write!(f, "{} {:?}", self.command(), p),
- Self::CommandLine(s, p) => write!(f, "{} {} {}", self.command(), s, p),
- Self::CursorMoveUp(i) => write!(f, "{} {}", self.command(), i),
- Self::CursorMoveDown(i) => write!(f, "{} {}", self.command(), i),
+ Self::ChangeDirectory { path } => write!(f, "{} {:?}", self.command(), path),
+ Self::CommandLine { prefix, suffix } => {
+ write!(f, "{} {} || {}", self.command(), prefix, suffix)
+ }
+ Self::CursorMoveUp { offset } => write!(f, "{} {}", self.command(), offset),
+ Self::CursorMoveDown { offset } => write!(f, "{} {}", self.command(), offset),
+
+ Self::ParentCursorMoveUp { offset } => write!(f, "{} {}", self.command(), offset),
+ Self::ParentCursorMoveDown { offset } => write!(f, "{} {}", self.command(), offset),
- Self::NewDirectory(d) => write!(f, "{} {:?}", self.command(), d),
+ Self::PreviewCursorMoveUp { offset } => write!(f, "{} {}", self.command(), offset),
+ Self::PreviewCursorMoveDown { offset } => write!(f, "{} {}", self.command(), offset),
- Self::PasteFiles(options) => write!(f, "{} {}", self.command(), options),
+ Self::NewDirectory { path } => write!(f, "{} {:?}", self.command(), path),
+
+ Self::SymlinkFiles { relative } => {
+ write!(f, "{} --relative={}", self.command(), relative)
+ }
+ Self::PasteFiles { options } => write!(f, "{} {}", self.command(), options),
Self::DeleteFiles { background: false } => {
write!(f, "{} --foreground=true", self.command(),)
}
- Self::RenameFile(name) => write!(f, "{} {:?}", self.command(), name),
+ Self::RenameFile { new_name } => write!(f, "{} {:?}", self.command(), new_name),
- Self::SearchGlob(s) => write!(f, "{} {}", self.command(), s),
- Self::SearchString(s) => write!(f, "{} {}", self.command(), s),
- Self::SelectFiles(pattern, options) => {
+ Self::SearchGlob { pattern } => write!(f, "{} {}", self.command(), pattern),
+ Self::SearchString { pattern } => write!(f, "{} {}", self.command(), pattern),
+ Self::SelectFiles { pattern, options } => {
write!(f, "{} {} {}", self.command(), pattern, options)
}
- Self::SubProcess(c, _) => write!(f, "{} {:?}", self.command(), c),
+ Self::SubProcess { words, .. } => write!(f, "{} {:?}", self.command(), words),
Self::Sort(t) => write!(f, "{} {}", self.command(), t),
- Self::TabSwitch(i) => write!(f, "{} {}", self.command(), i),
- Self::TabSwitchIndex(i) => write!(f, "{} {}", self.command(), i),
+ 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 9507305..c84bc1b 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -26,7 +26,10 @@ impl std::str::FromStr for Command {
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(stripped) = s.strip_prefix(':') {
- return Ok(Self::CommandLine(stripped.to_owned(), "".to_owned()));
+ return Ok(Self::CommandLine {
+ prefix: stripped.to_owned(),
+ suffix: "".to_owned(),
+ });
}
let (command, arg) = match s.find(' ') {
@@ -68,7 +71,6 @@ impl std::str::FromStr for Command {
);
simple_command_conversion_case!(command, CMD_COPY_FILEPATH, Self::CopyFilePath);
simple_command_conversion_case!(command, CMD_COPY_DIRECTORY_PATH, Self::CopyDirPath);
- simple_command_conversion_case!(command, CMD_SYMLINK_FILES, Self::SymlinkFiles);
simple_command_conversion_case!(command, CMD_OPEN_FILE, Self::OpenFile);
@@ -97,7 +99,7 @@ impl std::str::FromStr for Command {
} else if command == CMD_CHANGE_DIRECTORY {
match arg {
"" => match HOME_DIR.as_ref() {
- Some(s) => Ok(Self::ChangeDirectory(s.clone())),
+ Some(s) => Ok(Self::ChangeDirectory { path: s.clone() }),
None => Err(JoshutoError::new(
JoshutoErrorKind::EnvVarNotPresent,
format!("{}: Cannot find home directory", command),
@@ -105,16 +107,17 @@ impl std::str::FromStr for Command {
},
".." => Ok(Self::ParentDirectory),
"-" => Ok(Self::PreviousDirectory),
- arg => Ok({
+ arg => {
let path_accepts_tilde = tilde_with_context(arg, home_dir);
- Self::ChangeDirectory(path::PathBuf::from(path_accepts_tilde.as_ref()))
- }),
+ let path = path::PathBuf::from(path_accepts_tilde.as_ref());
+ Ok(Self::ChangeDirectory { path })
+ }
}
} else if command == CMD_CURSOR_MOVE_DOWN {
match arg {
- "" => Ok(Self::CursorMoveDown(1)),
+ "" => Ok(Self::CursorMoveDown { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::CursorMoveDown(s)),
+ Ok(s) => Ok(Self::CursorMoveDown { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -129,9 +132,9 @@ impl std::str::FromStr for Command {
Ok(Self::CursorMovePageDown(p))
} else if command == CMD_CURSOR_MOVE_UP {
match arg {
- "" => Ok(Self::CursorMoveUp(1)),
+ "" => Ok(Self::CursorMoveUp { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::CursorMoveUp(s)),
+ Ok(s) => Ok(Self::CursorMoveUp { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -140,9 +143,9 @@ impl std::str::FromStr for Command {
}
} else if command == CMD_PARENT_CURSOR_MOVE_DOWN {
match arg {
- "" => Ok(Self::ParentCursorMoveDown(1)),
+ "" => Ok(Self::ParentCursorMoveDown { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::ParentCursorMoveDown(s)),
+ Ok(s) => Ok(Self::ParentCursorMoveDown { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -151,9 +154,9 @@ impl std::str::FromStr for Command {
}
} else if command == CMD_PARENT_CURSOR_MOVE_UP {
match arg {
- "" => Ok(Self::ParentCursorMoveUp(1)),
+ "" => Ok(Self::ParentCursorMoveUp { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::ParentCursorMoveUp(s)),
+ Ok(s) => Ok(Self::ParentCursorMoveUp { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -162,9 +165,9 @@ impl std::str::FromStr for Command {
}
} else if command == CMD_PREVIEW_CURSOR_MOVE_DOWN {
match arg {
- "" => Ok(Self::PreviewCursorMoveDown(1)),
+ "" => Ok(Self::PreviewCursorMoveDown { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::PreviewCursorMoveDown(s)),
+ Ok(s) => Ok(Self::PreviewCursorMoveDown { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -173,9 +176,9 @@ impl std::str::FromStr for Command {
}
} else if command == CMD_PREVIEW_CURSOR_MOVE_UP {
match arg {
- "" => Ok(Self::PreviewCursorMoveUp(1)),
+ "" => Ok(Self::PreviewCursorMoveUp { offset: 1 }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::PreviewCursorMoveUp(s)),
+ Ok(s) => Ok(Self::PreviewCursorMoveUp { offset: s }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
@@ -189,19 +192,35 @@ impl std::str::FromStr for Command {
format!("{}: no directory name given", command),
))
} else {
- Ok(Self::NewDirectory(path::PathBuf::from(arg)))
+ let path = path::PathBuf::from(arg);
+ Ok(Self::NewDirectory { path })
}
} else if command == CMD_OPEN_FILE_WITH {
match arg {
- "" => Ok(Self::OpenFileWith(None)),
+ "" => Ok(Self::OpenFileWith { index: None }),
arg => match arg.trim().parse::<usize>() {
- Ok(s) => Ok(Self::OpenFileWith(Some(s))),
+ Ok(s) => Ok(Self::OpenFileWith { index: Some(s) }),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ParseError,
e.to_string(),
)),
},
}
+ } else if command == CMD_SYMLINK_FILES {
+ let mut relative = false;
+ for arg in arg.split_whitespace() {
+ match arg {
+ "--relative=true" => relative = true,
+ "--relative=false" => relative = false,
+ _ => {
+ return Err(JoshutoError::new(
+ JoshutoErrorKind::UnrecognizedArgument,
+ format!("{}: unknown option '{}'", command, arg),
+ ));
+ }
+ }
+ }
+ Ok(Self::SymlinkFiles { relative })
} else if command == CMD_PASTE_FILES {
let mut options = FileOperationOptions::default();
for arg in arg.split_whitespace() {
@@ -218,7 +237,7 @@ impl std::str::FromStr for Command {
}
}
}
- Ok(Self::PasteFiles(options))
+ Ok(Self::PasteFiles { options })
} else if command == CMD_DELETE_FILES {
match arg {
"--foreground=true" => Ok(Self::DeleteFiles { background: true }),
@@ -236,7 +255,7 @@ impl std::str::FromStr for Command {
)),
arg => {
let path: path::PathBuf = path::PathBuf::from(arg);
- Ok(Self::RenameFile(path))
+ Ok(Self::RenameFile { new_name: path })
}
}
} else if command == CMD_SEARCH_STRING {
@@ -245,17 +264,23 @@ impl std::str::FromStr for Command {
JoshutoErrorKind::InvalidParameters,
format!("{}: Expected 1, got 0", command),
)),
- arg => Ok(Self::SearchString(arg.to_string())),
+ arg => Ok(Self::SearchString {
+ pattern: arg.to_string(),
+ }),
}
} else if command == CMD_SEARCH_INCREMENTAL {
- Ok(Self::SearchIncremental(arg.to_string()))
+ Ok(Self::SearchIncremental {
+ pattern: arg.to_string(),
+ })
} else if command == CMD_SEARCH_GLOB {
match arg {
"" => Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
format!("{}: Expected 1, got 0", command),
)),
- arg => Ok(Self::SearchGlob(arg.to_string())),
+ arg => Ok(Self::SearchGlob {
+ pattern: arg.to_string(),
+ }),
}
} else if command == CMD_SELECT_FILES {
let mut options = SelectOption::default();
@@ -273,7 +298,10 @@ impl std::str::FromStr for Command {
s => pattern = s,
}
}
- Ok(Self::SelectFiles(pattern.to_string(), options))
+ Ok(Self::SelectFiles {
+ pattern: pattern.to_string(),
+ options,
+ })
}
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
@@ -282,7 +310,10 @@ impl std::str::FromStr for Command {
}
} else if command == CMD_SUBPROCESS_FOREGROUND || command == CMD_SUBPROCESS_BACKGROUND {