1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
10#[serde(rename_all = "lowercase")]
11pub enum StatusBarSection {
12 #[default]
14 Left,
15 Center,
17 Right,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
23#[serde(rename_all = "snake_case")]
24pub enum WidgetId {
25 Clock,
27 UsernameHostname,
29 CurrentDirectory,
31 GitBranch,
33 CpuUsage,
35 MemoryUsage,
37 NetworkStatus,
39 BellIndicator,
41 CurrentCommand,
43 Custom(String),
45}
46
47impl WidgetId {
48 pub fn label(&self) -> &str {
50 match self {
51 WidgetId::Clock => "Clock",
52 WidgetId::UsernameHostname => "User@Host",
53 WidgetId::CurrentDirectory => "Directory",
54 WidgetId::GitBranch => "Git Branch",
55 WidgetId::CpuUsage => "CPU Usage",
56 WidgetId::MemoryUsage => "Memory Usage",
57 WidgetId::NetworkStatus => "Network Status",
58 WidgetId::BellIndicator => "Bell Indicator",
59 WidgetId::CurrentCommand => "Current Command",
60 WidgetId::Custom(name) => name.as_str(),
61 }
62 }
63
64 pub fn icon(&self) -> &str {
66 match self {
67 WidgetId::Clock => "\u{1f551}", WidgetId::UsernameHostname => "\u{1f464}", WidgetId::CurrentDirectory => "\u{1f4c2}", WidgetId::GitBranch => "\u{e0a0}", WidgetId::CpuUsage => "\u{1f4bb}", WidgetId::MemoryUsage => "\u{1f4be}", WidgetId::NetworkStatus => "\u{1f310}", WidgetId::BellIndicator => "\u{1f514}", WidgetId::CurrentCommand => "\u{25b6}", WidgetId::Custom(_) => "\u{2699}", }
78 }
79
80 pub fn needs_system_monitor(&self) -> bool {
82 matches!(
83 self,
84 WidgetId::CpuUsage | WidgetId::MemoryUsage | WidgetId::NetworkStatus
85 )
86 }
87}
88
89#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
91pub struct StatusBarWidgetConfig {
92 pub id: WidgetId,
94 #[serde(default = "default_true")]
96 pub enabled: bool,
97 #[serde(default)]
99 pub section: StatusBarSection,
100 #[serde(default)]
102 pub order: i32,
103 #[serde(default, skip_serializing_if = "Option::is_none")]
105 pub format: Option<String>,
106}
107
108fn default_true() -> bool {
109 true
110}
111
112pub fn default_widgets() -> Vec<StatusBarWidgetConfig> {
118 vec![
119 StatusBarWidgetConfig {
120 id: WidgetId::UsernameHostname,
121 enabled: true,
122 section: StatusBarSection::Left,
123 order: 0,
124 format: None,
125 },
126 StatusBarWidgetConfig {
127 id: WidgetId::CurrentDirectory,
128 enabled: true,
129 section: StatusBarSection::Left,
130 order: 1,
131 format: None,
132 },
133 StatusBarWidgetConfig {
134 id: WidgetId::GitBranch,
135 enabled: true,
136 section: StatusBarSection::Left,
137 order: 2,
138 format: None,
139 },
140 StatusBarWidgetConfig {
141 id: WidgetId::CurrentCommand,
142 enabled: true,
143 section: StatusBarSection::Center,
144 order: 0,
145 format: None,
146 },
147 StatusBarWidgetConfig {
148 id: WidgetId::CpuUsage,
149 enabled: false,
150 section: StatusBarSection::Right,
151 order: 0,
152 format: None,
153 },
154 StatusBarWidgetConfig {
155 id: WidgetId::MemoryUsage,
156 enabled: false,
157 section: StatusBarSection::Right,
158 order: 1,
159 format: None,
160 },
161 StatusBarWidgetConfig {
162 id: WidgetId::NetworkStatus,
163 enabled: false,
164 section: StatusBarSection::Right,
165 order: 2,
166 format: None,
167 },
168 StatusBarWidgetConfig {
169 id: WidgetId::BellIndicator,
170 enabled: true,
171 section: StatusBarSection::Right,
172 order: 3,
173 format: None,
174 },
175 StatusBarWidgetConfig {
176 id: WidgetId::Clock,
177 enabled: true,
178 section: StatusBarSection::Right,
179 order: 4,
180 format: None,
181 },
182 ]
183}