Simplify the code

This commit is contained in:
sxyazi 2024-06-19 17:24:40 +08:00
parent dab892e77c
commit 3dc80e28c8
No known key found for this signature in database
5 changed files with 14 additions and 21 deletions

View file

@ -180,7 +180,7 @@ delete_offset = [ 0, 5, 70, 20 ]
# overwrite # overwrite
overwrite_title = "Are you sure?" overwrite_title = "Are you sure?"
overwrite_content = "Overwrite existing file: {file}?" overwrite_content = "Will overwrite existing file: {url}"
overwrite_origin = "top-center" overwrite_origin = "top-center"
overwrite_offset = [ 0, 2, 50, 20 ] overwrite_offset = [ 0, 2, 50, 20 ]

View file

@ -1,3 +1,5 @@
use yazi_shared::fs::Url;
use super::{Offset, Position}; use super::{Offset, Position};
use crate::{CONFIRM, INPUT, SELECT}; use crate::{CONFIRM, INPUT, SELECT};
@ -127,10 +129,10 @@ impl ConfirmCfg {
} }
#[inline] #[inline]
pub fn overwrite(file: &str) -> Self { pub fn overwrite(url: &Url) -> Self {
Self { Self {
title: CONFIRM.overwrite_title.to_owned(), 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), position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset),
} }
} }

View file

@ -31,11 +31,11 @@ impl Manager {
} }
let new = cwd.join(&name); let new = cwd.join(&name);
if !opt.force && maybe_exists(&new).await { if !opt.force
match ConfirmProxy::show(ConfirmCfg::overwrite(&new.to_string())).await { && maybe_exists(&new).await
Ok(c) if c => (), && !ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await
_ => return Ok(()), {
} return Ok(());
} }
Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await

View file

@ -52,13 +52,9 @@ impl Manager {
} }
} }
// recv(&mut result); if result.await {
if let Ok(choice) = result.await {
if choice {
emit!(Quit(opt)); emit!(Quit(opt));
} }
}
}); });
} }
} }

View file

@ -88,18 +88,13 @@ impl Utils {
ya.raw_set( ya.raw_set(
"confirm", "confirm",
lua.create_async_function(|lua, t: Table| async move { lua.create_async_function(|_, t: Table| async move {
let result = ConfirmProxy::show(ConfirmCfg { let result = ConfirmProxy::show(ConfirmCfg {
title: t.raw_get("title")?, title: t.raw_get("title")?,
content: t.raw_get("content")?, content: t.raw_get("content")?,
position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(), position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(),
}); });
Ok(result.await)
if let Ok(_answer) = result.await {
true.into_lua_multi(lua)
} else {
false.into_lua_multi(lua)
}
})?, })?,
)?; )?;