refactor: simplify building conditions (#280)

This commit is contained in:
三咲雅 · Misaki Masa 2023-10-16 09:04:20 +08:00 committed by GitHub
parent 54339e79a7
commit fa5de51ce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 26 additions and 26 deletions

View file

@ -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" ] }

View file

@ -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();

View file

@ -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<JoinHandle<()>> {
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};

View file

@ -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<PathBuf> {
#[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)

View file

@ -31,5 +31,5 @@ yazi-prebuild = "^0"
# Logging
tracing = "^0"
[target.'cfg(target_os = "windows")'.dependencies]
[target."cfg(windows)".dependencies]
clipboard-win = "^4"

View file

@ -2,7 +2,7 @@ use std::ffi::OsString;
use anyhow::Result;
#[cfg(not(target_os = "windows"))]
#[cfg(unix)]
pub async fn clipboard_get() -> Result<OsString> {
use std::os::unix::prelude::OsStringExt;
@ -28,7 +28,7 @@ pub async fn clipboard_get() -> Result<OsString> {
bail!("failed to get clipboard")
}
#[cfg(target_os = "windows")]
#[cfg(windows)]
pub async fn clipboard_get() -> Result<OsString> {
use anyhow::anyhow;
use clipboard_win::{formats, get_clipboard};
@ -37,7 +37,7 @@ pub async fn clipboard_get() -> Result<OsString> {
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<std::ffi::OsStr>) -> Result<()> {
use std::{os::unix::prelude::OsStrExt, process::Stdio};
@ -77,7 +77,7 @@ pub async fn clipboard_set(s: impl AsRef<std::ffi::OsStr>) -> Result<()> {
bail!("failed to set clipboard")
}
#[cfg(target_os = "windows")]
#[cfg(windows)]
pub async fn clipboard_set(s: impl AsRef<std::ffi::OsStr>) -> Result<()> {
use anyhow::anyhow;
use clipboard_win::{formats, set_clipboard};

View file

@ -72,11 +72,11 @@ impl Manager {
{
let s = old.iter().map(|o| o.as_os_str()).collect::<Vec<_>>().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?;

View file

@ -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

View file

@ -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())

View file

@ -179,7 +179,7 @@ pub fn max_common_root(files: &[impl AsRef<Path>]) -> 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(), "");

View file

@ -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);