mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Working through replacing quit/overwrite Input with Confirm popup
This commit is contained in:
parent
e9c9daf33d
commit
373d452451
7 changed files with 75 additions and 57 deletions
|
|
@ -167,27 +167,30 @@ shell_title = [ "Shell:", "Shell (block):" ]
|
|||
shell_origin = "top-center"
|
||||
shell_offset = [ 0, 2, 50, 3 ]
|
||||
|
||||
# overwrite
|
||||
overwrite_title = "Overwrite an existing file? (y/N)"
|
||||
overwrite_origin = "top-center"
|
||||
overwrite_offset = [ 0, 2, 50, 3 ]
|
||||
|
||||
# quit
|
||||
quit_title = "{n} task{s} running, sure to quit? (y/N)"
|
||||
quit_origin = "top-center"
|
||||
quit_offset = [ 0, 2, 50, 3 ]
|
||||
|
||||
[confirm]
|
||||
# trash
|
||||
trash_title = "Move {n} selected file{s} to trash? (y/N)"
|
||||
trash_title = "Move {n} selected file{s} to trash?"
|
||||
trash_origin = "top-center"
|
||||
trash_offset = [ 0, 5, 70, 20 ]
|
||||
|
||||
# delete
|
||||
delete_title = "Delete {n} selected file{s} permanently? (y/N)"
|
||||
delete_title = "Delete {n} selected file{s} permanently?"
|
||||
delete_origin = "top-center"
|
||||
delete_offset = [ 0, 5, 70, 20 ]
|
||||
|
||||
# overwrite
|
||||
overwrite_title = "Are you sure?"
|
||||
overwrite_message = "Overwrite existing file: {file}?"
|
||||
overwrite_origin = "top-center"
|
||||
overwrite_offset = [ 0, 2, 50, 20 ]
|
||||
|
||||
# quit
|
||||
quit_title = "Are you sure you want to quit?"
|
||||
quit_message = "The following tasks are running:\n"
|
||||
quit_origin = "top-center"
|
||||
quit_offset = [ 0, 2, 50, 20 ]
|
||||
|
||||
|
||||
[select]
|
||||
open_title = "Open with:"
|
||||
open_origin = "hovered"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,18 @@ pub struct Confirm {
|
|||
pub delete_title: String,
|
||||
pub delete_origin: Origin,
|
||||
pub delete_offset: Offset,
|
||||
|
||||
// overwrite
|
||||
pub overwrite_title: String,
|
||||
pub overwrite_message: String,
|
||||
pub overwrite_origin: Origin,
|
||||
pub overwrite_offset: Offset,
|
||||
|
||||
// quit
|
||||
pub quit_title: String,
|
||||
pub quit_message: String,
|
||||
pub quit_origin: Origin,
|
||||
pub quit_offset: Offset,
|
||||
}
|
||||
|
||||
impl FromStr for Confirm {
|
||||
|
|
|
|||
|
|
@ -42,16 +42,6 @@ pub struct Input {
|
|||
pub shell_title: [String; 2],
|
||||
pub shell_origin: Origin,
|
||||
pub shell_offset: Offset,
|
||||
|
||||
// overwrite
|
||||
pub overwrite_title: String,
|
||||
pub overwrite_origin: Origin,
|
||||
pub overwrite_offset: Offset,
|
||||
|
||||
// quit
|
||||
pub quit_title: String,
|
||||
pub quit_origin: Origin,
|
||||
pub quit_offset: Offset,
|
||||
}
|
||||
|
||||
impl Input {
|
||||
|
|
|
|||
|
|
@ -94,25 +94,6 @@ impl InputCfg {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn overwrite() -> Self {
|
||||
Self {
|
||||
title: INPUT.overwrite_title.to_owned(),
|
||||
position: Position::new(INPUT.overwrite_origin, INPUT.overwrite_offset),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn quit(n: usize) -> Self {
|
||||
let title = INPUT.quit_title.replace("{n}", &n.to_string());
|
||||
Self {
|
||||
title: title.replace("{s}", if n > 1 { "s" } else { "" }),
|
||||
position: Position::new(INPUT.quit_origin, INPUT.quit_offset),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn with_value(mut self, value: impl Into<String>) -> Self {
|
||||
self.value = value.into();
|
||||
|
|
@ -144,6 +125,29 @@ impl ConfirmCfg {
|
|||
message: targets.iter().map(|t| t.to_string()).collect::<Vec<_>>().join("\n"),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn overwrite(file: &str) -> Self {
|
||||
Self {
|
||||
title: CONFIRM.overwrite_title.to_owned(),
|
||||
message: CONFIRM.overwrite_message.replace("{file}", file),
|
||||
position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn quit(ongoing_task_names: Vec<String>) -> Self {
|
||||
let n = ongoing_task_names.len();
|
||||
let mut message = CONFIRM.quit_message.replace("{n}", &n.to_string());
|
||||
|
||||
message.push_str(&ongoing_task_names.join("\n"));
|
||||
|
||||
Self {
|
||||
title: CONFIRM.quit_title.to_owned(),
|
||||
message,
|
||||
position: Position::new(CONFIRM.quit_origin, CONFIRM.quit_offset),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SelectCfg {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use std::collections::HashMap;
|
|||
|
||||
use anyhow::Result;
|
||||
use tokio::fs;
|
||||
use yazi_config::popup::InputCfg;
|
||||
use yazi_proxy::{InputProxy, TabProxy, WATCHER};
|
||||
use yazi_config::popup::{ConfirmCfg, InputCfg};
|
||||
use yazi_proxy::{ConfirmProxy, InputProxy, TabProxy, WATCHER};
|
||||
use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}};
|
||||
|
||||
use crate::manager::Manager;
|
||||
|
|
@ -32,8 +32,8 @@ impl Manager {
|
|||
|
||||
let new = cwd.join(&name);
|
||||
if !opt.force && maybe_exists(&new).await {
|
||||
match InputProxy::show(InputCfg::overwrite()).recv().await {
|
||||
Some(Ok(c)) if c == "y" || c == "Y" => (),
|
||||
match ConfirmProxy::show(ConfirmCfg::overwrite(&new.to_string())).await {
|
||||
Ok(c) if c => (),
|
||||
_ => return Ok(()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::time::Duration;
|
||||
use std::{future::Future, time::Duration};
|
||||
|
||||
use tokio::{select, time};
|
||||
use yazi_config::popup::InputCfg;
|
||||
use yazi_proxy::InputProxy;
|
||||
use yazi_config::popup::ConfirmCfg;
|
||||
use yazi_proxy::ConfirmProxy;
|
||||
use yazi_shared::{emit, event::{Cmd, EventQuit}};
|
||||
|
||||
use crate::{manager::Manager, tasks::Tasks};
|
||||
|
|
@ -18,6 +18,10 @@ impl From<Cmd> for Opt {
|
|||
fn from(c: Cmd) -> Self { Self { no_cwd_file: c.bool("no-cwd-file") } }
|
||||
}
|
||||
|
||||
// async fn recv(result: &mut impl Future<Output = anyhow::Result<bool>>) ->
|
||||
// anyhow::Result<bool> { result
|
||||
//}
|
||||
|
||||
impl Manager {
|
||||
pub fn quit(&self, opt: impl Into<Opt>, tasks: &Tasks) {
|
||||
let opt = EventQuit { no_cwd_file: opt.into().no_cwd_file, ..Default::default() };
|
||||
|
|
@ -32,7 +36,9 @@ impl Manager {
|
|||
|
||||
tokio::spawn(async move {
|
||||
let mut i = 0;
|
||||
let mut result = InputProxy::show(InputCfg::quit(left));
|
||||
let result = ConfirmProxy::show(ConfirmCfg::quit(
|
||||
ongoing.lock().values().map(|t| t.name.clone()).collect(),
|
||||
));
|
||||
loop {
|
||||
select! {
|
||||
_ = time::sleep(Duration::from_millis(100)) => {
|
||||
|
|
@ -43,17 +49,13 @@ impl Manager {
|
|||
return;
|
||||
}
|
||||
}
|
||||
choice = result.recv() => {
|
||||
if matches!(choice, Some(Ok(s)) if s == "y" || s == "Y") {
|
||||
emit!(Quit(opt));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(Ok(choice)) = result.recv().await {
|
||||
if choice == "y" || choice == "Y" {
|
||||
// recv(&mut result);
|
||||
|
||||
if let Ok(choice) = result.await {
|
||||
if choice {
|
||||
emit!(Quit(opt));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,11 @@ impl ConfirmProxy {
|
|||
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));
|
||||
rx.await?
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn show_sync(cfg: ConfirmCfg) -> oneshot::Receiver<bool> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));
|
||||
rx
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue