1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//! Status bar widget configuration types.
//!
//! Defines the widget identifiers, section layout, and per-widget configuration
//! used by the status bar system.
use serde::de::{self, Deserializer};
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
/// Section of the status bar where a widget is placed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum StatusBarSection {
/// Left-aligned section (default)
#[default]
Left,
/// Center-aligned section
Center,
/// Right-aligned section
Right,
}
/// Identifier for a built-in or custom status bar widget.
///
/// Serialized as a single plain string (`as_key`/`from_key`) so it round-trips
/// through `config.yaml`, which embeds the status bar via `#[serde(flatten)]`.
/// Built-in widgets use their snake_case name (e.g. `git_branch`); custom
/// widgets use `custom:<name>`; plugin widgets use `plugin:<id>`. serde's
/// flatten path cannot deserialize the
/// externally-tagged `Custom(String)` map form (`"untagged and internally tagged
/// enums do not support enum input"`), so a manual scalar representation is
/// used instead of the derived one.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WidgetId {
/// Current time (HH:MM:SS)
Clock,
/// user@hostname
UsernameHostname,
/// Current working directory
CurrentDirectory,
/// Git branch name with icon
GitBranch,
/// CPU usage percentage
CpuUsage,
/// Memory usage (used / total)
MemoryUsage,
/// Network throughput (rx/tx rates)
NetworkStatus,
/// Free disk space (percent + bytes)
DiskFree,
/// Bell indicator with count
BellIndicator,
/// Currently running command name
CurrentCommand,
/// Update available notification
UpdateAvailable,
/// Agent subscription usage summary (self-hiding; click opens the usage panel)
AgentUsage,
/// par-mux agent roster summary (self-hiding; click opens the command
/// palette). Empty without an attached mux session.
AgentRoster,
/// Custom widget (user-defined via format string)
Custom(String),
/// Plugin-provided status bar widget (`plugin:<id>` key)
Plugin(String),
}
impl WidgetId {
/// Human-readable label for UI display.
pub fn label(&self) -> &str {
match self {
WidgetId::Clock => "Clock",
WidgetId::UsernameHostname => "User@Host",
WidgetId::CurrentDirectory => "Directory",
WidgetId::GitBranch => "Git Branch",
WidgetId::CpuUsage => "CPU Usage",
WidgetId::MemoryUsage => "Memory Usage",
WidgetId::NetworkStatus => "Network Status",
WidgetId::DiskFree => "Disk Free",
WidgetId::BellIndicator => "Bell Indicator",
WidgetId::CurrentCommand => "Current Command",
WidgetId::UpdateAvailable => "Update Available",
WidgetId::AgentUsage => "Agent Usage",
WidgetId::AgentRoster => "Agent Roster",
WidgetId::Custom(name) => name.as_str(),
WidgetId::Plugin(id) => id.as_str(),
}
}
/// Icon/prefix character for the widget.
pub fn icon(&self) -> &str {
match self {
WidgetId::Clock => "\u{1f551}", // clock emoji
WidgetId::UsernameHostname => "\u{1f464}", // bust in silhouette
WidgetId::CurrentDirectory => "\u{1f4c2}", // open file folder
WidgetId::GitBranch => "\u{1f500}", // twisted rightwards arrows (branch)
WidgetId::CpuUsage => "\u{1f4bb}", // laptop
WidgetId::MemoryUsage => "\u{1f4be}", // floppy disk
WidgetId::NetworkStatus => "\u{1f310}", // globe with meridians
WidgetId::DiskFree => "\u{1f4bf}", // optical disk
WidgetId::BellIndicator => "\u{1f514}", // bell
WidgetId::CurrentCommand => "\u{25b6}", // play button
WidgetId::UpdateAvailable => "\u{2b06}", // upwards arrow
WidgetId::AgentUsage => "\u{25c6}", // diamond (matches the summary glyph)
WidgetId::AgentRoster => "\u{1f465}", // busts in silhouette (a roster of agents)
WidgetId::Custom(_) => "\u{2699}", // gear
WidgetId::Plugin(_) => "\u{1f9e9}", // puzzle piece
}
}
/// Whether this widget requires the system monitor to be running.
pub fn needs_system_monitor(&self) -> bool {
matches!(
self,
WidgetId::CpuUsage | WidgetId::MemoryUsage | WidgetId::NetworkStatus
)
}
/// Whether this widget requires the disk monitor to be running.
pub fn needs_disk_monitor(&self) -> bool {
matches!(self, WidgetId::DiskFree)
}
/// Stable string key used for YAML serialization. Built-in widgets use their
/// snake_case name; custom widgets are prefixed with `custom:`.
fn as_key(&self) -> String {
match self {
WidgetId::Clock => "clock".to_string(),
WidgetId::UsernameHostname => "username_hostname".to_string(),
WidgetId::CurrentDirectory => "current_directory".to_string(),
WidgetId::GitBranch => "git_branch".to_string(),
WidgetId::CpuUsage => "cpu_usage".to_string(),
WidgetId::MemoryUsage => "memory_usage".to_string(),
WidgetId::NetworkStatus => "network_status".to_string(),
WidgetId::DiskFree => "disk_free".to_string(),
WidgetId::BellIndicator => "bell_indicator".to_string(),
WidgetId::CurrentCommand => "current_command".to_string(),
WidgetId::UpdateAvailable => "update_available".to_string(),
WidgetId::AgentUsage => "agent_usage".to_string(),
WidgetId::AgentRoster => "agent_roster".to_string(),
WidgetId::Custom(name) => format!("custom:{name}"),
WidgetId::Plugin(id) => format!("plugin:{id}"),
}
}
/// Parse a serialization key back into a [`WidgetId`]. Returns `None` for
/// unrecognized built-in names.
fn from_key(key: &str) -> Option<WidgetId> {
if let Some(name) = key.strip_prefix("custom:") {
return Some(WidgetId::Custom(name.to_string()));
}
if let Some(id) = key.strip_prefix("plugin:") {
return Some(WidgetId::Plugin(id.to_string()));
}
Some(match key {
"clock" => WidgetId::Clock,
"username_hostname" => WidgetId::UsernameHostname,
"current_directory" => WidgetId::CurrentDirectory,
"git_branch" => WidgetId::GitBranch,
"cpu_usage" => WidgetId::CpuUsage,
"memory_usage" => WidgetId::MemoryUsage,
"network_status" => WidgetId::NetworkStatus,
"disk_free" => WidgetId::DiskFree,
"bell_indicator" => WidgetId::BellIndicator,
"current_command" => WidgetId::CurrentCommand,
"update_available" => WidgetId::UpdateAvailable,
"agent_usage" => WidgetId::AgentUsage,
"agent_roster" => WidgetId::AgentRoster,
_ => return None,
})
}
}
impl Serialize for WidgetId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.as_key())
}
}
impl<'de> Deserialize<'de> for WidgetId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let key = String::deserialize(deserializer)?;
WidgetId::from_key(&key)
.ok_or_else(|| de::Error::custom(format!("unknown status bar widget id: `{key}`")))
}
}
/// Configuration for a single status bar widget.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct StatusBarWidgetConfig {
/// Which widget to display
pub id: WidgetId,
/// Whether this widget is enabled
#[serde(default = "default_true")]
pub enabled: bool,
/// Section placement (left, center, right)
#[serde(default)]
pub section: StatusBarSection,
/// Sort order within the section (lower values first)
#[serde(default)]
pub order: i32,
/// Optional format override string with `\(variable)` interpolation
#[serde(default, skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
}
fn default_true() -> bool {
true
}
/// Default widget configuration set.
///
/// Returns a sensible starting set of widgets covering common use-cases.
/// System monitor widgets (CPU, memory, network) are disabled by default
/// to avoid unnecessary resource usage.
pub fn default_widgets() -> Vec<StatusBarWidgetConfig> {
vec![
StatusBarWidgetConfig {
id: WidgetId::UsernameHostname,
enabled: true,
section: StatusBarSection::Left,
order: 0,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::CurrentDirectory,
enabled: true,
section: StatusBarSection::Left,
order: 1,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::GitBranch,
enabled: true,
section: StatusBarSection::Left,
order: 2,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::CurrentCommand,
enabled: true,
section: StatusBarSection::Center,
order: 0,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::CpuUsage,
enabled: false,
section: StatusBarSection::Right,
order: 0,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::MemoryUsage,
enabled: false,
section: StatusBarSection::Right,
order: 1,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::NetworkStatus,
enabled: false,
section: StatusBarSection::Right,
order: 2,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::DiskFree,
enabled: false,
section: StatusBarSection::Right,
order: 3,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::BellIndicator,
enabled: true,
section: StatusBarSection::Right,
order: 4,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::Clock,
enabled: true,
section: StatusBarSection::Right,
order: 5,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::UpdateAvailable,
enabled: true,
section: StatusBarSection::Right,
order: 6,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::AgentUsage,
enabled: false,
section: StatusBarSection::Right,
order: 7,
format: None,
},
StatusBarWidgetConfig {
id: WidgetId::AgentRoster,
enabled: false,
section: StatusBarSection::Right,
order: 8,
format: None,
},
]
}