Skip to main content

par_term_config/config/config_struct/
status_bar_config.rs

1//! [`StatusBarConfig`]: Status bar settings.
2
3use crate::types::StatusBarPosition;
4use serde::{Deserialize, Serialize};
5
6/// Configuration for the status bar displayed at the top or bottom of the terminal.
7///
8/// Extracted from the monolithic `Config` struct via `#[serde(flatten)]`.
9/// All fields that were previously `status_bar_*` on `Config` are now
10/// grouped here, keeping the YAML format fully backward-compatible.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(default)]
13pub struct StatusBarConfig {
14    /// Enable the status bar
15    #[serde(default = "default_status_bar_enabled")]
16    pub status_bar_enabled: bool,
17
18    /// Status bar position (top or bottom)
19    #[serde(default)]
20    pub status_bar_position: StatusBarPosition,
21
22    /// Status bar height in pixels
23    #[serde(default = "default_status_bar_height")]
24    pub status_bar_height: f32,
25
26    /// Status bar background color [R, G, B] (0-255)
27    #[serde(default = "default_status_bar_bg_color")]
28    pub status_bar_bg_color: [u8; 3],
29
30    /// Status bar background alpha (0.0-1.0)
31    #[serde(default = "default_status_bar_bg_alpha")]
32    pub status_bar_bg_alpha: f32,
33
34    /// Status bar foreground (text) color [R, G, B] (0-255)
35    #[serde(default = "default_status_bar_fg_color")]
36    pub status_bar_fg_color: [u8; 3],
37
38    /// Status bar font family (empty string = use terminal font)
39    #[serde(default)]
40    pub status_bar_font: String,
41
42    /// Status bar font size in points
43    #[serde(default = "default_status_bar_font_size")]
44    pub status_bar_font_size: f32,
45
46    /// Separator string between widgets
47    #[serde(default = "default_status_bar_separator")]
48    pub status_bar_separator: String,
49
50    /// Auto-hide the status bar when in fullscreen mode
51    #[serde(default = "default_status_bar_auto_hide_fullscreen")]
52    pub status_bar_auto_hide_fullscreen: bool,
53
54    /// Auto-hide the status bar when mouse is inactive
55    #[serde(default = "default_status_bar_auto_hide_mouse_inactive")]
56    pub status_bar_auto_hide_mouse_inactive: bool,
57
58    /// Timeout in seconds before hiding status bar after last mouse activity
59    #[serde(default = "default_status_bar_mouse_inactive_timeout")]
60    pub status_bar_mouse_inactive_timeout: f32,
61
62    /// Polling interval in seconds for system monitor data (CPU, memory, network)
63    #[serde(default = "default_status_bar_system_poll_interval")]
64    pub status_bar_system_poll_interval: f32,
65
66    /// Polling interval in seconds for git branch detection
67    #[serde(default = "default_status_bar_git_poll_interval")]
68    pub status_bar_git_poll_interval: f32,
69
70    /// Time format string for the Clock widget (chrono strftime syntax)
71    #[serde(default = "default_status_bar_time_format")]
72    pub status_bar_time_format: String,
73
74    /// Show ahead/behind and dirty indicators on the Git Branch widget
75    #[serde(default = "default_status_bar_git_show_status")]
76    pub status_bar_git_show_status: bool,
77
78    /// Widget configuration list
79    #[serde(default = "crate::status_bar::default_widgets")]
80    pub status_bar_widgets: Vec<crate::status_bar::StatusBarWidgetConfig>,
81}
82
83// ── Default value functions ────────────────────────────────────────────────
84
85fn default_status_bar_enabled() -> bool {
86    false
87}
88
89fn default_status_bar_height() -> f32 {
90    22.0
91}
92
93fn default_status_bar_bg_color() -> [u8; 3] {
94    [30, 30, 30]
95}
96
97fn default_status_bar_bg_alpha() -> f32 {
98    0.95
99}
100
101fn default_status_bar_fg_color() -> [u8; 3] {
102    [200, 200, 200]
103}
104
105fn default_status_bar_font_size() -> f32 {
106    12.0
107}
108
109fn default_status_bar_separator() -> String {
110    " \u{2502} ".to_string() // " │ "
111}
112
113fn default_status_bar_auto_hide_fullscreen() -> bool {
114    true
115}
116
117fn default_status_bar_auto_hide_mouse_inactive() -> bool {
118    false
119}
120
121fn default_status_bar_mouse_inactive_timeout() -> f32 {
122    3.0
123}
124
125fn default_status_bar_system_poll_interval() -> f32 {
126    2.0
127}
128
129fn default_status_bar_git_poll_interval() -> f32 {
130    5.0
131}
132
133fn default_status_bar_time_format() -> String {
134    "%H:%M:%S".to_string()
135}
136
137fn default_status_bar_git_show_status() -> bool {
138    true
139}
140
141impl Default for StatusBarConfig {
142    fn default() -> Self {
143        Self {
144            status_bar_enabled: default_status_bar_enabled(),
145            status_bar_position: StatusBarPosition::default(),
146            status_bar_height: default_status_bar_height(),
147            status_bar_bg_color: default_status_bar_bg_color(),
148            status_bar_bg_alpha: default_status_bar_bg_alpha(),
149            status_bar_fg_color: default_status_bar_fg_color(),
150            status_bar_font: String::new(),
151            status_bar_font_size: default_status_bar_font_size(),
152            status_bar_separator: default_status_bar_separator(),
153            status_bar_auto_hide_fullscreen: default_status_bar_auto_hide_fullscreen(),
154            status_bar_auto_hide_mouse_inactive: default_status_bar_auto_hide_mouse_inactive(),
155            status_bar_mouse_inactive_timeout: default_status_bar_mouse_inactive_timeout(),
156            status_bar_system_poll_interval: default_status_bar_system_poll_interval(),
157            status_bar_git_poll_interval: default_status_bar_git_poll_interval(),
158            status_bar_time_format: default_status_bar_time_format(),
159            status_bar_git_show_status: default_status_bar_git_show_status(),
160            status_bar_widgets: crate::status_bar::default_widgets(),
161        }
162    }
163}