mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: simplify building conditions (#280)
This commit is contained in:
parent
54339e79a7
commit
fa5de51ce8
11 changed files with 26 additions and 26 deletions
|
|
@ -24,7 +24,7 @@ tracing = "^0"
|
||||||
tracing-appender = "^0"
|
tracing-appender = "^0"
|
||||||
tracing-subscriber = "^0"
|
tracing-subscriber = "^0"
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "windows"))'.dependencies]
|
[target."cfg(unix)".dependencies]
|
||||||
libc = "^0"
|
libc = "^0"
|
||||||
signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] }
|
signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ impl App {
|
||||||
if let Some(p) = BOOT.cwd_file.as_ref().filter(|_| !no_cwd_file) {
|
if let Some(p) = BOOT.cwd_file.as_ref().filter(|_| !no_cwd_file) {
|
||||||
let cwd = self.cx.manager.cwd().as_os_str();
|
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();
|
std::fs::write(p, cwd.to_string_lossy().as_bytes()).ok();
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
|
@ -191,11 +191,11 @@ impl App {
|
||||||
s
|
s
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
std::fs::write(p, paths.to_string_lossy().as_bytes()).ok();
|
std::fs::write(p, paths.to_string_lossy().as_bytes()).ok();
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
std::fs::write(p, paths.as_bytes()).ok();
|
std::fs::write(p, paths.as_bytes()).ok();
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,10 @@ impl Signals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
fn spawn_system_task(&self) -> Result<()> { Ok(()) }
|
fn spawn_system_task(&self) -> Result<()> { Ok(()) }
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
|
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
|
||||||
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ impl Xdg {
|
||||||
return Some(expand_path(s));
|
return Some(expand_path(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
dirs::config_dir().map(|p| p.join("yazi").join("config"))
|
dirs::config_dir().map(|p| p.join("yazi").join("config"))
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
env::var_os("XDG_CONFIG_HOME")
|
env::var_os("XDG_CONFIG_HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
|
|
@ -25,11 +25,11 @@ impl Xdg {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn state_dir() -> Option<PathBuf> {
|
pub(super) fn state_dir() -> Option<PathBuf> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
dirs::data_dir().map(|p| p.join("yazi").join("state"))
|
dirs::data_dir().map(|p| p.join("yazi").join("state"))
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
env::var_os("XDG_STATE_HOME")
|
env::var_os("XDG_STATE_HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,5 @@ yazi-prebuild = "^0"
|
||||||
# Logging
|
# Logging
|
||||||
tracing = "^0"
|
tracing = "^0"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target."cfg(windows)".dependencies]
|
||||||
clipboard-win = "^4"
|
clipboard-win = "^4"
|
||||||
|
|
|
||||||
8
core/src/external/clipboard.rs
vendored
8
core/src/external/clipboard.rs
vendored
|
|
@ -2,7 +2,7 @@ use std::ffi::OsString;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
pub async fn clipboard_get() -> Result<OsString> {
|
pub async fn clipboard_get() -> Result<OsString> {
|
||||||
use std::os::unix::prelude::OsStringExt;
|
use std::os::unix::prelude::OsStringExt;
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ pub async fn clipboard_get() -> Result<OsString> {
|
||||||
bail!("failed to get clipboard")
|
bail!("failed to get clipboard")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
pub async fn clipboard_get() -> Result<OsString> {
|
pub async fn clipboard_get() -> Result<OsString> {
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use clipboard_win::{formats, get_clipboard};
|
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())
|
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<()> {
|
pub async fn clipboard_set(s: impl AsRef<std::ffi::OsStr>) -> Result<()> {
|
||||||
use std::{os::unix::prelude::OsStrExt, process::Stdio};
|
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")
|
bail!("failed to set clipboard")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
pub async fn clipboard_set(s: impl AsRef<std::ffi::OsStr>) -> Result<()> {
|
pub async fn clipboard_set(s: impl AsRef<std::ffi::OsStr>) -> Result<()> {
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use clipboard_win::{formats, set_clipboard};
|
use clipboard_win::{formats, set_clipboard};
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,11 @@ impl Manager {
|
||||||
{
|
{
|
||||||
let s = old.iter().map(|o| o.as_os_str()).collect::<Vec<_>>().join(OsStr::new("\n"));
|
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?;
|
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?;
|
f.write_all(s.to_string_lossy().as_bytes()).await?;
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
f.write_all(s.as_bytes()).await?;
|
f.write_all(s.as_bytes()).await?;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{emit, manager::Manager};
|
use crate::manager::Manager;
|
||||||
|
|
||||||
impl Manager {
|
impl Manager {
|
||||||
pub fn suspend(&mut self) -> bool {
|
pub fn suspend(&mut self) -> bool {
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
emit!(Stop(true)).await;
|
crate::emit!(Stop(true)).await;
|
||||||
unsafe { libc::raise(libc::SIGTSTP) };
|
unsafe { libc::raise(libc::SIGTSTP) };
|
||||||
});
|
});
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -78,11 +78,11 @@ impl Finder {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn matches(&self, name: &OsStr) -> bool {
|
fn matches(&self, name: &OsStr) -> bool {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
self.query.is_match(name.to_string_lossy().as_bytes())
|
self.query.is_match(name.to_string_lossy().as_bytes())
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
self.query.is_match(name.as_bytes())
|
self.query.is_match(name.as_bytes())
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ pub fn max_common_root(files: &[impl AsRef<Path>]) -> PathBuf {
|
||||||
root
|
root
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_max_common_root() {
|
fn test_max_common_root() {
|
||||||
assert_eq!(max_common_root(&[] as &[PathBuf]).as_os_str(), "");
|
assert_eq!(max_common_root(&[] as &[PathBuf]).as_os_str(), "");
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ impl Term {
|
||||||
W: Write,
|
W: Write,
|
||||||
F: FnOnce(&mut W) -> Result<()>,
|
F: FnOnce(&mut W) -> Result<()>,
|
||||||
{
|
{
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ impl Term {
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
queue!(&mut stdout, SavePosition, MoveTo(x, y))?;
|
queue!(&mut stdout, SavePosition, MoveTo(x, y))?;
|
||||||
let result = cb(&mut stdout);
|
let result = cb(&mut stdout);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue