supercode_frontend_tui/terminal/notifications/
mod.rs1mod bel;
10mod osc9;
11
12use std::io;
13
14use bel::BelBackend;
15use osc9::Osc9Backend;
16
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub enum NotificationMethod {
19 Auto,
20 Osc9,
21 Bell,
22}
23
24#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
25pub struct NotificationCapabilities {
26 pub osc9: bool,
27 pub tmux_passthrough: bool,
28}
29
30#[derive(Debug)]
31pub enum DesktopNotificationBackend {
32 Osc9(Osc9Backend),
33 Bell(BelBackend),
34}
35
36impl DesktopNotificationBackend {
37 pub fn new(method: NotificationMethod, capabilities: NotificationCapabilities) -> Self {
38 match method {
39 NotificationMethod::Auto if capabilities.osc9 => {
40 Self::Osc9(Osc9Backend::new(capabilities.tmux_passthrough))
41 }
42 NotificationMethod::Osc9 => Self::Osc9(Osc9Backend::new(capabilities.tmux_passthrough)),
43 NotificationMethod::Auto | NotificationMethod::Bell => Self::Bell(BelBackend),
44 }
45 }
46
47 pub fn method(&self) -> NotificationMethod {
48 match self {
49 Self::Osc9(_) => NotificationMethod::Osc9,
50 Self::Bell(_) => NotificationMethod::Bell,
51 }
52 }
53
54 pub fn notify(&mut self, message: &str) -> io::Result<()> {
55 match self {
56 Self::Osc9(backend) => backend.notify(message),
57 Self::Bell(backend) => backend.notify(message),
58 }
59 }
60}