mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: confirm on quitting
This commit is contained in:
parent
2279d95fab
commit
43ec2ada0b
4 changed files with 44 additions and 21 deletions
|
|
@ -3,7 +3,7 @@ use std::{collections::{BTreeSet, HashMap, HashSet}, mem, path::PathBuf};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use super::{PreviewData, Tab, Tabs, Watcher};
|
use super::{PreviewData, Tab, Tabs, Watcher};
|
||||||
use crate::{core::{files::{File, FilesOp}, input::{Input, InputOpt, InputPos}, manager::Folder, tasks::Precache}, emit};
|
use crate::{core::{files::{File, FilesOp}, input::{InputOpt, InputPos}, manager::Folder, tasks::{Precache, Tasks}}, emit};
|
||||||
|
|
||||||
pub struct Manager {
|
pub struct Manager {
|
||||||
tabs: Tabs,
|
tabs: Tabs,
|
||||||
|
|
@ -72,15 +72,6 @@ impl Manager {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self) -> bool {
|
|
||||||
if self.tabs.len() > 1 {
|
|
||||||
return self.tabs.close(self.tabs.idx());
|
|
||||||
}
|
|
||||||
|
|
||||||
emit!(Quit);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn yank(&mut self, cut: bool) -> bool {
|
pub fn yank(&mut self, cut: bool) -> bool {
|
||||||
self.yanked.0 = cut;
|
self.yanked.0 = cut;
|
||||||
self.yanked.1.clear();
|
self.yanked.1.clear();
|
||||||
|
|
@ -91,6 +82,37 @@ impl Manager {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn yanked(&self) -> &(bool, HashSet<PathBuf>) { &self.yanked }
|
pub fn yanked(&self) -> &(bool, HashSet<PathBuf>) { &self.yanked }
|
||||||
|
|
||||||
|
pub fn quit(&self, tasks: &Tasks) -> bool {
|
||||||
|
let tasks = tasks.len();
|
||||||
|
if tasks == 0 {
|
||||||
|
emit!(Quit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let result = emit!(Input(InputOpt {
|
||||||
|
title: format!("There are {} tasks running, sure to quit? (y/N)", tasks),
|
||||||
|
value: "".to_string(),
|
||||||
|
position: InputPos::Top,
|
||||||
|
}))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
if let Ok(choice) = result {
|
||||||
|
if choice.to_lowercase() == "y" {
|
||||||
|
emit!(Quit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn close(&mut self, tasks: &Tasks) -> bool {
|
||||||
|
if self.tabs.len() > 1 {
|
||||||
|
return self.tabs.close(self.tabs.idx());
|
||||||
|
}
|
||||||
|
self.quit(tasks)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create(&self) -> bool {
|
pub fn create(&self) -> bool {
|
||||||
let cwd = self.current().cwd.clone();
|
let cwd = self.current().cwd.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ use std::{collections::BTreeMap, mem, path::{Path, PathBuf}};
|
||||||
|
|
||||||
use anyhow::{Error, Result};
|
use anyhow::{Error, Result};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
use super::{Folder, Mode, Preview};
|
use super::{Folder, Mode, Preview};
|
||||||
use crate::{core::{external::{self, FzfOpt, ZoxideOpt}, files::{File, Files, FilesOp}, input::{Input, InputOpt, InputPos}, Event, BLOCKER}, emit, misc::Defer};
|
use crate::{core::{external::{self, FzfOpt, ZoxideOpt}, files::{File, Files, FilesOp}, input::{InputOpt, InputPos}, Event, BLOCKER}, emit, misc::Defer};
|
||||||
|
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
pub(super) current: Folder,
|
pub(super) current: Folder,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::{collections::{BTreeMap, HashSet}, path::PathBuf, sync::Arc};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{Scheduler, TASKS_PADDING, TASKS_PERCENT};
|
use super::{Scheduler, TASKS_PADDING, TASKS_PERCENT};
|
||||||
use crate::{config::OPEN, core::input::{Input, InputOpt, InputPos}, emit, misc::tty_size};
|
use crate::{config::OPEN, core::input::{InputOpt, InputPos}, emit, misc::tty_size};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
|
|
@ -71,7 +71,7 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> bool {
|
pub fn next(&mut self) -> bool {
|
||||||
let limit = Self::limit().min(self.scheduler.running.read().len());
|
let limit = Self::limit().min(self.len());
|
||||||
|
|
||||||
let old = self.cursor;
|
let old = self.cursor;
|
||||||
self.cursor = limit.saturating_sub(1).min(self.cursor + 1);
|
self.cursor = limit.saturating_sub(1).min(self.cursor + 1);
|
||||||
|
|
@ -151,7 +151,7 @@ impl Tasks {
|
||||||
let scheduler = self.scheduler.clone();
|
let scheduler = self.scheduler.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let result = emit!(Input(InputOpt {
|
let result = emit!(Input(InputOpt {
|
||||||
title: "Are you sure delete these files? (Y/n)".to_string(),
|
title: "Are you sure delete these files? (y/N)".to_string(),
|
||||||
value: "".to_string(),
|
value: "".to_string(),
|
||||||
position: InputPos::Hovered,
|
position: InputPos::Hovered,
|
||||||
}))
|
}))
|
||||||
|
|
@ -182,3 +182,8 @@ impl Tasks {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Tasks {
|
||||||
|
#[inline]
|
||||||
|
pub fn len(&self) -> usize { self.scheduler.running.read().len() }
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crossterm::event::KeyCode;
|
use crossterm::event::KeyCode;
|
||||||
|
|
||||||
use super::Ctx;
|
use super::Ctx;
|
||||||
use crate::{config::{keymap::{Exec, Key, Single}, KEYMAP}, core::input::InputMode, emit, misc::optinal_bool};
|
use crate::{config::{keymap::{Exec, Key, Single}, KEYMAP}, core::input::InputMode, misc::optinal_bool};
|
||||||
|
|
||||||
pub struct Executor;
|
pub struct Executor;
|
||||||
|
|
||||||
|
|
@ -45,11 +45,8 @@ impl Executor {
|
||||||
fn manager(cx: &mut Ctx, exec: &Exec) -> bool {
|
fn manager(cx: &mut Ctx, exec: &Exec) -> bool {
|
||||||
match exec.cmd.as_str() {
|
match exec.cmd.as_str() {
|
||||||
"escape" => cx.manager.active_mut().escape(),
|
"escape" => cx.manager.active_mut().escape(),
|
||||||
"quit" => {
|
"quit" => cx.manager.quit(&cx.tasks),
|
||||||
emit!(Quit);
|
"close" => cx.manager.close(&cx.tasks),
|
||||||
false
|
|
||||||
}
|
|
||||||
"close" => cx.manager.close(),
|
|
||||||
|
|
||||||
// Navigation
|
// Navigation
|
||||||
"arrow" => {
|
"arrow" => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue