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 UpdateAvailable,
45 Custom(String),
47}
48
49impl WidgetId {
50 pub fn label(&self) -> &str {
52 match self {
53 WidgetId::Clock => "Clock",
54 WidgetId::UsernameHostname => "User@Host",
55 WidgetId::CurrentDirectory => "Directory",
56 WidgetId::GitBranch => "Git Branch",
57 WidgetId::CpuUsage => "CPU Usage",
58 WidgetId::MemoryUsage => "Memory Usage",
59 WidgetId::NetworkStatus => "Network Status",
60 WidgetId::BellIndicator => "Bell Indicator",
61 WidgetId::CurrentCommand => "Current Command",
62 WidgetId::UpdateAvailable => "Update Available",
63 WidgetId::Custom(name) => name.as_str(),
64 }
65 }
66
67 pub fn icon(&self) -> &str {
69 match self {
70 WidgetId::Clock => "\u{1f551}", WidgetId::UsernameHostname => "\u{1f464}", WidgetId::CurrentDirectory => "\u{1f4c2}", WidgetId::GitBranch => "\u{1f500}", WidgetId::CpuUsage => "\u{1f4bb}", WidgetId::MemoryUsage => "\u{1f4be}", WidgetId::NetworkStatus => "\u{1f310}", WidgetId::BellIndicator => "\u{1f514}", WidgetId::CurrentCommand => "\u{25b6}", WidgetId::UpdateAvailable => "\u{2b06}", WidgetId::Custom(_) => "\u{2699}", }
82 }
83
84 pub fn needs_system_monitor(&self) -> bool {
86 matches!(
87 self,
88 WidgetId::CpuUsage | WidgetId::MemoryUsage | WidgetId::NetworkStatus
89 )
90 }
91}
92
93#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
95pub struct StatusBarWidgetConfig {
96 pub id: WidgetId,
98 #[serde(default = "default_true")]
100 pub enabled: bool,
101 #[serde(default)]
103 pub section: StatusBarSection,
104 #[serde(default)]
106 pub order: i32,
107 #[serde(default, skip_serializing_if = "Option::is_none")]
109 pub format: Option<String>,
110}
111
112fn default_true() -> bool {
113 true
114}
115
116pub fn default_widgets() -> Vec<StatusBarWidgetConfig> {
122 vec![
123 StatusBarWidgetConfig {
124 id: WidgetId::UsernameHostname,
125 enabled: true,
126 section: StatusBarSection::Left,
127 order: 0,
128 format: None,
129 },
130 StatusBarWidgetConfig {
131 id: WidgetId::CurrentDirectory,
132 enabled: true,
133 section: StatusBarSection::Left,
134 order: 1,
135 format: None,
136 },
137 StatusBarWidgetConfig {
138 id: WidgetId::GitBranch,
139 enabled: true,
140 section: StatusBarSection::Left,
141 order: 2,
142 format: None,
143 },
144 StatusBarWidgetConfig {
145 id: WidgetId::CurrentCommand,
146 enabled: true,
147 section: StatusBarSection::Center,
148 order: 0,
149 format: None,
150 },
151 StatusBarWidgetConfig {
152 id: WidgetId::CpuUsage,
153 enabled: false,
154 section: StatusBarSection::Right,
155 order: 0,
156 format: None,
157 },
158 StatusBarWidgetConfig {
159 id: WidgetId::MemoryUsage,
160 enabled: false,
161 section: StatusBarSection::Right,
162 order: 1,
163 format: None,
164 },
165 StatusBarWidgetConfig {
166 id: WidgetId::NetworkStatus,
167 enabled: false,
168 section: StatusBarSection::Right,
169 order: 2,
170 format: None,
171 },
172 StatusBarWidgetConfig {
173 id: WidgetId::BellIndicator,
174 enabled: true,
175 section: StatusBarSection::Right,
176 order: 3,
177 format: None,
178 },
179 StatusBarWidgetConfig {
180 id: WidgetId::Clock,
181 enabled: true,
182 section: StatusBarSection::Right,
183 order: 4,
184 format: None,
185 },
186 StatusBarWidgetConfig {
187 id: WidgetId::UpdateAvailable,
188 enabled: true,
189 section: StatusBarSection::Right,
190 order: 5,
191 format: None,
192 },
193 ]
194}