leenfetch_core/config/
settings.rs1use serde::Deserialize;
2
3#[derive(Debug, Deserialize, Clone)]
6#[serde(untagged)]
7pub enum LayoutItem {
8 Break(String),
10 Module(ModuleEntry),
12}
13
14#[derive(Debug, Deserialize, Clone)]
17pub struct Flags {
18 #[serde(default)]
19 pub ascii_distro: String, #[serde(default)]
21 pub ascii_colors: String, #[serde(default)]
23 pub battery_display: String, #[serde(default)]
25 pub color_blocks: String, #[serde(default)]
27 pub cpu_brand: bool, #[serde(default)]
29 pub cpu_cores: bool, #[serde(default)]
31 pub cpu_frequency: bool, #[serde(default)]
33 pub cpu_speed: bool, #[serde(default)]
35 pub cpu_temp: char, #[serde(default)]
37 pub cpu_show_temp: bool, #[serde(default)]
39 pub custom_ascii_path: String, #[serde(default)]
41 pub de_version: bool, #[serde(default)]
43 pub distro_display: String, #[serde(default)]
45 pub disk_display: String, #[serde(default)]
47 pub disk_subtitle: String, #[serde(default)]
49 pub memory_percent: bool, #[serde(default)]
51 pub memory_unit: String, #[serde(default)]
53 pub package_managers: String, #[serde(default)]
55 pub refresh_rate: bool, #[serde(default)]
57 pub shell_path: bool, #[serde(default)]
59 pub shell_version: bool, #[serde(default)]
61 pub uptime_shorthand: String, #[serde(default)]
63 pub os_age_shorthand: String, }
65
66#[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#[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#[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 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 pub fn label(&self) -> Option<&str> {
123 self.key.as_deref().or(self.label.as_deref())
124 }
125
126 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