diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-01 12:00:36 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-01 12:00:36 -0400 |
commit | ee0dec521b73a4328660969c3be8454dc0bf73e8 (patch) | |
tree | 7c13b7f82a0faf6c9116ddfdc8458b43289d63a0 /src/commands | |
parent | 7cb3e8be67621191a43d530a5a0a4e49baec26e0 (diff) |
add delete_files with foreground option
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/delete_files.rs | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index c56118d..272fd1a 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -1,14 +1,20 @@ use std::path; +use std::sync::mpsc; use termion::event::Key; use crate::context::AppContext; +use crate::error::JoshutoResult; use crate::history::DirectoryHistory; use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread}; use crate::ui::widgets::TuiPrompt; use crate::ui::AppBackend; -fn delete_files(context: &mut AppContext, backend: &mut AppBackend) -> std::io::Result<()> { +fn delete_files( + context: &mut AppContext, + backend: &mut AppBackend, + background: bool, +) -> std::io::Result<()> { let paths = context .tab_context_ref() .curr_tab_ref() @@ -47,12 +53,18 @@ fn delete_files(context: &mut AppContext, backend: &mut AppBackend) -> std::io:: let options = FileOperationOptions { overwrite: false, skip_exist: false, + symlink: false, permanently: !context.config_ref().use_trash, }; let dest = path::PathBuf::new(); let worker_thread = IoWorkerThread::new(file_op, paths, dest, options); - context.worker_context_mut().push_worker(worker_thread); + if background { + context.worker_context_mut().push_worker(worker_thread); + } else { + let (wtx, _) = mpsc::channel(); + worker_thread.start(wtx)?; + } } Ok(()) } @@ -60,11 +72,11 @@ fn delete_files(context: &mut AppContext, backend: &mut AppBackend) -> std::io:: } } -pub fn delete_selected_files( +fn _delete_selected_files( context: &mut AppContext, backend: &mut AppBackend, ) -> std::io::Result<()> { - let _ = delete_files(context, backend)?; + let _ = delete_files(context, backend, false)?; let options = context.config_ref().display_options_ref().clone(); let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf(); @@ -73,3 +85,30 @@ pub fn delete_selected_files( } Ok(()) } + +pub fn delete_selected_files(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult { + _delete_selected_files(context, backend)?; + Ok(()) +} + +fn _delete_selected_files_background( + context: &mut AppContext, + backend: &mut AppBackend, +) -> std::io::Result<()> { + let _ = delete_files(context, backend, true)?; + + let options = context.config_ref().display_options_ref().clone(); + let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf(); + for tab in context.tab_context_mut().iter_mut() { + tab.history_mut().reload(&curr_path, &options)?; + } + Ok(()) +} + +pub fn delete_selected_files_background( + context: &mut AppContext, + backend: &mut AppBackend, +) -> JoshutoResult { + _delete_selected_files(context, backend)?; + Ok(()) +} |