diff --git a/Cargo.lock b/Cargo.lock index fcf8d68..db9fb97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,20 +189,6 @@ dependencies = [ "roff", ] -[[package]] -name = "console" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "terminal_size", - "unicode-width", - "winapi", -] - [[package]] name = "crc32fast" version = "1.3.2" @@ -239,12 +225,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "fastrand" version = "1.8.0" @@ -355,17 +335,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "indicatif" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b" -dependencies = [ - "console", - "number_prefix", - "unicode-width", -] - [[package]] name = "infer" version = "0.9.0" @@ -514,12 +483,6 @@ dependencies = [ "libc", ] -[[package]] -name = "number_prefix" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" - [[package]] name = "once_cell" version = "1.15.0" @@ -547,7 +510,6 @@ dependencies = [ "fs-err", "humansize", "ignore", - "indicatif", "infer", "is_executable", "libc", @@ -894,16 +856,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "termtree" version = "0.2.4" @@ -955,12 +907,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "uuid" version = "1.2.1" diff --git a/Cargo.toml b/Cargo.toml index 08eb4af..6ba1003 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,11 @@ description = "A command-line utility for easily compressing and decompressing f atty = "0.2.14" bzip2 = "0.4.3" clap = { version = "4.0.13", features = ["derive", "env"] } +filetime = "0.2.17" flate2 = { version = "1.0.24", default-features = false } fs-err = "2.8.1" humansize = "2.1.0" +ignore = "0.4.18" libc = "0.2.135" linked-hash-map = "0.5.6" lzzzz = "1.0.3" @@ -26,13 +28,10 @@ once_cell = "1.15.0" same-file = "1.0.6" snap = "1.0.5" tar = "0.4.38" +tempfile = "3.3.0" xz2 = "0.1.7" zip = { version = "0.6.2", default-features = false, features = ["time"] } zstd = { version = "0.11.2", default-features = false } -tempfile = "3.3.0" -ignore = "0.4.18" -indicatif = "0.17.1" -filetime = "0.2.17" [target.'cfg(unix)'.dependencies] time = { version = "0.3.15", default-features = false } diff --git a/src/accessible.rs b/src/accessible.rs index 5f26411..1e4e220 100644 --- a/src/accessible.rs +++ b/src/accessible.rs @@ -2,7 +2,6 @@ use once_cell::sync::OnceCell; /// Whether to enable accessible output (removes info output and reduces other /// output, removes visual markers like '[' and ']'). -/// Removes th progress bar as well pub static ACCESSIBLE: OnceCell = OnceCell::new(); pub fn is_running_in_accessible_mode() -> bool { diff --git a/src/archive/tar.rs b/src/archive/tar.rs index f8d8b13..f7f3763 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -16,18 +16,13 @@ use crate::{ error::FinalError, info, list::FileInArchive, - progress::OutputLine, utils::{self, FileVisibilityPolicy}, warning, }; /// Unpacks the archive given by `archive` into the folder given by `into`. /// Assumes that output_folder is empty -pub fn unpack_archive( - reader: Box, - output_folder: &Path, - mut log_out: impl OutputLine, -) -> crate::Result> { +pub fn unpack_archive(reader: Box, output_folder: &Path) -> crate::Result> { assert!(output_folder.read_dir().expect("dir exists").count() == 0); let mut archive = tar::Archive::new(reader); @@ -44,7 +39,6 @@ pub fn unpack_archive( // and so on info!( - @log_out, inaccessible, "{:?} extracted. ({})", utils::strip_cur_dir(&output_folder.join(file.path()?)), @@ -87,16 +81,14 @@ pub fn list_archive( } /// Compresses the archives given by `input_filenames` into the file given previously to `writer`. -pub fn build_archive_from_paths( +pub fn build_archive_from_paths( input_filenames: &[PathBuf], output_path: &Path, writer: W, file_visibility_policy: FileVisibilityPolicy, - mut log_out: D, ) -> crate::Result where W: Write, - D: OutputLine, { let mut builder = tar::Builder::new(writer); let output_handle = Handle::from_path(output_path); @@ -115,7 +107,6 @@ where if let Ok(ref handle) = output_handle { if matches!(Handle::from_path(path), Ok(x) if &x == handle) { warning!( - @log_out, "The output file and the input file are the same: `{}`, skipping...", output_path.display() ); @@ -127,7 +118,7 @@ where // little importance for most users, but would generate lots of // spoken text for users using screen readers, braille displays // and so on - info!(@log_out, inaccessible, "Compressing '{}'.", utils::to_utf(path)); + info!(inaccessible, "Compressing '{}'.", utils::to_utf(path)); if path.is_dir() { builder.append_dir(path, path)?; diff --git a/src/archive/zip.rs b/src/archive/zip.rs index efc4667..585acf7 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -20,7 +20,6 @@ use crate::{ error::FinalError, info, list::FileInArchive, - progress::OutputLine, utils::{ self, cd_into_same_dir_as, get_invalid_utf8_paths, pretty_format_list_of_paths, strip_cur_dir, to_utf, FileVisibilityPolicy, @@ -30,14 +29,9 @@ use crate::{ /// Unpacks the archive given by `archive` into the folder given by `output_folder`. /// Assumes that output_folder is empty -pub fn unpack_archive( - mut archive: ZipArchive, - output_folder: &Path, - mut log_out: D, -) -> crate::Result> +pub fn unpack_archive(mut archive: ZipArchive, output_folder: &Path) -> crate::Result> where R: Read + Seek, - D: OutputLine, { assert!(output_folder.read_dir().expect("dir exists").count() == 0); @@ -60,7 +54,7 @@ where // importance for most users, but would generate lots of // spoken text for users using screen readers, braille displays // and so on - info!(@log_out, inaccessible, "File {} extracted to \"{}\"", idx, file_path.display()); + info!(inaccessible, "File {} extracted to \"{}\"", idx, file_path.display()); fs::create_dir_all(&file_path)?; } _is_file @ false => { @@ -73,7 +67,6 @@ where // same reason is in _is_dir: long, often not needed text info!( - @log_out, inaccessible, "{:?} extracted. ({})", file_path.display(), @@ -137,16 +130,14 @@ where } /// Compresses the archives given by `input_filenames` into the file given previously to `writer`. -pub fn build_archive_from_paths( +pub fn build_archive_from_paths( input_filenames: &[PathBuf], output_path: &Path, writer: W, file_visibility_policy: FileVisibilityPolicy, - mut log_out: D, ) -> crate::Result where W: Write + Seek, - D: OutputLine, { let mut writer = zip::ZipWriter::new(writer); let options = zip::write::FileOptions::default(); @@ -183,7 +174,6 @@ where if let Ok(ref handle) = output_handle { if matches!(Handle::from_path(path), Ok(x) if &x == handle) { warning!( - @log_out, "The output file and the input file are the same: `{}`, skipping...", output_path.display() ); @@ -195,7 +185,7 @@ where // little importance for most users, but would generate lots of // spoken text for users using screen readers, braille displays // and so on - info!(@log_out, inaccessible, "Compressing '{}'.", to_utf(path)); + info!(inaccessible, "Compressing '{}'.", to_utf(path)); let metadata = match path.metadata() { Ok(metadata) => metadata, diff --git a/src/commands/compress.rs b/src/commands/compress.rs index 1643477..1936036 100644 --- a/src/commands/compress.rs +++ b/src/commands/compress.rs @@ -6,7 +6,6 @@ use std::{ use fs_err as fs; use crate::{ - accessible::is_running_in_accessible_mode, archive, commands::warn_user_about_loading_zip_in_memory, extension::{ @@ -14,7 +13,6 @@ use crate::{ CompressionFormat::{self, *}, Extension, }, - progress::Progress, utils::{user_wants_to_continue, FileVisibilityPolicy}, QuestionAction, QuestionPolicy, BUFFER_CAPACITY, }; @@ -37,15 +35,7 @@ pub fn compress_files( question_policy: QuestionPolicy, file_visibility_policy: FileVisibilityPolicy, ) -> crate::Result { - // The next lines are for displaying the progress bar // If the input files contain a directory, then the total size will be underestimated - let (total_input_size, precise) = files - .iter() - .map(|f| (f.metadata().expect("file exists").len(), f.is_file())) - .fold((0, true), |(total_size, and_precise), (size, precise)| { - (total_size + size, and_precise & precise) - }); - let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file); let mut writer: Box = Box::new(file_writer); @@ -81,37 +71,11 @@ pub fn compress_files( writer = chain_writer_encoder(&first_format, writer)?; let mut reader = fs::File::open(&files[0]).unwrap(); - if is_running_in_accessible_mode() { - io::copy(&mut reader, &mut writer)?; - } else { - io::copy( - &mut Progress::new(total_input_size, precise, true).wrap_read(reader), - &mut writer, - )?; - } + io::copy(&mut reader, &mut writer)?; } Tar => { - if is_running_in_accessible_mode() { - archive::tar::build_archive_from_paths( - &files, - output_path, - &mut writer, - file_visibility_policy, - io::stderr(), - )?; - writer.flush()?; - } else { - let mut progress = Progress::new(total_input_size, precise, true); - let mut writer = progress.wrap_write(writer); - archive::tar::build_archive_from_paths( - &files, - output_path, - &mut writer, - file_visibility_policy, - &mut progress, - )?; - writer.flush()?; - } + archive::tar::build_archive_from_paths(&files, output_path, &mut writer, file_visibility_policy)?; + writer.flush()?; } Zip => { if !formats.is_empty() { @@ -124,28 +88,9 @@ pub fn compress_files( let mut vec_buffer = Cursor::new(vec![]); - if is_running_in_accessible_mode() { - archive::zip::build_archive_from_paths( - &files, - output_path, - &mut vec_buffer, - file_visibility_policy, - io::stderr(), - )?; - vec_buffer.rewind()?; - io::copy(&mut vec_buffer, &mut writer)?; - } else { - let mut progress = Progress::new(total_input_size, precise, true); - archive::zip::build_archive_from_paths( - &files, - output_path, - &mut vec_buffer, - file_visibility_policy, - &mut progress, - )?; - vec_buffer.rewind()?; - io::copy(&mut progress.wrap_read(vec_buffer), &mut writer)?; - } + archive::zip::build_archive_from_paths(&files, output_path, &mut vec_buffer, file_visibility_policy)?; + vec_buffer.rewind()?; + io::copy(&mut vec_buffer, &mut writer)?; } } diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index 02e5d9f..937902d 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -7,7 +7,6 @@ use std::{ use fs_err as fs; use crate::{ - accessible::is_running_in_accessible_mode, commands::warn_user_about_loading_zip_in_memory, extension::{ split_first_compression_format, @@ -15,7 +14,6 @@ use crate::{ Extension, }, info, - progress::{OutputLine, Progress}, utils::{self, nice_directory_display, user_wants_to_continue}, QuestionAction, QuestionPolicy, BUFFER_CAPACITY, }; @@ -34,7 +32,6 @@ pub fn decompress_file( question_policy: QuestionPolicy, ) -> crate::Result<()> { assert!(output_dir.exists()); - let total_input_size = input_file_path.metadata().expect("file exists").len(); let reader = fs::File::open(input_file_path)?; // Zip archives are special, because they require io::Seek, so it requires it's logic separated @@ -51,8 +48,7 @@ pub fn decompress_file( { let zip_archive = zip::ZipArchive::new(reader)?; let files = if let ControlFlow::Continue(files) = smart_unpack( - |output_dir, progress| crate::archive::zip::unpack_archive(zip_archive, output_dir, progress), - total_input_size, + |output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir), output_dir, &output_file_path, question_policy, @@ -109,21 +105,13 @@ pub fn decompress_file( None => return Ok(()), }; - if is_running_in_accessible_mode() { - io::copy(&mut reader, &mut writer)?; - } else { - io::copy( - &mut Progress::new(total_input_size, true, true).wrap_read(reader), - &mut writer, - )?; - } + io::copy(&mut reader, &mut writer)?; vec![output_file_path] } Tar => { if let ControlFlow::Continue(files) = smart_unpack( - |output_dir, progress| crate::archive::tar::unpack_archive(reader, output_dir, progress), - total_input_size, + |output_dir| crate::archive::tar::unpack_archive(reader, output_dir), output_dir, &output_file_path, question_policy, @@ -147,8 +135,7 @@ pub fn decompress_file( let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?; if let ControlFlow::Continue(files) = smart_unpack( - |output_dir, progress| crate::archive::zip::unpack_archive(zip_archive, output_dir, progress), - total_input_size, + |output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir), output_dir, &output_file_path, question_policy, @@ -180,8 +167,7 @@ pub fn decompress_file( /// output_dir named after the archive (given by `output_file_path`) /// Note: This functions assumes that `output_dir` exists fn smart_unpack( - unpack_fn: impl FnOnce(&Path, &mut dyn OutputLine) -> crate::Result>, - total_input_size: u64, + unpack_fn: impl FnOnce(&Path) -> crate::Result>, output_dir: &Path, output_file_path: &Path, question_policy: QuestionPolicy, @@ -195,12 +181,7 @@ fn smart_unpack( nice_directory_display(temp_dir_path) ); - // unpack the files - let files = if is_running_in_accessible_mode() { - unpack_fn(temp_dir_path, &mut io::stderr()) - } else { - unpack_fn(temp_dir_path, &mut Progress::new(total_input_size, true, false)) - }?; + let files = unpack_fn(temp_dir_path)?; let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.count() == 1; if root_contains_only_one_element { @@ -237,5 +218,6 @@ fn smart_unpack( nice_directory_display(output_file_path) ); } + Ok(ControlFlow::Continue(files)) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index a658103..cbab242 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -17,7 +17,6 @@ use crate::{ extension::{self, flatten_compression_formats, Extension, SUPPORTED_EXTENSIONS}, info, list::ListOptions, - progress::OutputLine, utils::{ self, dir_is_empty, pretty_format_list_of_paths, to_utf, try_infer_extension, user_wants_to_continue, FileVisibilityPolicy, diff --git a/src/error.rs b/src/error.rs index 7d3fddf..395bd2b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,8 +7,6 @@ use std::{ fmt::{self, Display}, }; -use indicatif::style::TemplateError; - use crate::{accessible::is_running_in_accessible_mode, utils::colors::*}; /// All errors that can be generated by `ouch` @@ -32,8 +30,6 @@ pub enum Error { CompressingRootFolder, /// Specialized walkdir's io::Error wrapper with additional information on the error WalkdirError { reason: String }, - /// TemplateError from - TemplateError(TemplateError), /// Custom and unique errors are reported in this variant Custom { reason: FinalError }, } @@ -139,9 +135,6 @@ impl fmt::Display for Error { FinalError::with_title(error_title.to_string()).detail("Permission denied") } Error::UnsupportedZipArchive(reason) => FinalError::with_title("Unsupported zip archive").detail(*reason), - Error::TemplateError(reason) => { - FinalError::with_title(reason.to_string()).detail("Progress bar template error") - } Error::Custom { reason } => reason.clone(), }; diff --git a/src/list.rs b/src/list.rs index 1bce0dc..8bed90a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -2,8 +2,6 @@ use std::path::{Path, PathBuf}; -use indicatif::{ProgressBar, ProgressStyle}; - use self::tree::Tree; use crate::accessible::is_running_in_accessible_mode; @@ -34,27 +32,13 @@ pub fn list_files( println!("Archive: {}", archive.display()); if list_options.tree { - let pb = if !is_running_in_accessible_mode() { - let template = "{wide_msg} [{elapsed_precise}] {spinner:.green}"; - let style = ProgressStyle::with_template(template).map_err(crate::Error::TemplateError)?; - Some(ProgressBar::new_spinner().with_style(style)) - } else { - None - }; - let tree: Tree = files .into_iter() .map(|file| { let file = file?; - if !is_running_in_accessible_mode() { - pb.as_ref() - .expect("exists") - .set_message(format!("Processing: {}", file.path.display())); - } Ok(file) }) .collect::>()?; - drop(pb); tree.print(); } else { for file in files { diff --git a/src/macros.rs b/src/macros.rs index e717088..338ece7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,8 +1,6 @@ //! Macros used on ouch. -use crate::accessible::is_running_in_accessible_mode; - -/// Macro that prints \[INFO\] messages, wraps [`println`]. +/// Macro that prints \[INFO\] messages, wraps [`eprintln`]. /// /// There are essentially two different versions of the `info!()` macro: /// - `info!(accessible, ...)` should only be used for short, important @@ -16,58 +14,45 @@ use crate::accessible::is_running_in_accessible_mode; /// while it would generate long and hard to navigate text for blind people /// who have to have each line of output read to them aloud, whithout to /// ability to skip some lines deemed not important like a seeing person would. -/// -/// By default `info` outputs to Stdout, if you want to specify the output you can use -/// `@log_out` modifier - #[macro_export] macro_rules! info { // Accessible (short/important) info message. // Show info message even in ACCESSIBLE mode - (accessible, $($arg:tt)*) => { - info!(@::std::io::stderr(), accessible, $($arg)*); - }; - (@$log_out: expr, accessible, $($arg:tt)*) => {{ - // if in ACCESSIBLE mode, suppress the "[INFO]" and just print the message - if !$crate::accessible::is_running_in_accessible_mode() { - $log_out.output_line_info(format_args!($($arg)*)); + (accessible, $($arg:tt)*) => {{ + use $crate::utils::colors::{YELLOW, RESET}; + + if $crate::accessible::is_running_in_accessible_mode() { + eprint!("{}Info:{} ", *YELLOW, *RESET); } else { - $log_out.output_line(format_args!($($arg)*)); + eprint!("{}[INFO]{} ", *YELLOW, *RESET); } + + eprintln!($($arg)*); }}; // Inccessible (long/no important) info message. // Print info message if ACCESSIBLE is not turned on - (inaccessible, $($arg:tt)*) => { - info!(@::std::io::stderr(), inaccessible, $($arg)*); - }; - (@$log_out: expr, inaccessible, $($arg:tt)*) => {{ + (inaccessible, $($arg:tt)*) => {{ + use $crate::utils::colors::{YELLOW, RESET}; + if !$crate::accessible::is_running_in_accessible_mode() { - $log_out.output_line_info(format_args!($($arg)*)); + eprint!("{}[INFO]{} ", *YELLOW, *RESET); + eprintln!($($arg)*); } }}; } -/// Macro that prints \[WARNING\] messages, wraps [`eprintln`]. +/// Macro that prints WARNING messages, wraps [`eprintln`]. #[macro_export] macro_rules! warning { - (@$log_out: expr, $($arg:tt)*) => { - if !$crate::accessible::is_running_in_accessible_mode() { - $log_out.output_line_warning(format_args!($($arg)*)); + ($($arg:tt)*) => {{ + use $crate::utils::colors::{ORANGE, RESET}; + + if $crate::accessible::is_running_in_accessible_mode() { + eprint!("{}Warning:{} ", *ORANGE, *RESET); + } else { + eprint!("{}[WARNING]{} ", *ORANGE, *RESET); } - }; - ($($arg:tt)*) => { - $crate::macros::_warning_helper(); + eprintln!($($arg)*); - }; -} - -/// Helper to display "\[WARNING\]", colored orange -pub fn _warning_helper() { - use crate::utils::colors::{ORANGE, RESET}; - - if is_running_in_accessible_mode() { - eprint!("{}Warning:{} ", *ORANGE, *RESET); - } else { - eprint!("{}[WARNING]{} ", *ORANGE, *RESET); - } + }}; } diff --git a/src/main.rs b/src/main.rs index cdc2a81..7abb4f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ pub mod commands; pub mod error; pub mod extension; pub mod list; -pub mod progress; pub mod utils; /// CLI argparsing definitions, using `clap`. diff --git a/src/progress.rs b/src/progress.rs deleted file mode 100644 index 2ffabcf..0000000 --- a/src/progress.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! Module that provides functions to display progress bars for compressing and decompressing files. -use std::{ - fmt::Arguments, - io::{Read, Stderr, Write}, -}; - -use indicatif::{ProgressBar, ProgressBarIter, ProgressStyle}; - -use crate::utils::colors::{ORANGE, RESET, YELLOW}; - -/// Draw a ProgressBar using a function that checks periodically for the progress -pub struct Progress { - bar: ProgressBar, -} - -pub trait OutputLine { - fn output_line(&mut self, args: Arguments); - fn output_line_info(&mut self, args: Arguments); - fn output_line_warning(&mut self, args: Arguments); -} - -impl OutputLine for Progress { - fn output_line(&mut self, args: Arguments) { - self.bar.set_message(args.to_string()); - } - - fn output_line_info(&mut self, args: Arguments) { - self.bar.set_message(format!("{}[INFO]{} {args}", *YELLOW, *RESET)); - } - - fn output_line_warning(&mut self, args: Arguments) { - self.bar.println(format!("{}[WARNING]{} {args}", *ORANGE, *RESET)); - } -} - -impl OutputLine for Stderr { - fn output_line(&mut self, args: Arguments) { - self.write_fmt(args).unwrap(); - } - - fn output_line_info(&mut self, args: Arguments) { - write!(self, "{}[INFO]{} ", *YELLOW, *RESET).unwrap(); - self.write_fmt(args).unwrap(); - self.write_all(b"\n").unwrap(); - } - - fn output_line_warning(&mut self, args: Arguments) { - write!(self, "{}[WARNING]{}", *ORANGE, *RESET).unwrap(); - self.write_fmt(args).unwrap(); - self.write_all(b"\n").unwrap(); - } -} - -impl OutputLine for &mut T { - fn output_line(&mut self, args: Arguments) { - (*self).output_line(args) - } - - fn output_line_info(&mut self, args: Arguments) { - (*self).output_line_info(args); - } - - fn output_line_warning(&mut self, args: Arguments) { - (*self).output_line_warning(args); - } -} - -impl Progress { - pub(crate) fn new(total_input_size: u64, precise: bool, position_updates: bool) -> Self { - let template = { - let mut t = String::new(); - t += "{wide_msg} [{elapsed_precise}] "; - if precise && position_updates { - t += "[{bar:.cyan/blue}] "; - } else { - t += "{spinner:.green} "; - } - if position_updates { - t += "{bytes}/ "; - } - if precise { - t += "{total_bytes} "; - } - t += "({bytes_per_sec}, {eta}) {path}"; - t - }; - let bar = ProgressBar::new(total_input_size) - .with_style(ProgressStyle::with_template(&template).unwrap().progress_chars("#>-")); - - Progress { bar } - } - - pub(crate) fn wrap_read(&self, read: R) -> ProgressBarIter { - self.bar.wrap_read(read) - } - - pub(crate) fn wrap_write(&self, write: W) -> ProgressBarIter { - self.bar.wrap_write(write) - } -} diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 6f6f1f1..4779549 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -10,7 +10,7 @@ use std::{ use fs_err as fs; use super::{to_utf, user_wants_to_overwrite}; -use crate::{extension::Extension, info, progress::OutputLine, QuestionPolicy}; +use crate::{extension::Extension, info, QuestionPolicy}; /// Checks if given path points to an empty directory. pub fn dir_is_empty(dir_path: &Path) -> bool {