mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
dab892e77c
commit
3dc80e28c8
5 changed files with 14 additions and 21 deletions
|
|
@ -180,7 +180,7 @@ delete_offset = [ 0, 5, 70, 20 ]
|
|||
|
||||
# overwrite
|
||||
overwrite_title = "Are you sure?"
|
||||
overwrite_content = "Overwrite existing file: {file}?"
|
||||
overwrite_content = "Will overwrite existing file: {url}"
|
||||
overwrite_origin = "top-center"
|
||||
overwrite_offset = [ 0, 2, 50, 20 ]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use yazi_shared::fs::Url;
|
||||
|
||||
use super::{Offset, Position};
|
||||
use crate::{CONFIRM, INPUT, SELECT};
|
||||
|
||||
|
|
@ -127,10 +129,10 @@ impl ConfirmCfg {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn overwrite(file: &str) -> Self {
|
||||
pub fn overwrite(url: &Url) -> Self {
|
||||
Self {
|
||||
title: CONFIRM.overwrite_title.to_owned(),
|
||||
content: CONFIRM.overwrite_content.replace("{file}", file),
|
||||
content: CONFIRM.overwrite_content.replace("{url}", &url.to_string()),
|
||||
position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ impl Manager {
|
|||
}
|
||||
|
||||
let new = cwd.join(&name);
|
||||
if !opt.force && maybe_exists(&new).await {
|
||||
match ConfirmProxy::show(ConfirmCfg::overwrite(&new.to_string())).await {
|
||||
Ok(c) if c => (),
|
||||
_ => return Ok(()),
|
||||
}
|
||||
if !opt.force
|
||||
&& maybe_exists(&new).await
|
||||
&& !ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await
|
||||
|
|
|
|||
|
|
@ -52,12 +52,8 @@ impl Manager {
|
|||
}
|
||||
}
|
||||
|
||||
// recv(&mut result);
|
||||
|
||||
if let Ok(choice) = result.await {
|
||||
if choice {
|
||||
emit!(Quit(opt));
|
||||
}
|
||||
if result.await {
|
||||
emit!(Quit(opt));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,18 +88,13 @@ impl Utils {
|
|||
|
||||
ya.raw_set(
|
||||
"confirm",
|
||||
lua.create_async_function(|lua, t: Table| async move {
|
||||
lua.create_async_function(|_, t: Table| async move {
|
||||
let result = ConfirmProxy::show(ConfirmCfg {
|
||||
title: t.raw_get("title")?,
|
||||
content: t.raw_get("content")?,
|
||||
position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(),
|
||||
});
|
||||
|
||||
if let Ok(_answer) = result.await {
|
||||
true.into_lua_multi(lua)
|
||||
} else {
|
||||
false.into_lua_multi(lua)
|
||||
}
|
||||
Ok(result.await)
|
||||
})?,
|
||||
)?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue