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 shell_path: bool, #[serde(default)]
57 pub shell_version: bool, #[serde(default)]
59 pub uptime_shorthand: String, #[serde(default)]
61 pub os_age_shorthand: String, }
63
64#[derive(Debug, Deserialize, Clone)]
68pub struct Config {
69 #[serde(default, rename = "$schema")]
70 #[allow(dead_code)]
71 pub schema: Option<String>,
72 #[serde(default)]
73 #[allow(dead_code)]
74 pub logo: Option<Logo>,
75 #[serde(default)]
76 pub flags: Flags,
77 #[serde(default, alias = "layout", alias = "modules")]
78 pub layout: Vec<LayoutItem>,
79}
80
81#[derive(Debug, Deserialize, Clone, Default)]
83pub struct Logo {
84 #[serde(rename = "type", default)]
85 #[allow(dead_code)]
86 pub logo_type: Option<String>,
87 #[serde(default)]
88 #[allow(dead_code)]
89 pub source: Option<String>,
90}
91
92#[derive(Debug, Deserialize, Clone, Default)]
94pub struct ModuleEntry {
95 #[serde(rename = "type", default)]
96 pub module_type: Option<String>,
97 #[serde(default)]
98 pub key: Option<String>,
99 #[serde(default)]
100 pub label: Option<String>,
101 #[serde(default)]
102 pub field: Option<String>,
103 #[serde(default)]
104 pub format: Option<String>,
105 #[serde(default)]
106 pub text: Option<String>,
107}
108
109impl ModuleEntry {
110 pub fn field_name(&self) -> Option<&str> {
112 self.module_type
113 .as_deref()
114 .or(self.field.as_deref())
115 .map(str::trim)
116 .filter(|value| !value.is_empty())
117 }
118
119 pub fn label(&self) -> Option<&str> {
121 self.key.as_deref().or(self.label.as_deref())
122 }
123
124 pub fn is_custom(&self) -> bool {
126 self.field_name()
127 .map(|field| field.eq_ignore_ascii_case("custom"))
128 .unwrap_or(false)
129 }
130}
131
132impl Default for Flags {
133 fn default() -> Self {
134 Self {
135 ascii_distro: "auto".into(),
136 ascii_colors: "distro".into(),
137 custom_ascii_path: String::new(),
138 battery_display: "barinfo".into(),
139 color_blocks: "███".into(),
140 cpu_brand: true,
141 cpu_cores: true,
142 cpu_frequency: true,
143 cpu_speed: true,
144 cpu_temp: 'C',
145 cpu_show_temp: true,
146 de_version: true,
147 distro_display: "name_model_arch".into(),
148 disk_display: "barinfo".into(),
149 disk_subtitle: "dir".into(),
150 memory_percent: true,
151 memory_unit: "mib".into(),
152 package_managers: "tiny".into(),
153 shell_path: true,
154 shell_version: true,
155 uptime_shorthand: "full".into(),
156 os_age_shorthand: "full".into(),
157 }
158 }
159}
160
161