1mod error;
2pub use error::Error;
3
4#[cfg(all(unix, not(target_os = "macos")))]
5mod linux;
6
7#[cfg(all(unix, not(target_os = "macos")))]
8pub use crate::linux::*;
9
10#[cfg(target_os = "macos")]
12mod macos;
13
14#[cfg(target_os = "macos")]
15pub use macos::*;
16
17#[cfg(windows)]
18mod windows;
19
20#[cfg(windows)]
21pub use windows::*;
22
23#[cfg(not(any(unix, windows)))]
25mod unsupported;
26
27#[cfg(not(any(unix, windows)))]
28pub use unsupported::*;
29
30type Result<T, E = Error> = std::result::Result<T, E>;
31
32#[derive(Clone, Debug)]
33pub enum Mode {
34 Center,
35 Crop,
36 Fit,
37 Span,
38 Stretch,
39 Tile,
40}
41
42#[cfg(unix)]
43fn get_stdout(command: &str, args: &[&str]) -> Result<String> {
44 use std::process::Command;
45
46 let output = Command::new(command).args(args).output()?;
47 if output.status.success() {
48 Ok(String::from_utf8(output.stdout)?.trim().into())
49 } else {
50 Err(Error::CommandFailed {
51 command: command.to_string(),
52 code: output.status.code().unwrap_or(-1),
53 })
54 }
55}
56
57#[cfg(unix)]
58#[inline]
59fn run(command: &str, args: &[&str]) -> Result<()> {
60 get_stdout(command, args).map(|_| ())
61}