fix: Use BufWriter for list output

Also replaces one `print` call with `write`.

Fixes #702
This commit is contained in:
Pascal Hertleif 2025-02-12 13:53:49 +01:00 committed by João Marcos
parent 28d0933d6c
commit aeefa694bf
2 changed files with 6 additions and 5 deletions

View File

@ -41,6 +41,7 @@ Categories Used:
- Fix logging IO bottleneck [\#642](https://github.com/ouch-org/ouch/pull/642) ([AntoniosBarotsis](https://github.com/AntoniosBarotsis))
- Support decompression over stdin [\#692](https://github.com/ouch-org/ouch/pull/692) ([rcorre](https://github.com/rcorre))
- Make `--format` more forgiving with the formatting of the provided format [\#519](https://github.com/ouch-org/ouch/pull/519) ([marcospb19](https://github.com/marcospb19))
- Use buffered writer for list output [\#764](https://github.com/ouch-org/ouch/pull/764) ([killercup](https://github.com/killercup))
## [0.5.1](https://github.com/ouch-org/ouch/compare/0.5.0...0.5.1)

View File

@ -1,7 +1,7 @@
//! Some implementation helpers related to the 'list' command.
use std::{
io::{stdout, Write},
io::{stdout, BufWriter, Write},
path::{Path, PathBuf},
};
@ -32,16 +32,16 @@ pub fn list_files(
files: impl IntoIterator<Item = crate::Result<FileInArchive>>,
list_options: ListOptions,
) -> crate::Result<()> {
let out = &mut stdout().lock();
let mut out = BufWriter::new(stdout().lock());
let _ = writeln!(out, "Archive: {}", EscapedPathDisplay::new(archive));
if list_options.tree {
let tree = files.into_iter().collect::<crate::Result<Tree>>()?;
tree.print(out);
tree.print(&mut out);
} else {
for file in files {
let FileInArchive { path, is_dir } = file?;
print_entry(out, EscapedPathDisplay::new(&path), is_dir);
print_entry(&mut out, EscapedPathDisplay::new(&path), is_dir);
}
}
Ok(())
@ -143,7 +143,7 @@ mod tree {
false => draw::FINAL_BRANCH,
};
print!("{prefix}{final_part}");
let _ = write!(out, "{prefix}{final_part}");
let is_dir = match self.file {
Some(FileInArchive { is_dir, .. }) => is_dir,
None => true,