mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
small refactor and renamings
This commit is contained in:
parent
8bd78f49cd
commit
4d518b7056
@ -45,7 +45,7 @@ where
|
||||
|
||||
let file_path = output_folder.join(file_path);
|
||||
|
||||
check_for_comments(&file);
|
||||
display_zip_comment_if_exists(&file);
|
||||
|
||||
match (&*file.name()).ends_with('/') {
|
||||
_is_dir @ true => {
|
||||
@ -191,7 +191,7 @@ where
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
fn check_for_comments(file: &ZipFile) {
|
||||
fn display_zip_comment_if_exists(file: &ZipFile) {
|
||||
let comment = file.comment();
|
||||
if !comment.is_empty() {
|
||||
// Zip file comments seem to be pretty rare, but if they are used,
|
||||
|
@ -97,8 +97,7 @@ pub fn decompress_file(
|
||||
reader = chain_reader_decoder(format, reader)?;
|
||||
}
|
||||
|
||||
let files_unpacked;
|
||||
match formats[0].compression_formats[0] {
|
||||
let files_unpacked = match formats[0].compression_formats[0] {
|
||||
Gzip | Bzip | Lz4 | Lzma | Snappy | Zstd => {
|
||||
reader = chain_reader_decoder(&formats[0].compression_formats[0], reader)?;
|
||||
|
||||
@ -116,10 +115,10 @@ pub fn decompress_file(
|
||||
let _progress = Progress::new_accessible_aware(total_input_size, true, Some(current_position_fn));
|
||||
|
||||
io::copy(&mut reader, &mut writer)?;
|
||||
files_unpacked = vec![output_file_path];
|
||||
vec![output_file_path]
|
||||
}
|
||||
Tar => {
|
||||
files_unpacked = if let ControlFlow::Continue(files) = smart_unpack(
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
Box::new(move |output_dir| {
|
||||
let mut progress = Progress::new_accessible_aware(total_input_size, true, None);
|
||||
crate::archive::tar::unpack_archive(
|
||||
@ -135,7 +134,7 @@ pub fn decompress_file(
|
||||
files
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
}
|
||||
}
|
||||
Zip => {
|
||||
if formats.len() > 1 {
|
||||
@ -151,7 +150,7 @@ pub fn decompress_file(
|
||||
io::copy(&mut reader, &mut vec)?;
|
||||
let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?;
|
||||
|
||||
files_unpacked = if let ControlFlow::Continue(files) = smart_unpack(
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
Box::new(move |output_dir| {
|
||||
let mut progress = Progress::new_accessible_aware(total_input_size, true, None);
|
||||
crate::archive::zip::unpack_archive(
|
||||
@ -167,9 +166,9 @@ pub fn decompress_file(
|
||||
files
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// this is only printed once, so it doesn't result in much text. On the other hand,
|
||||
// having a final status message is important especially in an accessibility context
|
||||
|
@ -23,9 +23,9 @@ impl PartialEq for Extension {
|
||||
impl Extension {
|
||||
/// # Panics:
|
||||
/// Will panic if `formats` is empty
|
||||
pub fn new(formats: &'static [CompressionFormat], text: impl Into<String>) -> Self {
|
||||
pub fn new(formats: &'static [CompressionFormat], text: impl ToString) -> Self {
|
||||
assert!(!formats.is_empty());
|
||||
Self { compression_formats: formats, display_text: text.into() }
|
||||
Self { compression_formats: formats, display_text: text.to_string() }
|
||||
}
|
||||
|
||||
/// Checks if the first format in `compression_formats` is an archive
|
||||
|
@ -78,21 +78,21 @@ impl Progress {
|
||||
t += "({bytes_per_sec}, {eta}) {path}";
|
||||
t
|
||||
};
|
||||
let pb = ProgressBar::new(total_input_size);
|
||||
pb.set_style(ProgressStyle::default_bar().template(&template).progress_chars("#>-"));
|
||||
let bar = ProgressBar::new(total_input_size);
|
||||
bar.set_style(ProgressStyle::default_bar().template(&template).progress_chars("#>-"));
|
||||
|
||||
while draw_rx.try_recv().is_err() {
|
||||
if let Some(ref pos_fn) = current_position_fn {
|
||||
pb.set_position(pos_fn());
|
||||
bar.set_position(pos_fn());
|
||||
} else {
|
||||
pb.tick();
|
||||
bar.tick();
|
||||
}
|
||||
if let Ok(msg) = msg_rx.try_recv() {
|
||||
pb.set_message(msg);
|
||||
bar.set_message(msg);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
pb.finish();
|
||||
bar.finish();
|
||||
let _ = clean_tx.send(());
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user