1use serde::{Deserialize, Serialize};
2use std::str::FromStr;
3
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
11#[allow(dead_code)]
12pub struct SongInfo {
13 pub artist: String,
14 pub album: String,
15 pub title: String,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq)]
23pub enum PackageShorthand {
24 Off,
25 On,
26 Tiny,
27}
28
29impl FromStr for PackageShorthand {
30 type Err = ();
31
32 fn from_str(s: &str) -> Result<Self, ()> {
33 match s.to_lowercase().as_str() {
34 "off" => Ok(PackageShorthand::Off),
35 "on" => Ok(PackageShorthand::On),
36 "tiny" => Ok(PackageShorthand::Tiny),
37 _ => Ok(PackageShorthand::On),
38 }
39 }
40}
41
42#[derive(Debug, Clone, Copy, PartialEq)]
52pub enum DistroDisplay {
53 Name,
54 NameVersion,
55 NameArch,
56 NameModel,
57 NameModelVersion,
58 NameModelArch,
59 NameModelVersionArch,
60}
61
62impl std::str::FromStr for DistroDisplay {
63 type Err = ();
64
65 fn from_str(s: &str) -> Result<Self, ()> {
66 match s.to_lowercase().as_str() {
67 "name" => Ok(DistroDisplay::Name),
68 "name_version" => Ok(DistroDisplay::NameVersion),
69 "name_arch" => Ok(DistroDisplay::NameArch),
70 "name_model" => Ok(DistroDisplay::NameModel),
71 "name_model_version" => Ok(DistroDisplay::NameModelVersion),
72 "name_model_arch" => Ok(DistroDisplay::NameModelArch),
73 "name_model_version_arch" => Ok(DistroDisplay::NameModelVersionArch),
74 _ => Err(()),
75 }
76 }
77}
78
79#[derive(Debug, Clone, Copy, PartialEq)]
84pub enum UptimeShorthand {
85 Full,
86 Tiny,
87 Seconds,
88}
89
90impl FromStr for UptimeShorthand {
91 type Err = ();
92
93 fn from_str(s: &str) -> Result<Self, Self::Err> {
94 match s.to_lowercase().as_str() {
95 "full" => Ok(UptimeShorthand::Full),
96 "tiny" => Ok(UptimeShorthand::Tiny),
97 "seconds" => Ok(UptimeShorthand::Seconds),
98 _ => Ok(UptimeShorthand::Full),
99 }
100 }
101}
102
103#[derive(Debug, Clone, Copy, PartialEq)]
108pub enum OsAgeShorthand {
109 Full,
110 Tiny,
111 Seconds,
112}
113
114impl FromStr for OsAgeShorthand {
115 type Err = ();
116
117 fn from_str(s: &str) -> Result<Self, Self::Err> {
118 match s.to_lowercase().as_str() {
119 "full" => Ok(Self::Full),
120 "tiny" => Ok(Self::Tiny),
121 "seconds" => Ok(Self::Seconds),
122 _ => Ok(Self::Full),
123 }
124 }
125}
126
127#[derive(Debug, Clone, Copy)]
132pub enum MemoryUnit {
133 MiB,
134 GiB,
135 KiB,
136}
137
138impl FromStr for MemoryUnit {
139 type Err = ();
140
141 fn from_str(s: &str) -> Result<Self, ()> {
142 match s.to_lowercase().as_str() {
143 "mib" => Ok(MemoryUnit::MiB),
144 "gib" => Ok(MemoryUnit::GiB),
145 "kib" => Ok(MemoryUnit::KiB),
146 _ => Ok(MemoryUnit::MiB),
147 }
148 }
149}
150
151#[derive(Debug, Clone, Copy)]
157pub enum DiskSubtitle {
158 Name,
159 Dir,
160 None,
161 Mount,
162}
163
164impl FromStr for DiskSubtitle {
165 type Err = ();
166
167 fn from_str(s: &str) -> Result<Self, Self::Err> {
168 match s.to_lowercase().as_str() {
169 "name" => Ok(DiskSubtitle::Name),
170 "dir" => Ok(DiskSubtitle::Dir),
171 "none" => Ok(DiskSubtitle::None),
172 "mount" => Ok(DiskSubtitle::Mount),
173 _ => Ok(DiskSubtitle::Dir),
174 }
175 }
176}
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq)]
180pub enum DiskDisplayPart {
181 Info,
182 Percentage,
183 Bar,
184}
185
186pub fn parse_disk_display_parts(spec: &str) -> Result<Vec<DiskDisplayPart>, String> {
187 let mut parts = Vec::new();
188
189 for token in spec.split(',') {
190 let normalized = token.trim().to_ascii_lowercase();
191 if normalized.is_empty() {
192 continue;
193 }
194
195 match normalized.as_str() {
196 "info" => parts.push(DiskDisplayPart::Info),
197 "percentage" => parts.push(DiskDisplayPart::Percentage),
198 "bar" => parts.push(DiskDisplayPart::Bar),
199 _ => return Err(format!("invalid disk_display part: {normalized}")),
200 }
201 }
202
203 if parts.is_empty() {
204 return Err("disk_display is empty".to_string());
205 }
206
207 Ok(parts)
208}
209
210#[derive(Debug, Clone, Copy)]
216pub enum BatteryDisplayMode {
217 Off,
218 Bar,
219 InfoBar,
220 BarInfo,
221}
222
223impl FromStr for BatteryDisplayMode {
224 type Err = ();
225
226 fn from_str(s: &str) -> Result<Self, ()> {
227 match s.to_lowercase().as_str() {
228 "off" => Ok(BatteryDisplayMode::Off),
229 "bar" => Ok(BatteryDisplayMode::Bar),
230 "infobar" => Ok(BatteryDisplayMode::InfoBar),
231 "barinfo" => Ok(BatteryDisplayMode::BarInfo),
232 _ => Ok(BatteryDisplayMode::BarInfo),
233 }
234 }
235}