diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-08-30 15:20:03 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-08-30 15:20:03 -0400 |
commit | e7218c81d90ae07d7f56dce0c3032db15b11d118 (patch) | |
tree | 63c3b63345ec73031b26c1b900957ad06b69aec6 /src/util | |
parent | a592bfe51c0cbb7744f14586520827cb06da8c8d (diff) |
rework and fix issues
- fixed bug where io tasks would not run when user is in a textfield or prompt
- fixed bug where cut doesn't work
- rework structs to have private fields and public functions
- move IOWorkerObserver into seperate file
- move code from TuiView to TuiFolderView
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/load_child.rs | 2 | ||||
-rw-r--r-- | src/util/mod.rs | 1 | ||||
-rw-r--r-- | src/util/unix.rs | 4 | ||||
-rw-r--r-- | src/util/worker.rs | 53 |
4 files changed, 58 insertions, 2 deletions
diff --git a/src/util/load_child.rs b/src/util/load_child.rs index b295f03..4d293fc 100644 --- a/src/util/load_child.rs +++ b/src/util/load_child.rs @@ -22,7 +22,7 @@ impl LoadChild { context .tab_context_mut() .curr_tab_mut() - .history + .history_mut() .create_or_soft_update(path.as_path(), &options)?; } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 862f989..6ba770d 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -4,3 +4,4 @@ pub mod key_mapping; pub mod load_child; pub mod sort; pub mod unix; +pub mod worker; diff --git a/src/util/unix.rs b/src/util/unix.rs index 6a52c3a..b2105a9 100644 --- a/src/util/unix.rs +++ b/src/util/unix.rs @@ -3,7 +3,9 @@ use std::path::Path; pub fn is_executable(mode: u32) -> bool { const LIBC_PERMISSION_VALS: [libc::mode_t; 3] = [libc::S_IXUSR, libc::S_IXGRP, libc::S_IXOTH]; - LIBC_PERMISSION_VALS.iter().any(|val| mode & (*val as u32) != 0) + LIBC_PERMISSION_VALS + .iter() + .any(|val| mode & (*val as u32) != 0) } pub fn stringify_mode(mode: u32) -> String { diff --git a/src/util/worker.rs b/src/util/worker.rs new file mode 100644 index 0000000..73e7277 --- /dev/null +++ b/src/util/worker.rs @@ -0,0 +1,53 @@ +use crate::context::JoshutoContext; +use crate::history::DirectoryHistory; +use crate::io::FileOp; + +use super::format; + +pub fn process_worker_progress(context: &mut JoshutoContext, res: (FileOp, u64)) { + let (file_op, progress) = res; + let prog_str = format::file_size_to_string(progress); + match file_op { + FileOp::Cut => { + context.set_worker_msg(format!("{} moved", prog_str)); + } + FileOp::Copy => { + context.set_worker_msg(format!("{} copied", prog_str)); + } + } +} + +pub fn process_finished_worker( + context: &mut JoshutoContext, + res: (FileOp, Result<u64, std::io::Error>), +) { + let (file_op, status) = res; + let observer = context.remove_job().unwrap(); + let options = context.config_t.sort_option.clone(); + for tab in context.tab_context_mut().iter_mut() { + tab.history_mut().reload(observer.get_dest_path(), &options); + tab.history_mut().reload(observer.get_src_path(), &options); + } + match status { + Ok(p) => { + let msg = match file_op { + FileOp::Copy => format!( + "copied {} to {:?}", + format::file_size_to_string(p), + observer.get_dest_path() + ), + FileOp::Cut => format!( + "moved {} to {:?}", + format::file_size_to_string(p), + observer.get_dest_path() + ), + }; + context.push_msg(msg); + } + Err(e) => { + let msg = format!("{}", e); + context.push_msg(msg); + } + } + observer.join(); +} |