1use std::error::Error;
31
32#[cfg(all(unix, not(target_os = "macos")))]
33mod linux;
34
35#[cfg(all(unix, not(target_os = "macos")))]
36pub use crate::linux::*;
37
38#[cfg(target_os = "macos")]
40mod macos;
41
42#[cfg(target_os = "macos")]
43pub use macos::*;
44
45#[cfg(windows)]
46mod win;
47
48#[cfg(windows)]
49pub use win::*;
50
51#[cfg(not(any(unix, windows)))]
53mod unsupported;
54
55#[cfg(not(any(unix, windows)))]
56pub use unsupported::*;
57
58#[cfg(feature = "from_url")]
60mod from_url;
61
62#[cfg(feature = "from_url")]
63pub(crate) use from_url::download_image;
64
65type Result<T> = std::result::Result<T, Box<dyn Error>>;
66
67#[derive(Clone, Debug)]
68pub enum Mode {
69 Center,
70 Crop,
71 Fit,
72 Span,
73 Stretch,
74 Tile,
75}
76
77#[cfg(unix)]
78fn get_stdout(command: &str, args: &[&str]) -> Result<String> {
79 use std::process::Command;
80
81 let output = Command::new(command).args(args).output()?;
82 if output.status.success() {
83 Ok(String::from_utf8(output.stdout)?.trim().into())
84 } else {
85 Err(format!(
86 "{} exited with status code {}",
87 command,
88 output.status.code().unwrap_or(-1),
89 )
90 .into())
91 }
92}
93
94#[cfg(unix)]
95#[inline]
96fn run(command: &str, args: &[&str]) -> Result<()> {
97 get_stdout(command, args).map(|_| ())
98}