From e7755ad0be98540c777d86c67605386ff11522a3 Mon Sep 17 00:00:00 2001 From: Jeff Zhao Date: Sat, 3 Sep 2022 12:45:51 -0400 Subject: add symlink relative --- src/commands/file_ops.rs | 45 +++++++-------- src/commands/flat.rs | 2 +- src/commands/numbered_command.rs | 2 +- src/commands/show_help.rs | 4 +- src/commands/tab_ops.rs | 4 +- src/event/process_event.rs | 21 +++---- src/io/file_operation.rs | 23 +++++++- src/io/io_observer.rs | 9 +-- src/io/io_worker.rs | 51 ++++++++++++++++- src/key_command/command.rs | 106 ++++++++++++++++++++++++++---------- src/key_command/impl_appcommand.rs | 48 ++++++++-------- src/key_command/impl_appexecute.rs | 75 +++++++++++++++---------- src/key_command/impl_comment.rs | 61 +++++++++++---------- src/key_command/impl_display.rs | 37 ++++++++----- src/key_command/impl_from_str.rs | 101 ++++++++++++++++++++++------------ src/key_command/impl_interactive.rs | 2 +- src/key_command/impl_numbered.rs | 4 +- src/ui/widgets/tui_worker.rs | 8 +-- 18 files changed, 379 insertions(+), 224 deletions(-) (limited to 'src') 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, ) -> io::Result { @@ -112,6 +113,52 @@ impl IoWorkerThread { Ok(progress) } + fn paste_link_relative( + &self, + tx: mpsc::Sender, + ) -> io::Result { + 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, 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), - + OpenFileWith { + index: Option, + }, 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, bool), + SubProcess { + words: Vec, + 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 { 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::() { - 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::() { - 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::() { - 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::() { - 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::() { - 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::() { - 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::() { - 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 { match shell_words::split(arg) { - Ok(s) if !s.is_empty() => Ok(Self::SubProcess(s, command == "spawn")), + Ok(s) if !s.is_empty() => Ok(Self::SubProcess { + words: s, + spawn: command == "spawn", + }), Ok(_) => Err(JoshutoError::new( JoshutoErrorKind::InvalidParameters, format!("{}: No commands given", command), @@ -305,22 +336,24 @@ impl std::str::FromStr for Command { } } else if command == CMD_TAB_SWITCH { match arg.parse::() { - Ok(s) => Ok(Self::TabSwitch(s)), + Ok(s) => Ok(Self::TabSwitch { offset: s }), Err(e) => Err(JoshutoError::new( JoshutoErrorKind::InvalidParameters, format!("{}: {}", command, e), )), } } else if command == CMD_TAB_SWITCH_INDEX { - match arg.parse::() { - Ok(s) => Ok(Self::TabSwitchIndex(s)), + match arg.parse::() { + Ok(s) => Ok(Self::TabSwitchIndex { index: s }), Err(e) => Err(JoshutoError::new( JoshutoErrorKind::InvalidParameters, format!("{}: {}", command, e), )), } } else if command == CMD_TOUCH_FILE { - Ok(Self::TouchFile(arg.to_string())) + Ok(Self::TouchFile { + file_name: arg.to_string(), + }) } else if command == CMD_SWITCH_LINE_NUMBERS { let policy = match arg { "absolute" | "1" => LineNumberStyle::Absolute, @@ -330,7 +363,7 @@ impl std::str::FromStr for Command { Ok(Self::SwitchLineNums(policy)) } else if command == CMD_FLAT { match arg.parse::() { - Ok(i) => Ok(Self::Flat(i + 1)), + Ok(i) => Ok(Self::Flat { depth: i + 1 }), Err(e) => Err(JoshutoError::new( JoshutoErrorKind::InvalidParameters, format!("{}: {}", command, e), @@ -339,7 +372,7 @@ impl std::str::FromStr for Command { } else if command == CMD_NUMBERED_COMMAND { let c = arg.chars().next(); match c { - Some(c) => Ok(Self::NumberedCommand(c)), + Some(c) => Ok(Self::NumberedCommand { initial: c }), None => Err(JoshutoError::new( JoshutoErrorKind::InvalidParameters, format!("{}: no starting character given", command), diff --git a/src/key_command/impl_interactive.rs b/src/key_command/impl_interactive.rs index d2e102e..f92137d 100644 --- a/src/key_command/impl_interactive.rs +++ b/src/key_command/impl_interactive.rs @@ -7,7 +7,7 @@ impl InteractiveExecute for Command { #[allow(clippy::single_match)] fn interactive_execute(&self, context: &mut AppContext) { match self { - Self::SearchIncremental(pattern) => { + Self::SearchIncremental { pattern } => { search_string::search_string(context, pattern.as_str(), true) } _ => (), diff --git a/src/key_command/impl_numbered.rs b/src/key_command/impl_numbered.rs index d1f05f0..74ad6ee 100644 --- a/src/key_command/impl_numbered.rs +++ b/src/key_command/impl_numbered.rs @@ -19,8 +19,8 @@ impl NumberedExecute for Command { keymap_t: &AppKeyMapping, ) -> JoshutoResult { match self { - Self::CursorMoveUp(_) => cursor_move::up(context, number_prefix), - Self::CursorMoveDown(_) => cursor_move::down(context, number_prefix), + Self::CursorMoveUp { .. } => cursor_move::up(context, number_prefix), + Self::CursorMoveDown { .. } => cursor_move::down(context, number_prefix), _ => Err(JoshutoError::new( JoshutoErrorKind::UnrecognizedCommand, "Command cannot be prefixed by a number".to_string(), diff --git a/src/ui/widgets/tui_worker.rs b/src/ui/widgets/tui_worker.rs index 4ac034a..cb6460e 100644 --- a/src/ui/widgets/tui_worker.rs +++ b/src/ui/widgets/tui_worker.rs @@ -4,7 +4,6 @@ use tui::style::{Color, Modifier, Style}; use tui::widgets::Widget; use crate::context::WorkerContext; -use crate::io::FileOperation; use crate::util::format; pub struct TuiWorker<'a> { @@ -22,12 +21,7 @@ impl<'a> Widget for TuiWorker<'a> { match self.context.worker_ref() { Some(io_obs) => { if let Some(progress) = io_obs.progress.as_ref() { - 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()); -- cgit v1.2.3