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 {
|
||||
match event {
|
||||
Event::Quit(write_cwd_file) => {
|
||||
app.dispatch_quit(write_cwd_file);
|
||||
Event::Quit(no_cwd_file) => {
|
||||
app.dispatch_quit(no_cwd_file);
|
||||
break;
|
||||
}
|
||||
Event::Key(key) => app.dispatch_key(key),
|
||||
|
|
@ -41,19 +41,20 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn dispatch_quit(&mut self, write_cwd_file: bool) {
|
||||
if let Some(p) = &BOOT.cwd_file {
|
||||
let cwd =
|
||||
if write_cwd_file { self.cx.manager.cwd().as_os_str() } else { &BOOT.cwd.as_os_str() };
|
||||
fn dispatch_quit(&mut self, no_cwd_file: bool) {
|
||||
if !no_cwd_file {
|
||||
if let Some(p) = &BOOT.cwd_file {
|
||||
let cwd = self.cx.manager.cwd().as_os_str();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok();
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
std::fs::write(p, cwd.as_bytes()).ok();
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok();
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
std::fs::write(p, cwd.as_bytes()).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl Executor {
|
|||
fn manager(cx: &mut Ctx, exec: &Exec) -> bool {
|
||||
match exec.cmd.as_str() {
|
||||
"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),
|
||||
"suspend" => cx.manager.suspend(),
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::manager::PreviewLock;
|
|||
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
||||
|
||||
pub enum Event {
|
||||
Quit(bool), // write-cwd-file
|
||||
Quit(bool), // no-cwd-file
|
||||
Key(KeyEvent),
|
||||
Paste(String),
|
||||
Render(String),
|
||||
|
|
@ -54,8 +54,8 @@ impl Event {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! emit {
|
||||
(Quit($write_cwd_file:expr)) => {
|
||||
$crate::Event::Quit($write_cwd_file).emit();
|
||||
(Quit($no_cwd_file:expr)) => {
|
||||
$crate::Event::Quit($no_cwd_file).emit();
|
||||
};
|
||||
(Key($key:expr)) => {
|
||||
$crate::Event::Key($key).emit();
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ impl Manager {
|
|||
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();
|
||||
if tasks == 0 {
|
||||
emit!(Quit(write_cwd_file));
|
||||
emit!(Quit(no_cwd_file));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ impl Manager {
|
|||
|
||||
if let Some(Ok(choice)) = result.recv().await {
|
||||
if choice == "y" || choice == "Y" {
|
||||
emit!(Quit(write_cwd_file));
|
||||
emit!(Quit(no_cwd_file));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue