mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
chore: change name and write nothing with no-cwd-file
This commit is contained in:
parent
98de71e6fe
commit
9c6fa4ec93
4 changed files with 22 additions and 21 deletions
|
|
@ -25,8 +25,8 @@ impl App {
|
||||||
|
|
||||||
while let Some(event) = app.signals.recv().await {
|
while let Some(event) = app.signals.recv().await {
|
||||||
match event {
|
match event {
|
||||||
Event::Quit(write_cwd_file) => {
|
Event::Quit(no_cwd_file) => {
|
||||||
app.dispatch_quit(write_cwd_file);
|
app.dispatch_quit(no_cwd_file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Event::Key(key) => app.dispatch_key(key),
|
Event::Key(key) => app.dispatch_key(key),
|
||||||
|
|
@ -41,19 +41,20 @@ impl App {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_quit(&mut self, write_cwd_file: bool) {
|
fn dispatch_quit(&mut self, no_cwd_file: bool) {
|
||||||
if let Some(p) = &BOOT.cwd_file {
|
if !no_cwd_file {
|
||||||
let cwd =
|
if let Some(p) = &BOOT.cwd_file {
|
||||||
if write_cwd_file { self.cx.manager.cwd().as_os_str() } else { &BOOT.cwd.as_os_str() };
|
let cwd = self.cx.manager.cwd().as_os_str();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok();
|
std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok();
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
std::fs::write(p, cwd.as_bytes()).ok();
|
std::fs::write(p, cwd.as_bytes()).ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ 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" => cx.manager.quit(&cx.tasks, !exec.named.contains_key("no-cwd-file")),
|
"quit" => cx.manager.quit(&cx.tasks, exec.named.contains_key("no-cwd-file")),
|
||||||
"close" => cx.manager.close(&cx.tasks),
|
"close" => cx.manager.close(&cx.tasks),
|
||||||
"suspend" => cx.manager.suspend(),
|
"suspend" => cx.manager.suspend(),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::manager::PreviewLock;
|
||||||
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Quit(bool), // write-cwd-file
|
Quit(bool), // no-cwd-file
|
||||||
Key(KeyEvent),
|
Key(KeyEvent),
|
||||||
Paste(String),
|
Paste(String),
|
||||||
Render(String),
|
Render(String),
|
||||||
|
|
@ -54,8 +54,8 @@ impl Event {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! emit {
|
macro_rules! emit {
|
||||||
(Quit($write_cwd_file:expr)) => {
|
(Quit($no_cwd_file:expr)) => {
|
||||||
$crate::Event::Quit($write_cwd_file).emit();
|
$crate::Event::Quit($no_cwd_file).emit();
|
||||||
};
|
};
|
||||||
(Key($key:expr)) => {
|
(Key($key:expr)) => {
|
||||||
$crate::Event::Key($key).emit();
|
$crate::Event::Key($key).emit();
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,10 @@ impl Manager {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn quit(&self, tasks: &Tasks, write_cwd_file: bool) -> bool {
|
pub fn quit(&self, tasks: &Tasks, no_cwd_file: bool) -> bool {
|
||||||
let tasks = tasks.len();
|
let tasks = tasks.len();
|
||||||
if tasks == 0 {
|
if tasks == 0 {
|
||||||
emit!(Quit(write_cwd_file));
|
emit!(Quit(no_cwd_file));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ impl Manager {
|
||||||
|
|
||||||
if let Some(Ok(choice)) = result.recv().await {
|
if let Some(Ok(choice)) = result.recv().await {
|
||||||
if choice == "y" || choice == "Y" {
|
if choice == "y" || choice == "Y" {
|
||||||
emit!(Quit(write_cwd_file));
|
emit!(Quit(no_cwd_file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue