any-dialog 1.0.0

Simple dialogs via kdialog, zenity, osascript, or PowerShell. Zero dependencies.
Documentation
//! The crate's error type.

use std::fmt;
use std::path::PathBuf;
use std::process::ExitStatus;

/// Everything that can go wrong while showing a dialog.
#[derive(Debug)]
pub enum Error {
    /// None of the backends (`kdialog`, `zenity`, `osascript`,
    /// `powershell`) was found on this system.
    NoBackend,
    /// The helper could not be started.
    Spawn {
        program: PathBuf,
        source: std::io::Error,
    },
    /// The helper exited with a status that does not mean success or cancel.
    Exit {
        program: PathBuf,
        status: ExitStatus,
    },
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::NoBackend => {
                write!(
                    f,
                    "no dialog backend available (none of kdialog, zenity, osascript, or powershell was found)"
                )
            }
            Error::Spawn { program, source } => {
                write!(f, "could not run {}: {source}", program.display())
            }
            Error::Exit { program, status } => {
                write!(f, "{} exited with {status}", program.display())
            }
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Spawn { source, .. } => Some(source),
            _ => None,
        }
    }
}