leenfetch_core/modules/
enums.rs

1use serde::{Deserialize, Serialize};
2use std::str::FromStr;
3
4/// Holds information about the currently playing song, if available.
5/// Used for the media/song block in the output.
6///
7/// - `artist`: Name of the artist (e.g., "Radiohead")
8/// - `album`: Name of the album (e.g., "OK Computer")
9/// - `title`: Title of the song (e.g., "Paranoid Android")
10#[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/// Controls how the package manager summary is displayed in the output.
19/// - Off: Only show the total package count.
20/// - On: Show a list of package managers and their counts.
21/// - Tiny: Show only the count and a compact list of manager names.
22#[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/// Controls the format of the distribution (distro) string in the output.
43/// Used to customize how much detail about the OS is shown.
44/// - Name: Only the distro name (e.g., "Arch Linux").
45/// - NameVersion: Name and version.
46/// - NameArch: Name and architecture.
47/// - NameModel: Name and model (e.g., LTS, Rolling).
48/// - NameModelVersion: Name, model, and version.
49/// - NameModelArch: Name, model, and architecture.
50/// - NameModelVersionArch: Name, model, version, and architecture. (default)
51#[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/// Controls the format of the uptime string in the output.
80/// - Full: Verbose (e.g., "1 day, 2 hours, 55 minutes"). (default)
81/// - Tiny: Compact (e.g., "1d 2h 55m").
82/// - Seconds: Only seconds (e.g., "123456s").
83#[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/// Controls the format of the OS age string in the output.
104/// - Full: Verbose (e.g., "123 days, 4 hours, 12 minutes"). (default)
105/// - Tiny: Compact (e.g., "123d 4h 12m").
106/// - Seconds: Only seconds (e.g., "10612345s").
107#[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/// Controls the unit used to display memory usage.
128/// - MiB: Mebibytes (default).
129/// - GiB: Gibibytes.
130/// - KiB: Kibibytes.
131#[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/// Controls the subtitle/label shown for each disk in the disk usage output.
152/// - Name: Show the device name (e.g., /dev/sda1).
153/// - Dir: Show the last directory in the mount path (e.g., "home" for /home). (default)
154/// - None: No subtitle.
155/// - Mount: Show the full mount point (e.g., /home).
156#[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/// Controls the format of the disk usage display.
179/// - Info: Show used/total (e.g., "40G / 100G").
180/// - Percentage: Show percent used and a bar (e.g., "40% [███]"). (default)
181/// - InfoBar: Show used/total and a bar (e.g., "40G / 100G [███]").
182/// - BarInfo: Show bar first, then used/total.
183/// - Bar: Show only the bar.
184pub enum DiskDisplay {
185    Info,
186    Percentage,
187    InfoBar,
188    BarInfo,
189    Bar,
190}
191
192impl FromStr for DiskDisplay {
193    type Err = ();
194
195    fn from_str(s: &str) -> Result<Self, Self::Err> {
196        match s.to_lowercase().as_str() {
197            "info" => Ok(DiskDisplay::Info),
198            "percentage" => Ok(DiskDisplay::Percentage),
199            "infobar" => Ok(DiskDisplay::InfoBar),
200            "barinfo" => Ok(DiskDisplay::BarInfo),
201            "bar" => Ok(DiskDisplay::Bar),
202            _ => Ok(DiskDisplay::InfoBar),
203        }
204    }
205}
206
207/// Controls how battery information is displayed.
208/// - Off: Only show percent and status (e.g., "85% [Charging]").
209/// - Bar: Show only a bar.
210/// - InfoBar: Show percent, status, and bar (e.g., "85% [Charging] [███]").
211/// - BarInfo: Show bar, percent, and status (e.g., "[███] 85% [Charging]"). (default)
212#[derive(Debug, Clone, Copy)]
213pub enum BatteryDisplayMode {
214    Off,
215    Bar,
216    InfoBar,
217    BarInfo,
218}
219
220impl FromStr for BatteryDisplayMode {
221    type Err = ();
222
223    fn from_str(s: &str) -> Result<Self, ()> {
224        match s.to_lowercase().as_str() {
225            "off" => Ok(BatteryDisplayMode::Off),
226            "bar" => Ok(BatteryDisplayMode::Bar),
227            "infobar" => Ok(BatteryDisplayMode::InfoBar),
228            "barinfo" => Ok(BatteryDisplayMode::BarInfo),
229            _ => Ok(BatteryDisplayMode::BarInfo),
230        }
231    }
232}