Skip to main content

par_term_config/config/config_struct/
notification_config.rs

1//! Notification settings for the terminal emulator.
2//!
3//! Extracted from the top-level [`super::Config`] struct via `#[serde(flatten)]`.
4//! All fields serialise at the top level of the YAML config file — existing
5//! config files remain 100% compatible.
6//!
7//! Covers bell (audio, visual, desktop), activity/silence alerts, anti-idle
8//! keep-alive, and OSC 9/777 notification buffer limits.
9
10use crate::types::{AlertEvent, AlertSoundConfig};
11use serde::{Deserialize, Serialize};
12use std::collections::HashMap;
13
14/// Notification and alert settings for the terminal emulator.
15///
16/// Controls the bell (audio, visual, desktop notifications), activity and
17/// silence alerts, the anti-idle keep-alive mechanism, and limits on the
18/// OSC 9/777 notification buffer.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct NotificationConfig {
21    /// Forward BEL events to desktop notification centers
22    #[serde(default = "crate::defaults::bool_false", alias = "bell_desktop")]
23    pub notification_bell_desktop: bool,
24
25    /// Volume (0-100) for backend bell sound alerts (0 disables)
26    #[serde(default = "crate::defaults::bell_sound", alias = "bell_sound")]
27    pub notification_bell_sound: u8,
28
29    /// Enable backend visual bell overlay
30    #[serde(default = "crate::defaults::bool_true", alias = "bell_visual")]
31    pub notification_bell_visual: bool,
32
33    /// Visual bell flash color [R, G, B] (0-255, default: white)
34    #[serde(default = "crate::defaults::visual_bell_color")]
35    pub notification_visual_bell_color: [u8; 3],
36
37    /// Enable notifications when activity resumes after inactivity
38    #[serde(
39        default = "crate::defaults::bool_false",
40        alias = "activity_notifications"
41    )]
42    pub notification_activity_enabled: bool,
43
44    /// Seconds of inactivity required before an activity alert fires
45    #[serde(
46        default = "crate::defaults::activity_threshold",
47        alias = "activity_threshold"
48    )]
49    pub notification_activity_threshold: u64,
50
51    /// Enable anti-idle keep-alive (sends code after idle period)
52    #[serde(default = "crate::defaults::bool_false")]
53    pub anti_idle_enabled: bool,
54
55    /// Seconds of inactivity before sending keep-alive code
56    #[serde(default = "crate::defaults::anti_idle_seconds")]
57    pub anti_idle_seconds: u64,
58
59    /// ASCII code to send as keep-alive (e.g., 0 = NUL, 27 = ESC)
60    #[serde(default = "crate::defaults::anti_idle_code")]
61    pub anti_idle_code: u8,
62
63    /// Enable notifications after prolonged silence
64    #[serde(
65        default = "crate::defaults::bool_false",
66        alias = "silence_notifications"
67    )]
68    pub notification_silence_enabled: bool,
69
70    /// Seconds of silence before a silence alert fires
71    #[serde(
72        default = "crate::defaults::silence_threshold",
73        alias = "silence_threshold"
74    )]
75    pub notification_silence_threshold: u64,
76
77    /// Enable notification when a shell/session exits
78    #[serde(default = "crate::defaults::bool_false", alias = "session_ended")]
79    pub notification_session_ended: bool,
80
81    /// Suppress desktop notifications when the terminal window is focused
82    #[serde(default = "crate::defaults::bool_true")]
83    pub suppress_notifications_when_focused: bool,
84
85    /// Maximum number of OSC 9/777 notification entries retained by backend
86    #[serde(
87        default = "crate::defaults::notification_max_buffer",
88        alias = "max_notifications"
89    )]
90    pub notification_max_buffer: usize,
91
92    /// Alert sound configuration per event type.
93    ///
94    /// Maps [`AlertEvent`] variants to their sound settings.
95    #[serde(default)]
96    pub alert_sounds: HashMap<AlertEvent, AlertSoundConfig>,
97}
98
99impl Default for NotificationConfig {
100    fn default() -> Self {
101        Self {
102            notification_bell_desktop: crate::defaults::bool_false(),
103            notification_bell_sound: crate::defaults::bell_sound(),
104            notification_bell_visual: crate::defaults::bool_true(),
105            notification_visual_bell_color: crate::defaults::visual_bell_color(),
106            notification_activity_enabled: crate::defaults::bool_false(),
107            notification_activity_threshold: crate::defaults::activity_threshold(),
108            anti_idle_enabled: crate::defaults::bool_false(),
109            anti_idle_seconds: crate::defaults::anti_idle_seconds(),
110            anti_idle_code: crate::defaults::anti_idle_code(),
111            notification_silence_enabled: crate::defaults::bool_false(),
112            notification_silence_threshold: crate::defaults::silence_threshold(),
113            notification_session_ended: crate::defaults::bool_false(),
114            suppress_notifications_when_focused: crate::defaults::bool_true(),
115            notification_max_buffer: crate::defaults::notification_max_buffer(),
116            alert_sounds: HashMap::new(),
117        }
118    }
119}