use std::error::Error;
#[cfg(all(unix, not(target_os = "macos")))]
mod linux;
#[cfg(all(unix, not(target_os = "macos")))]
pub use crate::linux::*;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::*;
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use windows::*;
#[cfg(not(any(unix, windows)))]
mod unsupported;
#[cfg(not(any(unix, windows)))]
pub use unsupported::*;
#[cfg(feature = "from_url")]
mod from_url;
#[cfg(feature = "from_url")]
pub(crate) use from_url::download_image;
type Result<T> = std::result::Result<T, Box<dyn Error>>;
#[derive(Clone, Debug)]
pub enum Mode {
Center,
Crop,
Fit,
Span,
Stretch,
Tile,
}
#[cfg(unix)]
fn get_stdout(command: &str, args: &[&str]) -> Result<String> {
use std::process::Command;
let output = Command::new(command).args(args).output()?;
if output.status.success() {
Ok(String::from_utf8(output.stdout)?.trim().into())
} else {
Err(format!(
"{} exited with status code {}",
command,
output.status.code().unwrap_or(-1),
)
.into())
}
}
#[cfg(unix)]
#[inline]
fn run(command: &str, args: &[&str]) -> Result<()> {
get_stdout(command, args).map(|_| ())
}