mod bel;
mod osc9;
use std::io;
use bel::BelBackend;
use osc9::Osc9Backend;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum NotificationMethod {
Auto,
Osc9,
Bell,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct NotificationCapabilities {
pub osc9: bool,
pub tmux_passthrough: bool,
}
#[derive(Debug)]
pub enum DesktopNotificationBackend {
Osc9(Osc9Backend),
Bell(BelBackend),
}
impl DesktopNotificationBackend {
pub fn new(method: NotificationMethod, capabilities: NotificationCapabilities) -> Self {
match method {
NotificationMethod::Auto if capabilities.osc9 => {
Self::Osc9(Osc9Backend::new(capabilities.tmux_passthrough))
}
NotificationMethod::Osc9 => Self::Osc9(Osc9Backend::new(capabilities.tmux_passthrough)),
NotificationMethod::Auto | NotificationMethod::Bell => Self::Bell(BelBackend),
}
}
pub fn method(&self) -> NotificationMethod {
match self {
Self::Osc9(_) => NotificationMethod::Osc9,
Self::Bell(_) => NotificationMethod::Bell,
}
}
pub fn notify(&mut self, message: &str) -> io::Result<()> {
match self {
Self::Osc9(backend) => backend.notify(message),
Self::Bell(backend) => backend.notify(message),
}
}
}