summaryrefslogtreecommitdiffstats
path: root/src
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
parent596ced65ae6ae59f4e1ac2ed60246a4c5943a919 (diff)
add symlink relative
Diffstat (limited to 'src')
-rw-r--r--src/commands/file_ops.rs45
-rw-r--r--src/commands/flat.rs2
-rw-r--r--src/commands/numbered_command.rs2
-rw-r--r--src/commands/show_help.rs4
-rw-r--r--src/commands/tab_ops.rs4
-rw-r--r--src/event/process_event.rs21
-rw-r--r--src/io/file_operation.rs23
-rw-r--r--src/io/io_observer.rs9
-rw-r--r--src/io/io_worker.rs51
-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
-rw-r--r--src/ui/widgets/tui_worker.rs8
18 files changed, 379 insertions, 224 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs
index c50129b..dd16264 100644
--- a/src/commands/file_ops.rs
+++ b/src/commands/file_ops.rs
@@ -5,42 +5,35 @@ use crate::context::{AppContext, LocalStateContext};
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread};
-pub fn cut(context: &mut AppContext) -> JoshutoResult {
- if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() {
- let selected = list.get_selected_paths();
+fn new_local_state(context: &mut AppContext, file_op: FileOperation) -> Option<()> {
+ let list = context.tab_context_ref().curr_tab_ref().curr_list_ref()?;
+ let selected = list.get_selected_paths();
- let mut local_state = LocalStateContext::new();
- local_state.set_paths(selected.into_iter());
- local_state.set_file_op(FileOperation::Cut);
+ let mut local_state = LocalStateContext::new();
+ local_state.set_paths(selected.into_iter());
+ local_state.set_file_op(file_op);
- context.set_local_state(local_state);
- }
+ context.set_local_state(local_state);
+ Some(())
+}
+
+pub fn cut(context: &mut AppContext) -> JoshutoResult {
+ new_local_state(context, FileOperation::Cut);
Ok(())
}
pub fn copy(context: &mut AppContext) -> JoshutoResult {
- if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() {
- let selected = list.get_selected_paths();
-
- let mut local_state = LocalStateContext::new();
- local_state.set_paths(selected.into_iter());
- local_state.set_file_op(FileOperation::Copy);
-
- context.set_local_state(local_state);
- }
+ new_local_state(context, FileOperation::Copy);
Ok(())
}
-pub fn link(context: &mut AppContext) -> JoshutoResult {
- if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() {
- let selected = list.get_selected_paths();
-
- let mut local_state = LocalStateContext::new();
- local_state.set_paths(selected.into_iter());
- local_state.set_file_op(FileOperation::Symlink);
+pub fn symlink_absolute(context: &mut AppContext) -> JoshutoResult {
+ new_local_state(context, FileOperation::Symlink { relative: false });
+ Ok(())
+}
- context.set_local_state(local_state);
- }
+pub fn symlink_relative(context: &mut AppContext) -> JoshutoResult {
+ new_local_state(context, FileOperation::Symlink { relative: true });
Ok(())
}
diff --git a/src/commands/flat.rs b/src/commands/flat.rs
index 8e40151..94f0959 100644
--- a/src/commands/flat.rs
+++ b/src/commands/flat.rs
@@ -44,7 +44,7 @@ pub fn _walk_directory(
Ok(results)
}
-pub fn flatten(depth: usize, context: &mut AppContext) -> JoshutoResult {
+pub fn flatten(context: &mut AppContext, depth: usize) -> JoshutoResult {
let path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
let options = context.config_ref().display_options_ref().clone();
diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs
index c1331da..5072e0a 100644
--- a/src/commands/numbered_command.rs
+++ b/src/commands/numbered_command.rs
@@ -11,10 +11,10 @@ use crate::ui::views::TuiView;
use crate::ui::AppBackend;
pub fn numbered_command(
- first_char: char,
context: &mut AppContext,
backend: &mut AppBackend,
keymap: &AppKeyMapping,
+ first_char: char,
) -> JoshutoResult {
context.flush_event();
let mut prefix = String::from(first_char);
diff --git a/src/commands/show_help.rs b/src/commands/show_help.rs
index a8a7a4b..fbf80a0 100644
--- a/src/commands/show_help.rs
+++ b/src/commands/show_help.rs
@@ -52,8 +52,8 @@ pub fn help_loop(
keymap_t.help_view.get(&event)
{
match command {
- Command::CursorMoveUp(_) => move_offset(&mut offset, -1),
- Command::CursorMoveDown(_) => move_offset(&mut offset, 1),
+ Command::CursorMoveUp { .. } => move_offset(&mut offset, -1),
+ Command::CursorMoveDown { .. } => move_offset(&mut offset, 1),
Command::CursorMoveHome => offset = 0,
Command::CursorMoveEnd => offset = 255,
Command::CursorMovePageUp(_) => move_offset(&mut offset, -10),
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs
index bfd1d11..70e4ad1 100644
--- a/src/commands/tab_ops.rs
+++ b/src/commands/tab_ops.rs
@@ -69,7 +69,7 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<()
Ok(())
}
-pub fn tab_switch(offset: i32, context: &mut AppContext) -> std::io::Result<()> {
+pub fn tab_switch(context: &mut AppContext, offset: i32) -> std::io::Result<()> {
let index = context.tab_context_ref().index;
let num_tabs = context.tab_context_ref().len();
let new_index = (index as i32 + num_tabs as i32 + offset) as usize % num_tabs;
@@ -77,7 +77,7 @@ pub fn tab_switch(offset: i32, context: &mut AppContext) -> std::io::Result<()>
_tab_switch(new_index, context)
}
-pub fn tab_switch_index(new_index: usize, context: &mut AppContext) -> JoshutoResult {
+pub fn tab_switch_index(context: &mut AppContext, new_index: usize) -> JoshutoResult {
let num_tabs = context.tab_context_ref().len();
if new_index <= num_tabs {
_tab_switch(new_index - 1, context)?;
diff --git a/src/event/process_event.rs b/src/event/process_event.rs
index 125885e..5b759d7 100644
--- a/src/event/process_event.rs
+++ b/src/event/process_event.rs
@@ -13,7 +13,7 @@ use crate::context::AppContext;
use crate::event::AppEvent;
use crate::fs::JoshutoDirList;
use crate::history::DirectoryHistory;
-use crate::io::{FileOperation, FileOperationProgress};
+use crate::io::FileOperationProgress;
use crate::key_command::{AppExecute, Command, CommandKeybind};
use crate::preview::preview_dir::PreviewDirState;
use crate::preview::preview_file::{FilePreview, PreviewFileState};
@@ -116,12 +116,7 @@ pub fn process_finished_worker(
observer.join();
match res {
Ok(progress) => {
- let op = match progress.kind() {
- FileOperation::Cut => "moved",
- FileOperation::Copy => "copied",
- FileOperation::Symlink => "symlinked",
- FileOperation::Delete => "deleted",
- };
+ let op = progress.kind().actioned_str();
let processed_size = format::file_size_to_string(progress.bytes_processed());
let total_size = format::file_size_to_string(progress.total_bytes());
let msg = format!(
@@ -216,13 +211,13 @@ pub fn process_unsupported(
) {
match event.as_slice() {
[27, 79, 65] => {
- let command = Command::CursorMoveUp(1);
+ let command = Command::CursorMoveUp { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
}
[27, 79, 66] => {
- let command = Command::CursorMoveDown(1);
+ let command = Command::CursorMoveDown { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
@@ -255,12 +250,12 @@ pub fn process_mouse(
match event {
MouseEvent::Press(MouseButton::WheelUp, x, _) => {
if x < layout_rect[1].x {
- let command = Command::ParentCursorMoveUp(1);
+ let command = Command::ParentCursorMoveUp { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
} else if x < layout_rect[2].x {
- let command = Command::CursorMoveUp(1);
+ let command = Command::CursorMoveUp { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
@@ -270,12 +265,12 @@ pub fn process_mouse(
}
MouseEvent::Press(MouseButton::WheelDown, x, _) => {
if x < layout_rect[1].x {
- let command = Command::ParentCursorMoveDown(1);
+ let command = Command::ParentCursorMoveDown { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
} else if x < layout_rect[2].x {
- let command = Command::CursorMoveDown(1);
+ let command = Command::CursorMoveDown { offset: 1 };
if let Err(e) = command.execute(context, backend, keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
diff --git a/src/io/file_operation.rs b/src/io/file_operation.rs
index 9d39716..43589aa 100644
--- a/src/io/file_operation.rs
+++ b/src/io/file_operation.rs
@@ -2,16 +2,35 @@
pub enum FileOperation {
Cut,
Copy,
- Symlink,
+ Symlink { relative: bool },
Delete,
}
+impl FileOperation {
+ pub fn actioning_str(&self) -> &'static str {
+ match *self {
+ Self::Cut => "Moving",
+ Self::Copy => "Copying",
+ Self::Symlink { .. } => "Symlinking",
+ Self::Delete => "Deleting",
+ }
+ }
+ pub fn actioned_str(&self) -> &'static str {
+ match *self {
+ Self::Cut => "moved",
+ Self::Copy => "copied",
+ Self::Symlink { .. } => "symlinked",
+ Self::Delete => "deleted",
+ }
+ }
+}
+
impl std::fmt::Display for FileOperation {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Cut => write!(f, "Cut"),
Self::Copy => write!(f, "Copy"),
- Self::Symlink => write!(f, "Symlink"),
+ Self::Symlink { relative } => write!(f, "Symlink --relative={}", relative),
Self::Delete => write!(f, "Delete"),
}
}
diff --git a/src/io/io_observer.rs b/src/io/io_observer.rs
index 44d4248..93a1b15 100644
--- a/src/io/io_observer.rs
+++ b/src/io/io_observer.rs
@@ -1,7 +1,7 @@
use std::path;
use std::thread;
-use crate::io::{FileOperation, FileOperationProgress};
+use crate::io::FileOperationProgress;
use crate::util::format;
#[derive(Debug)]
@@ -34,12 +34,7 @@ impl IoWorkerObserver {
match self.progress.as_ref() {
None => {}
Some(progress) => {
- let op_str = match progress.kind() {
- FileOperation::Cut => "Moving",
- FileOperation::Copy => "Copying",
- FileOperation::Symlink => "Symlinking",
- FileOperation::Delete => "Deleting",
- };
+ let op_str = progress.kind().actioning_str();
let processed_size = format::file_size_to_string(progress.bytes_processed());
let total_size = format::file_size_to_string(progress.total_bytes());
diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs
index f9d86d9..54385ec 100644
--- a/src/io/io_worker.rs
+++ b/src/io/io_worker.rs
@@ -44,7 +44,8 @@ impl IoWorkerThread {
match self.kind() {
FileOperation::Cut => self.paste_cut(tx),
FileOperation::Copy => self.paste_copy(tx),
- FileOperation::Symlink => self.paste_link(tx),
+ FileOperation::Symlink { relative: false } => self.paste_link_absolute(tx),
+ FileOperation::Symlink { relative: true } => self.paste_link_relative(tx),
FileOperation::Delete => self.delete(tx),
}
}
@@ -87,7 +88,7 @@ impl IoWorkerThread {
Ok(progress)
}
- fn paste_link(
+ fn paste_link_absolute(
&self,
tx: mpsc::Sender<FileOperationProgress>,
) -> io::Result<FileOperationProgress> {
@@ -112,6 +113,52 @@ impl IoWorkerThread {
Ok(progress)
}
+ fn paste_link_relative(
+ &self,
+ tx: mpsc::Sender<FileOperationProgress>,
+ ) -> io::Result<FileOperationProgress> {
+ let total_files = self.paths.len();
+ let total_bytes = total_files as u64;
+ let mut progress = FileOperationProgress::new(self.kind(), 0, total_files, 0, total_bytes);
+
+ #[cfg(unix)]
+ for src in self.paths.iter() {
+ let _ = tx.send(progress.clone());
+ let mut dest_buf = self.dest.to_path_buf();
+ if let Some(s) = src.file_name() {
+ dest_buf.push(s);
+ }
+ if !self.options.overwrite {
+ rename_filename_conflict(&mut dest_buf);
+ }
+ let mut src_components = src.components();
+ let mut dest_components = dest_buf.components();
+
+ // skip to where the two paths diverge
+ let mut non_relative_path = path::PathBuf::new();
+ for (s, d) in src_components.by_ref().zip(dest_components.by_ref()) {
+ if s != d {
+ non_relative_path.push(s);
+ break;
+ }
+ }
+
+ let mut relative_path = path::PathBuf::new();
+ for _ in dest_components {
+ relative_path.push("..");
+ }
+ relative_path.push(non_relative_path);
+ for s in src_components {
+ relative_path.push(s);
+ }
+ unix::fs::symlink(relative_path, &dest_buf)?;
+
+ progress.set_files_processed(progress.files_processed() + 1);
+ progress.set_bytes_processed(progress.bytes_processed() + 1);
+ }
+ Ok(progress)
+ }
+
fn delete(
&self,
_tx: mpsc::Sender<FileOperationProgress>,
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::Command