diff --git a/yazi-config/preset/yazi-default.toml b/yazi-config/preset/yazi-default.toml index 12100e71..8d6e7a52 100644 --- a/yazi-config/preset/yazi-default.toml +++ b/yazi-config/preset/yazi-default.toml @@ -212,6 +212,11 @@ quit_content = "The following tasks are still running, are you sure you want to quit_origin = "center" quit_offset = [ 0, 0, 50, 15 ] +# bulk rename +bulk_rename_title = "Rename {n} file{s}?" +bulk_rename_origin = "center" +bulk_rename_offset = [0, 0, 70, 30] + [pick] open_title = "Open with:" open_origin = "hovered" diff --git a/yazi-config/src/popup/confirm.rs b/yazi-config/src/popup/confirm.rs index 703102b2..3e86fddc 100644 --- a/yazi-config/src/popup/confirm.rs +++ b/yazi-config/src/popup/confirm.rs @@ -26,6 +26,10 @@ pub struct Confirm { pub quit_content: String, pub quit_origin: Origin, pub quit_offset: Offset, + // bulk rename + pub bulk_rename_title: String, + pub bulk_rename_origin: Origin, + pub bulk_rename_offset: Offset, } impl Confirm { diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index b27d0c65..72b0777a 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use ratatui::{text::{Line, Text}, widgets::{Paragraph, Wrap}}; use yazi_shared::url::Url; @@ -154,6 +156,19 @@ impl ConfirmCfg { ) } + pub fn bulk_rename(todo: &[(PathBuf, PathBuf)]) -> Self { + let count = todo.len(); + + Self::new( + Self::replace_number(&YAZI.confirm.bulk_rename_title, count), + (YAZI.confirm.bulk_rename_origin, YAZI.confirm.bulk_rename_offset), + None, + Some(Text::from_iter( + todo.iter().map(|(old, new)| format!("{} -> {}", old.display(), new.display())), + )), + ) + } + fn replace_number(tpl: &str, n: usize) -> String { tpl.replace("{n}", &n.to_string()).replace("{s}", if n > 1 { "s" } else { "" }) } diff --git a/yazi-core/src/mgr/commands/bulk_rename.rs b/yazi-core/src/mgr/commands/bulk_rename.rs index f70c1a70..b8c7ff69 100644 --- a/yazi-core/src/mgr/commands/bulk_rename.rs +++ b/yazi-core/src/mgr/commands/bulk_rename.rs @@ -44,8 +44,6 @@ impl Mgr { .await; let _permit = HIDER.acquire().await.unwrap(); - defer!(AppProxy::resume()); - AppProxy::stop().await; let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().take(old.len()).map(PathBuf::from).collect(); @@ -70,18 +68,7 @@ impl Mgr { return Ok(()); } - { - let mut w = TTY.lockout(); - for (old, new) in &todo { - writeln!(w, "{} -> {}", old.display(), new.display())?; - } - write!(w, "Continue to rename? (y/N): ")?; - w.flush()?; - } - - let mut buf = [0; 10]; - _ = TTY.reader().read(&mut buf)?; - if buf[0] != b'y' && buf[0] != b'Y' { + if !ConfirmProxy::show(ConfirmCfg::bulk_rename(&todo)).await { return Ok(()); } diff --git a/yazi-fm/src/app/commands/render.rs b/yazi-fm/src/app/commands/render.rs index b0382de7..da5ba3ac 100644 --- a/yazi-fm/src/app/commands/render.rs +++ b/yazi-fm/src/app/commands/render.rs @@ -79,12 +79,11 @@ impl App { fn routine(push: bool, cursor: Option<(Position, SetCursorStyle)>) { static COUNT: AtomicU8 = AtomicU8::new(0); - if push && COUNT.fetch_add(1, Ordering::Relaxed) != 0 { - return; - } else if !push && COUNT.fetch_sub(1, Ordering::Relaxed) != 1 { + if (push && COUNT.fetch_add(1, Ordering::Relaxed) != 0) + || (!push && COUNT.fetch_sub(1, Ordering::Relaxed) != 1) + { return; } - _ = if push { queue!(TTY.writer(), BeginSynchronizedUpdate) } else if let Some((Position { x, y }, shape)) = cursor {