mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
confirm for bulk_rename
This commit is contained in:
parent
8ed569b729
commit
f46cd3f8ee
5 changed files with 28 additions and 18 deletions
|
|
@ -212,6 +212,11 @@ quit_content = "The following tasks are still running, are you sure you want to
|
||||||
quit_origin = "center"
|
quit_origin = "center"
|
||||||
quit_offset = [ 0, 0, 50, 15 ]
|
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]
|
[pick]
|
||||||
open_title = "Open with:"
|
open_title = "Open with:"
|
||||||
open_origin = "hovered"
|
open_origin = "hovered"
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ pub struct Confirm {
|
||||||
pub quit_content: String,
|
pub quit_content: String,
|
||||||
pub quit_origin: Origin,
|
pub quit_origin: Origin,
|
||||||
pub quit_offset: Offset,
|
pub quit_offset: Offset,
|
||||||
|
// bulk rename
|
||||||
|
pub bulk_rename_title: String,
|
||||||
|
pub bulk_rename_origin: Origin,
|
||||||
|
pub bulk_rename_offset: Offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Confirm {
|
impl Confirm {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use ratatui::{text::{Line, Text}, widgets::{Paragraph, Wrap}};
|
use ratatui::{text::{Line, Text}, widgets::{Paragraph, Wrap}};
|
||||||
use yazi_shared::url::Url;
|
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 {
|
fn replace_number(tpl: &str, n: usize) -> String {
|
||||||
tpl.replace("{n}", &n.to_string()).replace("{s}", if n > 1 { "s" } else { "" })
|
tpl.replace("{n}", &n.to_string()).replace("{s}", if n > 1 { "s" } else { "" })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,6 @@ impl Mgr {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let _permit = HIDER.acquire().await.unwrap();
|
let _permit = HIDER.acquire().await.unwrap();
|
||||||
defer!(AppProxy::resume());
|
|
||||||
AppProxy::stop().await;
|
|
||||||
|
|
||||||
let new: Vec<_> =
|
let new: Vec<_> =
|
||||||
fs::read_to_string(&tmp).await?.lines().take(old.len()).map(PathBuf::from).collect();
|
fs::read_to_string(&tmp).await?.lines().take(old.len()).map(PathBuf::from).collect();
|
||||||
|
|
@ -70,18 +68,7 @@ impl Mgr {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if !ConfirmProxy::show(ConfirmCfg::bulk_rename(&todo)).await {
|
||||||
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' {
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,12 +79,11 @@ impl App {
|
||||||
|
|
||||||
fn routine(push: bool, cursor: Option<(Position, SetCursorStyle)>) {
|
fn routine(push: bool, cursor: Option<(Position, SetCursorStyle)>) {
|
||||||
static COUNT: AtomicU8 = AtomicU8::new(0);
|
static COUNT: AtomicU8 = AtomicU8::new(0);
|
||||||
if push && COUNT.fetch_add(1, Ordering::Relaxed) != 0 {
|
if (push && COUNT.fetch_add(1, Ordering::Relaxed) != 0)
|
||||||
return;
|
|| (!push && COUNT.fetch_sub(1, Ordering::Relaxed) != 1)
|
||||||
} else if !push && COUNT.fetch_sub(1, Ordering::Relaxed) != 1 {
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = if push {
|
_ = if push {
|
||||||
queue!(TTY.writer(), BeginSynchronizedUpdate)
|
queue!(TTY.writer(), BeginSynchronizedUpdate)
|
||||||
} else if let Some((Position { x, y }, shape)) = cursor {
|
} else if let Some((Position { x, y }, shape)) = cursor {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue