use std::io::Write;
pub fn terminal_notify(title: &str, body: &str) {
let msg = if body.is_empty() {
title.to_owned()
} else {
format!("{title}: {body}")
};
let msg: String = msg.chars().filter(|c| !c.is_control()).collect();
if let Ok(mut tty) = std::fs::OpenOptions::new().write(true).open("/dev/tty") {
let _ = write!(tty, "\x07\x1b]9;{msg}\x07");
}
}
pub fn notify(title: &str, body: &str, sound: &str) {
terminal_notify(title, body);
#[cfg(target_os = "macos")]
{
fn escape(s: &str) -> String {
s.replace('\\', "\\\\").replace('"', "\\\"")
}
let script = format!(
r#"display notification "{}" with title "{}" sound name "{}""#,
escape(body),
escape(title),
escape(sound),
);
let _ = std::process::Command::new("osascript")
.args(["-e", &script])
.status();
}
#[cfg(not(target_os = "macos"))]
let _ = (title, body, sound);
}