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`.
/// 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);
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
info!(
@out,
@log_out,
inaccessible,
"{:?} extracted. ({})",
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],
writer: W,
file_visibility_policy: FileVisibilityPolicy,
mut out: D,
mut log_out: D,
) -> crate::Result<W>
where
W: Write,
@ -104,7 +108,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!(@out, inaccessible, "Compressing '{}'.", utils::to_utf(path));
info!(@log_out, inaccessible, "Compressing '{}'.", utils::to_utf(path));
if path.is_dir() {
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`.
/// 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
R: Read + Seek,
D: Write,
@ -53,7 +57,7 @@ where
// importance for most users, but would generate lots of
// spoken text for users using screen readers, braille displays
// 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)?;
}
_is_file @ false => {
@ -66,7 +70,7 @@ where
// same reason is in _is_dir: long, often not needed text
info!(
@out,
@log_out,
inaccessible,
"{:?} extracted. ({})",
file_path.display(), Bytes::new(file.size())
@ -133,7 +137,7 @@ pub fn build_archive_from_paths<W, D>(
input_filenames: &[PathBuf],
writer: W,
file_visibility_policy: FileVisibilityPolicy,
mut out: D,
mut log_out: D,
) -> crate::Result<W>
where
W: Write + Seek,
@ -173,7 +177,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!(@out, inaccessible, "Compressing '{}'.", to_utf(path));
info!(@log_out, inaccessible, "Compressing '{}'.", to_utf(path));
let metadata = match path.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.
///
/// By default `info` outputs to Stdout, if you want to specify the output you can use
/// `@out` modifier
/// `@log_out` modifier
#[macro_export]
macro_rules! info {
@ -27,24 +27,24 @@ macro_rules! info {
(accessible, $($arg:tt)*) => {
info!(@::std::io::stdout(), accessible, $($arg)*);
};
(@$out: expr, accessible, $($arg:tt)*) => {
let out = &mut $out;
(@$log_out: expr, accessible, $($arg:tt)*) => {
let log_out = &mut $log_out;
// if in ACCESSIBLE mode, suppress the "[INFO]" and just print the message
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.
// Print info message if ACCESSIBLE is not turned on
(inaccessible, $($arg:tt)*) => {
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() {
let out = &mut $out;
$crate::macros::_info_helper(out);
writeln!(out, $($arg)*).unwrap();
let log_out = &mut $log_out;
$crate::macros::_info_helper(log_out);
writeln!(log_out, $($arg)*).unwrap();
}
};
}