From 9c6fa4ec93ebc93b3086e9342129af145d9c1904 Mon Sep 17 00:00:00 2001 From: XOR-op <17672363+XOR-op@users.noreply.github.com> Date: Thu, 5 Oct 2023 08:54:11 -0400 Subject: [PATCH] chore: change name and write nothing with no-cwd-file --- app/src/app.rs | 29 +++++++++++++++-------------- app/src/executor.rs | 2 +- core/src/event.rs | 6 +++--- core/src/manager/manager.rs | 6 +++--- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/src/app.rs b/app/src/app.rs index 3ba8fb34..8725189d 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -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(); + } } } } diff --git a/app/src/executor.rs b/app/src/executor.rs index a583297c..8799e84f 100644 --- a/app/src/executor.rs +++ b/app/src/executor.rs @@ -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(), diff --git a/core/src/event.rs b/core/src/event.rs index b8eecb89..31b7d825 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -12,7 +12,7 @@ use crate::manager::PreviewLock; static TX: RoCell> = 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(); diff --git a/core/src/manager/manager.rs b/core/src/manager/manager.rs index cfa27039..25a2cfc4 100644 --- a/core/src/manager/manager.rs +++ b/core/src/manager/manager.rs @@ -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)); } } });