rename out to log_out

This commit is contained in:
figsoda 2022-10-13 10:27:04 -04:00
parent 759f322722
commit dd6ab2aa6e
3 changed files with 26 additions and 18 deletions

View File

@ -19,7 +19,11 @@ use crate::{
/// Unpacks the archive given by `archive` into the folder given by `into`. /// Unpacks the archive given by `archive` into the folder given by `into`.
/// Assumes that output_folder is empty /// Assumes that output_folder is empty
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, mut out: impl Write) -> crate::Result<Vec<PathBuf>> { pub fn unpack_archive(
reader: Box<dyn Read>,
output_folder: &Path,
mut log_out: impl Write,
) -> crate::Result<Vec<PathBuf>> {
assert!(output_folder.read_dir().expect("dir exists").count() == 0); assert!(output_folder.read_dir().expect("dir exists").count() == 0);
let mut archive = tar::Archive::new(reader); let mut archive = tar::Archive::new(reader);
@ -36,7 +40,7 @@ pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, mut out: impl
// and so on // and so on
info!( info!(
@out, @log_out,
inaccessible, inaccessible,
"{:?} extracted. ({})", "{:?} extracted. ({})",
utils::strip_cur_dir(&output_folder.join(file.path()?)), Bytes::new(file.size()) utils::strip_cur_dir(&output_folder.join(file.path()?)), Bytes::new(file.size())
@ -82,7 +86,7 @@ pub fn build_archive_from_paths<W, D>(
input_filenames: &[PathBuf], input_filenames: &[PathBuf],
writer: W, writer: W,
file_visibility_policy: FileVisibilityPolicy, file_visibility_policy: FileVisibilityPolicy,
mut out: D, mut log_out: D,
) -> crate::Result<W> ) -> crate::Result<W>
where where
W: Write, W: Write,
@ -104,7 +108,7 @@ where
// little importance for most users, but would generate lots of // little importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays // spoken text for users using screen readers, braille displays
// and so on // and so on
info!(@out, inaccessible, "Compressing '{}'.", utils::to_utf(path)); info!(@log_out, inaccessible, "Compressing '{}'.", utils::to_utf(path));
if path.is_dir() { if path.is_dir() {
builder.append_dir(path, path)?; builder.append_dir(path, path)?;

View File

@ -27,7 +27,11 @@ use crate::{
/// Unpacks the archive given by `archive` into the folder given by `output_folder`. /// Unpacks the archive given by `archive` into the folder given by `output_folder`.
/// Assumes that output_folder is empty /// Assumes that output_folder is empty
pub fn unpack_archive<R, D>(mut archive: ZipArchive<R>, output_folder: &Path, mut out: D) -> crate::Result<Vec<PathBuf>> pub fn unpack_archive<R, D>(
mut archive: ZipArchive<R>,
output_folder: &Path,
mut log_out: D,
) -> crate::Result<Vec<PathBuf>>
where where
R: Read + Seek, R: Read + Seek,
D: Write, D: Write,
@ -53,7 +57,7 @@ where
// importance for most users, but would generate lots of // importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays // spoken text for users using screen readers, braille displays
// and so on // and so on
info!(@out, inaccessible, "File {} extracted to \"{}\"", idx, file_path.display()); info!(@log_out, inaccessible, "File {} extracted to \"{}\"", idx, file_path.display());
fs::create_dir_all(&file_path)?; fs::create_dir_all(&file_path)?;
} }
_is_file @ false => { _is_file @ false => {
@ -66,7 +70,7 @@ where
// same reason is in _is_dir: long, often not needed text // same reason is in _is_dir: long, often not needed text
info!( info!(
@out, @log_out,
inaccessible, inaccessible,
"{:?} extracted. ({})", "{:?} extracted. ({})",
file_path.display(), Bytes::new(file.size()) file_path.display(), Bytes::new(file.size())
@ -133,7 +137,7 @@ pub fn build_archive_from_paths<W, D>(
input_filenames: &[PathBuf], input_filenames: &[PathBuf],
writer: W, writer: W,
file_visibility_policy: FileVisibilityPolicy, file_visibility_policy: FileVisibilityPolicy,
mut out: D, mut log_out: D,
) -> crate::Result<W> ) -> crate::Result<W>
where where
W: Write + Seek, W: Write + Seek,
@ -173,7 +177,7 @@ where
// little importance for most users, but would generate lots of // little importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays // spoken text for users using screen readers, braille displays
// and so on // and so on
info!(@out, inaccessible, "Compressing '{}'.", to_utf(path)); info!(@log_out, inaccessible, "Compressing '{}'.", to_utf(path));
let metadata = match path.metadata() { let metadata = match path.metadata() {
Ok(metadata) => metadata, Ok(metadata) => metadata,

View File

@ -18,7 +18,7 @@ use crate::accessible::is_running_in_accessible_mode;
/// ability to skip some lines deemed not important like a seeing person would. /// 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 /// By default `info` outputs to Stdout, if you want to specify the output you can use
/// `@out` modifier /// `@log_out` modifier
#[macro_export] #[macro_export]
macro_rules! info { macro_rules! info {
@ -27,24 +27,24 @@ macro_rules! info {
(accessible, $($arg:tt)*) => { (accessible, $($arg:tt)*) => {
info!(@::std::io::stdout(), accessible, $($arg)*); info!(@::std::io::stdout(), accessible, $($arg)*);
}; };
(@$out: expr, accessible, $($arg:tt)*) => { (@$log_out: expr, accessible, $($arg:tt)*) => {
let out = &mut $out; let log_out = &mut $log_out;
// if in ACCESSIBLE mode, suppress the "[INFO]" and just print the message // if in ACCESSIBLE mode, suppress the "[INFO]" and just print the message
if !$crate::accessible::is_running_in_accessible_mode() { if !$crate::accessible::is_running_in_accessible_mode() {
$crate::macros::_info_helper(out); $crate::macros::_info_helper(log_out);
} }
writeln!(out, $($arg)*).unwrap(); writeln!(log_out, $($arg)*).unwrap();
}; };
// Inccessible (long/no important) info message. // Inccessible (long/no important) info message.
// Print info message if ACCESSIBLE is not turned on // Print info message if ACCESSIBLE is not turned on
(inaccessible, $($arg:tt)*) => { (inaccessible, $($arg:tt)*) => {
info!(@::std::io::stdout(), inaccessible, $($arg)*); info!(@::std::io::stdout(), inaccessible, $($arg)*);
}; };
(@$out: expr, inaccessible, $($arg:tt)*) => { (@$log_out: expr, inaccessible, $($arg:tt)*) => {
if !$crate::accessible::is_running_in_accessible_mode() { if !$crate::accessible::is_running_in_accessible_mode() {
let out = &mut $out; let log_out = &mut $log_out;
$crate::macros::_info_helper(out); $crate::macros::_info_helper(log_out);
writeln!(out, $($arg)*).unwrap(); writeln!(log_out, $($arg)*).unwrap();
} }
}; };
} }