mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fine-grained stdout
This commit is contained in:
parent
789e955bd9
commit
ec790dcad2
1 changed files with 23 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, ffi::OsStr, io::{stdout, Write}, mem, os::unix::prelude::OsStrExt, path::{Path, PathBuf}};
|
||||
use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, ffi::OsStr, io::{stdout, BufWriter, Write}, mem, os::unix::prelude::OsStrExt, path::{Path, PathBuf}};
|
||||
|
||||
use anyhow::{bail, Error, Result};
|
||||
use config::{open::Opener, BOOT, OPEN};
|
||||
|
|
@ -281,9 +281,15 @@ impl Manager {
|
|||
}
|
||||
if todo.is_empty() {
|
||||
return Ok(());
|
||||
} else {
|
||||
print!("Continue to rename? (y/N): ");
|
||||
stdout().flush()?;
|
||||
}
|
||||
// NOTE: it's worth using two iterations for finer-grained stdout control
|
||||
{
|
||||
let mut stdout = BufWriter::new(stdout().lock());
|
||||
for (o, n) in &todo {
|
||||
writeln!(stdout, "{o:?} -> {n:?}")?;
|
||||
}
|
||||
write!(stdout, "Continue to rename? (y/N): ")?;
|
||||
stdout.flush()?;
|
||||
}
|
||||
|
||||
let mut buf = [0];
|
||||
|
|
@ -294,23 +300,26 @@ impl Manager {
|
|||
|
||||
let mut failed = Vec::new();
|
||||
for (o, n) in todo {
|
||||
let (o, n) = root.as_ref().map(|root| (root.join(&o), root.join(&n))).unwrap_or((o, n));
|
||||
if let Err(e) = fs::rename(&o, &n).await {
|
||||
failed.push((o, n, e));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let mut stdout = BufWriter::new(stdout().lock());
|
||||
if !failed.is_empty() {
|
||||
Term::clear()?;
|
||||
println!("Failed to rename:");
|
||||
writeln!(stdout, "Failed to rename:")?;
|
||||
for (o, n, e) in failed {
|
||||
stdout().write_all(o.as_os_str().as_bytes())?;
|
||||
stdout().write_all(b" -> ")?;
|
||||
stdout().write_all(n.as_os_str().as_bytes())?;
|
||||
stdout().write_fmt(format_args!(": {e}\n"))?;
|
||||
writeln!(stdout, "{o:?} -> {n:?}: {e}")?;
|
||||
}
|
||||
write!(stdout, "\nPress ENTER to exit")?;
|
||||
stdout.flush()?;
|
||||
}
|
||||
}
|
||||
println!("\nPress ENTER to exit");
|
||||
tokio::io::stdin().read_exact(&mut [0]).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue