summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2023-03-10 10:45:46 -0500
committerJeff Zhao <jeff.no.zhao@gmail.com>2023-03-10 10:45:46 -0500
commita5a0016052d45fe7ef5bfd73a093f4ec99c6a0d3 (patch)
tree2168545ad23ef4026eace23eaec3747fbd7a29b6
parentba59edf197d3a3cedf10780e117118c8920248c6 (diff)
parent3339c9b2294890fa4bd017794345bc1315cca92c (diff)
Merge branch 'dev'
-rw-r--r--src/io/file_operation.rs13
-rw-r--r--src/io/io_worker.rs75
-rw-r--r--src/key_command/impl_from_str.rs7
-rw-r--r--src/ui/widgets/tui_worker.rs49
-rw-r--r--src/util/fs.rs35
-rw-r--r--src/util/mod.rs1
6 files changed, 122 insertions, 58 deletions
diff --git a/src/io/file_operation.rs b/src/io/file_operation.rs
index 43589aa..c6dfb74 100644
--- a/src/io/file_operation.rs
+++ b/src/io/file_operation.rs
@@ -1,3 +1,5 @@
+use std::path;
+
#[derive(Clone, Copy, Debug)]
pub enum FileOperation {
Cut,
@@ -59,6 +61,7 @@ impl std::fmt::Display for FileOperationOptions {
#[derive(Clone, Debug)]
pub struct FileOperationProgress {
_kind: FileOperation,
+ _current_file: path::PathBuf,
_files_processed: usize,
_total_files: usize,
_bytes_processed: u64,
@@ -68,6 +71,7 @@ pub struct FileOperationProgress {
impl FileOperationProgress {
pub fn new(
_kind: FileOperation,
+ _current_file: path::PathBuf,
_files_processed: usize,
_total_files: usize,
_bytes_processed: u64,
@@ -75,6 +79,7 @@ impl FileOperationProgress {
) -> Self {
Self {
_kind,
+ _current_file,
_files_processed,
_total_files,
_bytes_processed,
@@ -86,6 +91,14 @@ impl FileOperationProgress {
self._kind
}
+ pub fn current_file(&self) -> &path::Path {
+ self._current_file.as_path()
+ }
+
+ pub fn set_current_file(&mut self, current_file: path::PathBuf) {
+ self._current_file = current_file;
+ }
+
pub fn files_processed(&self) -> usize {
self._files_processed
}
diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs
index 6ed7b9f..42a3ef5 100644
--- a/src/io/io_worker.rs
+++ b/src/io/io_worker.rs
@@ -1,4 +1,3 @@
-use std::collections::VecDeque;
use std::fs;
use std::io;
use std::path;
@@ -8,6 +7,7 @@ use std::sync::mpsc;
use std::os::unix;
use crate::io::{FileOperation, FileOperationOptions, FileOperationProgress};
+use crate::util::fs::query_number_of_items;
use crate::util::name_resolution::rename_filename_conflict;
#[derive(Clone, Debug)]
@@ -55,7 +55,14 @@ impl IoWorkerThread {
tx: mpsc::Sender<FileOperationProgress>,
) -> io::Result<FileOperationProgress> {
let (total_files, total_bytes) = query_number_of_items(&self.paths)?;
- let mut progress = FileOperationProgress::new(self.kind(), 0, total_files, 0, total_bytes);
+ let mut progress = FileOperationProgress::new(
+ self.kind(),
+ self.paths[0].to_path_buf(),
+ 0,
+ total_files,
+ 0,
+ total_bytes,
+ );
for path in self.paths.iter() {
let _ = tx.send(progress.clone());
recursive_copy(
@@ -74,7 +81,14 @@ impl IoWorkerThread {
tx: mpsc::Sender<FileOperationProgress>,
) -> io::Result<FileOperationProgress> {
let (total_files, total_bytes) = query_number_of_items(&self.paths)?;
- let mut progress = FileOperationProgress::new(self.kind(), 0, total_files, 0, total_bytes);
+ let mut progress = FileOperationProgress::new(
+ self.kind(),
+ self.paths[0].to_path_buf(),
+ 0,
+ total_files,
+ 0,
+ total_bytes,
+ );
for path in self.paths.iter() {
let _ = tx.send(progress.clone());
recursive_cut(
@@ -94,7 +108,14 @@ impl IoWorkerThread {
) -> 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);
+ let mut progress = FileOperationProgress::new(
+ self.kind(),
+ self.paths[0].to_path_buf(),
+ 0,
+ total_files,
+ 0,
+ total_bytes,
+ );
#[cfg(unix)]
for src in self.paths.iter() {
@@ -119,7 +140,14 @@ impl IoWorkerThread {
) -> 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);
+ let mut progress = FileOperationProgress::new(
+ self.kind(),
+ self.paths[0].to_path_buf(),
+ 0,
+ total_files,
+ 0,
+ total_bytes,
+ );
#[cfg(unix)]
for src in self.paths.iter() {
@@ -166,6 +194,7 @@ impl IoWorkerThread {
let (total_files, total_bytes) = query_number_of_items(&self.paths)?;
let progress = FileOperationProgress::new(
self.kind(),
+ self.paths[0].to_path_buf(),
total_files,
total_files,
total_bytes,
@@ -180,37 +209,6 @@ impl IoWorkerThread {
}
}
-fn query_number_of_items(paths: &[path::PathBuf]) -> io::Result<(usize, u64)> {
- let mut total_bytes = 0;
- let mut total_files = 0;
-
- let mut dirs: VecDeque<path::PathBuf> = VecDeque::new();
- for path in paths.iter() {
- let metadata = path.symlink_metadata()?;
- if metadata.is_dir() {
- dirs.push_back(path.clone());
- } else {
- let metadata = path.symlink_metadata()?;
- total_bytes += metadata.len();
- total_files += 1;
- }
- }
-
- while let Some(dir) = dirs.pop_front() {
- for entry in fs::read_dir(dir)? {
- let path = entry?.path();
- if path.is_dir() {
- dirs.push_back(path);
- } else {
- let metadata = path.symlink_metadata()?;
- total_bytes += metadata.len();
- total_files += 1;
- }
- }
- }
- Ok((total_files, total_bytes))
-}
-
pub fn recursive_copy(
tx: &mpsc::Sender<FileOperationProgress>,
src: &path::Path,
@@ -225,6 +223,9 @@ pub fn recursive_copy(
if !options.overwrite {
rename_filename_conflict(&mut dest_buf);
}
+
+ progress.set_current_file(src.to_path_buf());
+
let file_type = fs::symlink_metadata(src)?.file_type();
if file_type.is_dir() {
match fs::create_dir(dest_buf.as_path()) {
@@ -280,6 +281,8 @@ pub fn recursive_cut(
let metadata = fs::symlink_metadata(src)?;
let file_type = metadata.file_type();
+ progress.set_current_file(src.to_path_buf());
+
match fs::rename(src, dest_buf.as_path()) {
Ok(_) => {
let bytes_processed = progress.bytes_processed() + metadata.len();
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index e710b71..b88af8c 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -246,11 +246,12 @@ impl std::str::FromStr for Command {
}
Ok(Self::PasteFiles { options })
} else if command == CMD_DELETE_FILES {
- let (mut permanently, mut background) = (false, true);
+ let (mut permanently, mut background) = (false, false);
for arg in arg.split_whitespace() {
+ eprintln!("arg: {:?}", arg);
match arg {
- "--foreground=true" => background = true,
- "--foreground=false" => background = false,
+ "--background=true" => background = true,
+ "--background=false" => background = false,
"--permanently" => permanently = true,
_ => {
return Err(JoshutoError::new(
diff --git a/src/ui/widgets/tui_worker.rs b/src/ui/widgets/tui_worker.rs
index 4edfa22..3d06131 100644
--- a/src/ui/widgets/tui_worker.rs
+++ b/src/ui/widgets/tui_worker.rs
@@ -19,6 +19,9 @@ impl<'a> TuiWorker<'a> {
impl<'a> Widget for TuiWorker<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
+ if area.height < 7 {
+ return;
+ }
match self.context.worker_ref() {
Some(io_obs) => {
if let Some(progress) = io_obs.progress.as_ref() {
@@ -27,19 +30,19 @@ impl<'a> Widget for TuiWorker<'a> {
..area
};
TuiCurrentWorker::new(io_obs, progress).render(current_area, buf);
+ }
- // draw queued up work
- let style = Style::default()
- .fg(Color::Yellow)
- .add_modifier(Modifier::BOLD);
- buf.set_stringn(0, 5, "Queue:", area.width as usize, style);
+ // draw queued up work
+ let style = Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD);
+ buf.set_stringn(0, 6, "Queue:", area.width as usize, style);
- let queue_area = Rect {
- y: area.y + 7,
- ..area
- };
- TuiWorkerQueue::new(self.context).render(queue_area, buf);
- }
+ let queue_area = Rect {
+ y: area.y + 7,
+ ..area
+ };
+ TuiWorkerQueue::new(self.context).render(queue_area, buf);
}
_ => {
let style = Style::default();
@@ -76,22 +79,30 @@ impl<'a> Widget for TuiCurrentWorker<'a> {
let total_size = format::file_size_to_string(self.progress.total_bytes());
let msg = format!(
- "{} ({}/{}) ({}/{})\n",
+ "{} ({}/{}) ({}/{}) {:?}",
op_str,
self.progress.files_processed() + 1,
self.progress.total_files(),
processed_size,
total_size,
+ self.observer.dest_path(),
);
buf.set_stringn(left, top, msg, right as usize, Style::default());
- buf.set_stringn(
- left,
- top + 1,
- format!("{:?}\n", self.observer.dest_path()),
- right as usize,
- Style::default(),
- );
+ if let Some(file_name) = self
+ .progress
+ .current_file()
+ .file_name()
+ .map(|s| s.to_string_lossy())
+ {
+ buf.set_stringn(
+ left,
+ top + 1,
+ format!("{}", file_name),
+ right as usize,
+ Style::default(),
+ );
+ }
// draw a progress bar
let progress_bar_width = (self.progress.files_processed() as f32
diff --git a/src/util/fs.rs b/src/util/fs.rs
new file mode 100644
index 0000000..cabf374
--- /dev/null
+++ b/src/util/fs.rs
@@ -0,0 +1,35 @@
+use std::collections::VecDeque;
+use std::fs;
+use std::io;
+use std::path;
+
+pub fn query_number_of_items(paths: &[path::PathBuf]) -> io::Result<(usize, u64)> {
+ let mut total_bytes = 0;
+ let mut total_files = 0;
+
+ let mut dirs: VecDeque<path::PathBuf> = VecDeque::new();
+ for path in paths.iter() {
+ let metadata = path.symlink_metadata()?;
+ if metadata.is_dir() {
+ dirs.push_back(path.clone());
+ } else {
+ let metadata = path.symlink_metadata()?;
+ total_bytes += metadata.len();
+ total_files += 1;
+ }
+ }
+
+ while let Some(dir) = dirs.pop_front() {
+ for entry in fs::read_dir(dir)? {
+ let path = entry?.path();
+ if path.is_dir() {
+ dirs.push_back(path);
+ } else {
+ let metadata = path.symlink_metadata()?;
+ total_bytes += metadata.len();
+ total_files += 1;
+ }
+ }
+ }
+ Ok((total_files, total_bytes))
+} \ No newline at end of file
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 562ec57..313f193 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -2,6 +2,7 @@
pub mod devicons;
pub mod format;
+pub mod fs;
pub mod keyparse;
pub mod mimetype;
pub mod name_resolution;