diff --git a/app/Cargo.toml b/app/Cargo.toml index a4e167755..a0dc9e20a 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -24,7 +24,7 @@ tracing = "^0" tracing-appender = "^0" tracing-subscriber = "^0" -[target.'cfg(not(target_os = "windows"))'.dependencies] +[target."cfg(unix)".dependencies] libc = "^0" signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] } diff --git a/app/src/app.rs b/app/src/app.rs index 6ed4b11d9..dbcb1520d 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -45,11 +45,11 @@ impl App { if let Some(p) = BOOT.cwd_file.as_ref().filter(|_| !no_cwd_file) { let cwd = self.cx.manager.cwd().as_os_str(); - #[cfg(target_os = "windows")] + #[cfg(windows)] { std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok(); } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; std::fs::write(p, cwd.as_bytes()).ok(); @@ -191,11 +191,11 @@ impl App { s }); - #[cfg(target_os = "windows")] + #[cfg(windows)] { std::fs::write(p, paths.to_string_lossy().as_bytes()).ok(); } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; std::fs::write(p, paths.as_bytes()).ok(); diff --git a/app/src/signals.rs b/app/src/signals.rs index a01caa397..29a84d73a 100644 --- a/app/src/signals.rs +++ b/app/src/signals.rs @@ -45,10 +45,10 @@ impl Signals { } } - #[cfg(target_os = "windows")] + #[cfg(windows)] fn spawn_system_task(&self) -> Result<()> { Ok(()) } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] fn spawn_system_task(&self) -> Result> { use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM}; diff --git a/config/src/xdg.rs b/config/src/xdg.rs index 48edcd625..005d6e0ce 100644 --- a/config/src/xdg.rs +++ b/config/src/xdg.rs @@ -10,11 +10,11 @@ impl Xdg { return Some(expand_path(s)); } - #[cfg(target_os = "windows")] + #[cfg(windows)] { dirs::config_dir().map(|p| p.join("yazi").join("config")) } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { env::var_os("XDG_CONFIG_HOME") .map(PathBuf::from) @@ -25,11 +25,11 @@ impl Xdg { } pub(super) fn state_dir() -> Option { - #[cfg(target_os = "windows")] + #[cfg(windows)] { dirs::data_dir().map(|p| p.join("yazi").join("state")) } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { env::var_os("XDG_STATE_HOME") .map(PathBuf::from) diff --git a/core/Cargo.toml b/core/Cargo.toml index fb33d85bc..2fb3d0700 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -31,5 +31,5 @@ yazi-prebuild = "^0" # Logging tracing = "^0" -[target.'cfg(target_os = "windows")'.dependencies] +[target."cfg(windows)".dependencies] clipboard-win = "^4" diff --git a/core/src/external/clipboard.rs b/core/src/external/clipboard.rs index 86e770b5d..e6f95e307 100644 --- a/core/src/external/clipboard.rs +++ b/core/src/external/clipboard.rs @@ -2,7 +2,7 @@ use std::ffi::OsString; use anyhow::Result; -#[cfg(not(target_os = "windows"))] +#[cfg(unix)] pub async fn clipboard_get() -> Result { use std::os::unix::prelude::OsStringExt; @@ -28,7 +28,7 @@ pub async fn clipboard_get() -> Result { bail!("failed to get clipboard") } -#[cfg(target_os = "windows")] +#[cfg(windows)] pub async fn clipboard_get() -> Result { use anyhow::anyhow; use clipboard_win::{formats, get_clipboard}; @@ -37,7 +37,7 @@ pub async fn clipboard_get() -> Result { Ok(result.await?.map_err(|_| anyhow!("failed to get clipboard"))?.into()) } -#[cfg(not(target_os = "windows"))] +#[cfg(unix)] pub async fn clipboard_set(s: impl AsRef) -> Result<()> { use std::{os::unix::prelude::OsStrExt, process::Stdio}; @@ -77,7 +77,7 @@ pub async fn clipboard_set(s: impl AsRef) -> Result<()> { bail!("failed to set clipboard") } -#[cfg(target_os = "windows")] +#[cfg(windows)] pub async fn clipboard_set(s: impl AsRef) -> Result<()> { use anyhow::anyhow; use clipboard_win::{formats, set_clipboard}; diff --git a/core/src/manager/commands/rename.rs b/core/src/manager/commands/rename.rs index 5f276be6f..cc6da3713 100644 --- a/core/src/manager/commands/rename.rs +++ b/core/src/manager/commands/rename.rs @@ -72,11 +72,11 @@ impl Manager { { let s = old.iter().map(|o| o.as_os_str()).collect::>().join(OsStr::new("\n")); let mut f = OpenOptions::new().write(true).create_new(true).open(&tmp).await?; - #[cfg(target_os = "windows")] + #[cfg(windows)] { f.write_all(s.to_string_lossy().as_bytes()).await?; } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; f.write_all(s.as_bytes()).await?; diff --git a/core/src/manager/commands/suspend.rs b/core/src/manager/commands/suspend.rs index b80087d92..caee38eaf 100644 --- a/core/src/manager/commands/suspend.rs +++ b/core/src/manager/commands/suspend.rs @@ -1,10 +1,10 @@ -use crate::{emit, manager::Manager}; +use crate::manager::Manager; impl Manager { pub fn suspend(&mut self) -> bool { - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] tokio::spawn(async move { - emit!(Stop(true)).await; + crate::emit!(Stop(true)).await; unsafe { libc::raise(libc::SIGTSTP) }; }); false diff --git a/core/src/tab/finder.rs b/core/src/tab/finder.rs index d2b739307..d9e829dfc 100644 --- a/core/src/tab/finder.rs +++ b/core/src/tab/finder.rs @@ -78,11 +78,11 @@ impl Finder { #[inline] fn matches(&self, name: &OsStr) -> bool { - #[cfg(target_os = "windows")] + #[cfg(windows)] { self.query.is_match(name.to_string_lossy().as_bytes()) } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { use std::os::unix::ffi::OsStrExt; self.query.is_match(name.as_bytes()) diff --git a/shared/src/fs.rs b/shared/src/fs.rs index 6554d9d07..b140a21e8 100644 --- a/shared/src/fs.rs +++ b/shared/src/fs.rs @@ -179,7 +179,7 @@ pub fn max_common_root(files: &[impl AsRef]) -> PathBuf { root } -#[cfg(not(target_os = "windows"))] +#[cfg(unix)] #[test] fn test_max_common_root() { assert_eq!(max_common_root(&[] as &[PathBuf]).as_os_str(), ""); diff --git a/shared/src/term/cursor.rs b/shared/src/term/cursor.rs index ca74c9818..821f5f70c 100644 --- a/shared/src/term/cursor.rs +++ b/shared/src/term/cursor.rs @@ -22,7 +22,7 @@ impl Term { W: Write, F: FnOnce(&mut W) -> Result<()>, { - #[cfg(target_os = "windows")] + #[cfg(windows)] { use std::{thread, time::Duration}; @@ -39,7 +39,7 @@ impl Term { stdout.flush()?; result } - #[cfg(not(target_os = "windows"))] + #[cfg(unix)] { queue!(&mut stdout, SavePosition, MoveTo(x, y))?; let result = cb(&mut stdout);