leenfetch_core/config/
settings.rs

1use serde::Deserialize;
2
3/// Describes a single entry in the `modules` array.
4/// Entries are either literal strings (used for `break`) or objects describing a module.
5#[derive(Debug, Deserialize, Clone)]
6#[serde(untagged)]
7pub enum LayoutItem {
8    /// Matches the literal string "break" (case insensitive) to insert a blank line.
9    Break(String),
10    /// A normal module configuration entry.
11    Module(ModuleEntry),
12}
13
14/// Fine-grained configuration for how each block is displayed.
15/// Most fields correspond to a feature or formatting option.
16#[derive(Debug, Deserialize, Clone)]
17pub struct Flags {
18    #[serde(default)]
19    pub ascii_distro: String, // Which distro's ASCII art to use ("auto" or a specific name)
20    #[serde(default)]
21    pub ascii_colors: String, // Which color palette to use ("distro", or a comma-separated list of color indices)
22    #[serde(default)]
23    pub battery_display: String, // Battery display mode ("off", "bar", "infobar", "barinfo")
24    #[serde(default)]
25    pub color_blocks: String, // String to use for color blocks (e.g., "███")
26    #[serde(default)]
27    pub cpu_brand: bool, // Show CPU brand prefix (true/false)
28    #[serde(default)]
29    pub cpu_cores: bool, // Show CPU core count (true/false)
30    #[serde(default)]
31    pub cpu_frequency: bool, // Show CPU frequency (true/false)
32    #[serde(default)]
33    pub cpu_speed: bool, // Show CPU speed (true/false)
34    #[serde(default)]
35    pub cpu_temp: char, // Temperature unit ('C', 'F', or 'off')
36    #[serde(default)]
37    pub cpu_show_temp: bool, // Show CPU temperature (true/false)
38    #[serde(default)]
39    pub custom_ascii_path: String, // Path to custom ASCII art file
40    #[serde(default)]
41    pub de_version: bool, // Show DE version (true/false)
42    #[serde(default)]
43    pub distro_display: String, // Distro display format (see DistroDisplay enum)
44    #[serde(default)]
45    pub disk_display: String, // Disk display format (see DiskDisplay enum)
46    #[serde(default)]
47    pub disk_subtitle: String, // Disk subtitle format (see DiskSubtitle enum)
48    #[serde(default)]
49    pub memory_percent: bool, // Show memory usage as percentage (true/false)
50    #[serde(default)]
51    pub memory_unit: String, // Memory unit ("kib", "mib", "gib")
52    #[serde(default)]
53    pub package_managers: String, // Package manager display (see PackageShorthand enum)
54    #[serde(default)]
55    pub refresh_rate: bool, // Show display refresh rate (true/false)
56    #[serde(default)]
57    pub shell_path: bool, // Show full shell path (true/false)
58    #[serde(default)]
59    pub shell_version: bool, // Show shell version (true/false)
60    #[serde(default)]
61    pub uptime_shorthand: String, // Uptime display format (see UptimeShorthand enum)
62    #[serde(default)]
63    pub os_age_shorthand: String, // Uptime display format (see OsAgeShorthand enum)
64}
65
66/// Root configuration structure that mirrors the JSONC config file.
67/// Missing sections fall back to their type defaults so that
68/// users can keep only the keys they care about.
69#[derive(Debug, Deserialize, Clone)]
70pub struct Config {
71    #[serde(default, rename = "$schema")]
72    #[allow(dead_code)]
73    pub schema: Option<String>,
74    #[serde(default)]
75    #[allow(dead_code)]
76    pub logo: Option<Logo>,
77    #[serde(default)]
78    pub flags: Flags,
79    #[serde(default, alias = "layout", alias = "modules")]
80    pub layout: Vec<LayoutItem>,
81}
82
83/// Minimal representation of the logo block. Extra fields are ignored automatically.
84#[derive(Debug, Deserialize, Clone, Default)]
85pub struct Logo {
86    #[serde(rename = "type", default)]
87    #[allow(dead_code)]
88    pub logo_type: Option<String>,
89    #[serde(default)]
90    #[allow(dead_code)]
91    pub source: Option<String>,
92}
93
94/// Configuration for an individual info module.
95#[derive(Debug, Deserialize, Clone, Default)]
96pub struct ModuleEntry {
97    #[serde(rename = "type", default)]
98    pub module_type: Option<String>,
99    #[serde(default)]
100    pub key: Option<String>,
101    #[serde(default)]
102    pub label: Option<String>,
103    #[serde(default)]
104    pub field: Option<String>,
105    #[serde(default)]
106    pub format: Option<String>,
107    #[serde(default)]
108    pub text: Option<String>,
109}
110
111impl ModuleEntry {
112    /// Returns the resolved field identifier used for data lookups.
113    pub fn field_name(&self) -> Option<&str> {
114        self.module_type
115            .as_deref()
116            .or(self.field.as_deref())
117            .map(str::trim)
118            .filter(|value| !value.is_empty())
119    }
120
121    /// Returns the label to render for this module, if any.
122    pub fn label(&self) -> Option<&str> {
123        self.key.as_deref().or(self.label.as_deref())
124    }
125
126    /// Returns true when the module is a custom text block.
127    pub fn is_custom(&self) -> bool {
128        self.field_name()
129            .map(|field| field.eq_ignore_ascii_case("custom"))
130            .unwrap_or(false)
131    }
132}
133
134impl Default for Flags {
135    fn default() -> Self {
136        Self {
137            ascii_distro: "auto".into(),
138            ascii_colors: "distro".into(),
139            custom_ascii_path: String::new(),
140            battery_display: "barinfo".into(),
141            color_blocks: "███".into(),
142            cpu_brand: true,
143            cpu_cores: true,
144            cpu_frequency: true,
145            cpu_speed: true,
146            cpu_temp: 'C',
147            cpu_show_temp: true,
148            de_version: true,
149            distro_display: "name_model_arch".into(),
150            disk_display: "barinfo".into(),
151            disk_subtitle: "dir".into(),
152            memory_percent: true,
153            memory_unit: "mib".into(),
154            package_managers: "tiny".into(),
155            refresh_rate: true,
156            shell_path: true,
157            shell_version: true,
158            uptime_shorthand: "full".into(),
159            os_age_shorthand: "full".into(),
160        }
161    }
162}
163
164// impl Default for Toggles {
165//     fn default() -> Self {
166//         Self {
167//             show_titles: true,
168//             show_os: true,
169//             show_distro: true,
170//             show_model: true,
171//             show_uptime: true,
172//             show_packages: true,
173//             show_shell: true,
174//             show_wm: true,
175//             show_de: true,
176//             show_kernel: true,
177//             show_cpu: true,
178//             show_gpu: true,
179//             show_memory: true,
180//             show_song: true,
181//             show_resolution: true,
182//             show_theme: true,
183//             show_disks: true,
184//             show_battery: true,
185//             show_terminal_colors: true,
186//         }
187//     }
188// }