style: apply cargo fmt across all source files
Swadhin Biswas committed 7 months ago
95753c4
1 parent 05e809a
commit 95753c4
5 files changed
+40 -66
Showing 5 changed files+40-66
▼src/config/mod.rs
+6-15
| @@ -32,7 +32,6 @@ impl ColorConfig { | ||
32 | 32 | #[derive(Debug, Clone, Serialize, Deserialize)] |
33 | 33 | pub struct Config { |
34 | 34 | // ── Display options ────────────────────────────────────────── |
35 | - | |
36 | 35 | #[serde(default = "default_false")] |
37 | 36 | pub no_color: bool, |
38 | 37 | #[serde(default = "default_true")] |
| @@ -47,7 +46,6 @@ pub struct Config { | ||
47 | 46 | pub colors: ColorConfig, |
48 | 47 | |
49 | 48 | // ── ASCII / Logo options ───────────────────────────────────── |
50 | - | |
51 | 49 | /// Image backend: "ascii", "kitty", "sixel", "chafa", "off" |
52 | 50 | #[serde(default = "default_ascii")] |
53 | 51 | pub image_backend: String, |
| @@ -74,7 +72,6 @@ pub struct Config { | ||
74 | 72 | pub ascii_bold: bool, |
75 | 73 | |
76 | 74 | // ── Image options ──────────────────────────────────────────── |
77 | - | |
78 | 75 | /// Path to custom image to display (for kitty/sixel/chafa backends) |
79 | 76 | #[serde(default)] |
80 | 77 | pub custom_image: Option<String>, |
| @@ -92,7 +89,6 @@ pub struct Config { | ||
92 | 89 | pub crop_offset: String, |
93 | 90 | |
94 | 91 | // ── Extra features ─────────────────────────────────────────── |
95 | - | |
96 | 92 | /// Use emoji art instead of ASCII art |
97 | 93 | #[serde(default = "default_false")] |
98 | 94 | pub emoji_mode: bool, |
| @@ -102,7 +98,6 @@ pub struct Config { | ||
102 | 98 | pub nerd_font: bool, |
103 | 99 | |
104 | 100 | // ── Layout ─────────────────────────────────────────────────── |
105 | - | |
106 | 101 | /// Gap between logo and info text (in chars) |
107 | 102 | #[serde(default = "default_gap")] |
108 | 103 | pub gap: usize, |
| @@ -112,7 +107,6 @@ pub struct Config { | ||
112 | 107 | pub logo_only: bool, |
113 | 108 | |
114 | 109 | // ── Info field toggles ─────────────────────────────────────── |
115 | - | |
116 | 110 | #[serde(default = "default_true")] |
117 | 111 | pub show_title: bool, |
118 | 112 | #[serde(default = "default_true")] |
| @@ -169,7 +163,6 @@ pub struct Config { | ||
169 | 163 | pub show_colors: bool, |
170 | 164 | |
171 | 165 | // ── Progress bars ──────────── ──────────────────────────────── |
172 | - | |
173 | 166 | /// Show progress bar next to memory percentage |
174 | 167 | #[serde(default = "default_false")] |
175 | 168 | pub memory_bar: bool, |
| @@ -183,7 +176,6 @@ pub struct Config { | ||
183 | 176 | pub bar_width: usize, |
184 | 177 | |
185 | 178 | // ── Color blocks ───────────────────────────────────────────── |
186 | - | |
187 | 179 | #[serde(default = "default_block_range")] |
188 | 180 | pub block_range: (u8, u8), |
189 | 181 | #[serde(default = "default_block_width")] |
| @@ -192,13 +184,11 @@ pub struct Config { | ||
192 | 184 | pub block_height: usize, |
193 | 185 | |
194 | 186 | // ── Underline ──────────────────────────────────────────────── |
195 | - | |
196 | 187 | /// Underline character (neofetch defaults to "-") |
197 | 188 | #[serde(default = "default_underline_char")] |
198 | 189 | pub underline_char: String, |
199 | 190 | |
200 | 191 | // ── Misc ───────────────────────────────────────────────────── |
201 | - | |
202 | 192 | /// Stdout mode — disable colors & image backend (for piping) |
203 | 193 | #[serde(default = "default_false")] |
204 | 194 | pub stdout: bool, |
| @@ -321,10 +311,7 @@ impl Config { | ||
321 | 311 | match toml::from_str::<Config>(&content) { |
322 | 312 | Ok(config) => return config, |
323 | 313 | Err(e) => { |
324 | - eprintln!( | |
325 | - "\x1b[33m[fetchx] Warning: config parse error: {}\x1b[0m", | |
326 | - e | |
327 | - ); | |
314 | + eprintln!("\x1b[33m[fetchx] Warning: config parse error: {}\x1b[0m", e); | |
328 | 315 | eprintln!( |
329 | 316 | "\x1b[33m[fetchx] Using default config. Fix: {}\x1b[0m", |
330 | 317 | path.display() |
| @@ -638,7 +625,11 @@ mod tests { | ||
638 | 625 | #[test] |
639 | 626 | fn test_example_config_is_valid_toml() { |
640 | 627 | let result = toml::from_str::<Config>(EXAMPLE_CONFIG); |
641 | - assert!(result.is_ok(), "EXAMPLE_CONFIG is not valid: {:?}", result.err()); | |
628 | + assert!( | |
629 | + result.is_ok(), | |
630 | + "EXAMPLE_CONFIG is not valid: {:?}", | |
631 | + result.err() | |
632 | + ); | |
642 | 633 | } |
643 | 634 | |
644 | 635 | #[test] |
645 | 636 | |
▼src/display/mod.rs
+9-11
| @@ -511,12 +511,13 @@ impl Display { | ||
511 | 511 | // Memory — optionally with progress bar |
512 | 512 | if self.config.show_memory && sys.memory != "Unknown" && !sys.memory.is_empty() { |
513 | 513 | if self.config.memory_bar { |
514 | - let bar = colors::progress_bar( | |
515 | - sys.memory_percent, | |
516 | - self.config.bar_width, | |
517 | - &scheme.c[0], | |
518 | - ); | |
519 | - lines.push(field("Memory", "\u{f85a}", &format!("{} {}", sys.memory, bar))); | |
514 | + let bar = | |
515 | + colors::progress_bar(sys.memory_percent, self.config.bar_width, &scheme.c[0]); | |
516 | + lines.push(field( | |
517 | + "Memory", | |
518 | + "\u{f85a}", | |
519 | + &format!("{} {}", sys.memory, bar), | |
520 | + )); | |
520 | 521 | } else { |
521 | 522 | lines.push(field("Memory", "\u{f85a}", &sys.memory)); |
522 | 523 | } |
| @@ -525,11 +526,8 @@ impl Display { | ||
525 | 526 | // Disk — optionally with progress bar |
526 | 527 | if self.config.show_disk && sys.disk != "Unknown" && !sys.disk.is_empty() { |
527 | 528 | if self.config.disk_bar { |
528 | - let bar = colors::progress_bar( | |
529 | - sys.disk_percent, | |
530 | - self.config.bar_width, | |
531 | - &scheme.c[0], | |
532 | - ); | |
529 | + let bar = | |
530 | + colors::progress_bar(sys.disk_percent, self.config.bar_width, &scheme.c[0]); | |
533 | 531 | lines.push(field("Disk", "\u{f0a0}", &format!("{} {}", sys.disk, bar))); |
534 | 532 | } else { |
535 | 533 | lines.push(field("Disk", "\u{f0a0}", &sys.disk)); |
536 | 534 | |
▼src/image_backend/mod.rs
+9-29
| @@ -41,19 +41,14 @@ impl Backend { | ||
41 | 41 | Backend::Kitty => { |
42 | 42 | // Kitty is supported if TERM contains "kitty" or KITTY_PID is set |
43 | 43 | std::env::var("KITTY_PID").is_ok() |
44 | - || std::env::var("TERM") | |
45 | - .unwrap_or_default() | |
46 | - .contains("kitty") | |
44 | + || std::env::var("TERM").unwrap_or_default().contains("kitty") | |
47 | 45 | || std::env::var("TERM_PROGRAM") |
48 | 46 | .unwrap_or_default() |
49 | 47 | .contains("kitty") |
50 | 48 | } |
51 | 49 | Backend::Sixel => { |
52 | 50 | // Check if img2sixel or ImageMagick convert is available |
53 | - Command::new("img2sixel") | |
54 | - .arg("--version") | |
55 | - .output() | |
56 | - .is_ok() | |
51 | + Command::new("img2sixel").arg("--version").output().is_ok() | |
57 | 52 | } |
58 | 53 | Backend::Chafa => Command::new("chafa") |
59 | 54 | .arg("--version") |
| @@ -61,11 +56,9 @@ impl Backend { | ||
61 | 56 | .map(|o| o.status.success()) |
62 | 57 | .unwrap_or(false), |
63 | 58 | Backend::W3m => w3m_img_path().is_some(), |
64 | - Backend::Iterm2 => { | |
65 | - std::env::var("TERM_PROGRAM") | |
66 | - .unwrap_or_default() | |
67 | - .contains("iTerm") | |
68 | - } | |
59 | + Backend::Iterm2 => std::env::var("TERM_PROGRAM") | |
60 | + .unwrap_or_default() | |
61 | + .contains("iTerm"), | |
69 | 62 | } |
70 | 63 | } |
71 | 64 | } |
| @@ -272,11 +265,7 @@ pub fn display_chafa( | ||
272 | 265 | } |
273 | 266 | |
274 | 267 | /// Display an image using sixel (via img2sixel). |
275 | -pub fn display_sixel( | |
276 | - image_path: &str, | |
277 | - max_cols: usize, | |
278 | - _max_rows: usize, | |
279 | -) -> Result<(), String> { | |
268 | +pub fn display_sixel(image_path: &str, max_cols: usize, _max_rows: usize) -> Result<(), String> { | |
280 | 269 | let path = Path::new(image_path); |
281 | 270 | if !path.exists() { |
282 | 271 | return Err(format!("Image not found: {}", image_path)); |
| @@ -380,11 +369,7 @@ fn w3m_img_path() -> Option<String> { | ||
380 | 369 | /// w3m uses a helper binary that accepts commands on stdin: |
381 | 370 | /// 0;1;x;y;w;h;sx;sy;sw;sh;path\n (draw) |
382 | 371 | /// 6;offset_x;offset_y;width;height\n (sync) |
383 | -pub fn display_w3m( | |
384 | - image_path: &str, | |
385 | - max_cols: usize, | |
386 | - max_rows: usize, | |
387 | -) -> Result<(), String> { | |
372 | +pub fn display_w3m(image_path: &str, max_cols: usize, max_rows: usize) -> Result<(), String> { | |
388 | 373 | let path = Path::new(image_path); |
389 | 374 | if !path.exists() { |
390 | 375 | return Err(format!("Image not found: {}", image_path)); |
| @@ -454,18 +439,13 @@ pub fn display_w3m( | ||
454 | 439 | |
455 | 440 | /// Display an image using iTerm2's inline image protocol. |
456 | 441 | /// Format: \x1b]1337;File=inline=1;width=Ncells;height=Nrows;preserveAspectRatio=1:<base64>\x07 |
457 | -pub fn display_iterm2( | |
458 | - image_path: &str, | |
459 | - max_cols: usize, | |
460 | - max_rows: usize, | |
461 | -) -> Result<(), String> { | |
442 | +pub fn display_iterm2(image_path: &str, max_cols: usize, max_rows: usize) -> Result<(), String> { | |
462 | 443 | let path = Path::new(image_path); |
463 | 444 | if !path.exists() { |
464 | 445 | return Err(format!("Image not found: {}", image_path)); |
465 | 446 | } |
466 | 447 | |
467 | - let file_data = | |
468 | - std::fs::read(path).map_err(|e| format!("Failed to read image: {}", e))?; | |
448 | + let file_data = std::fs::read(path).map_err(|e| format!("Failed to read image: {}", e))?; | |
469 | 449 | let encoded = base64::engine::general_purpose::STANDARD.encode(&file_data); |
470 | 450 | let file_size = file_data.len(); |
471 | 451 | |
472 | 452 | |
▼src/image_cache.rs
+4-7
| @@ -55,8 +55,8 @@ pub fn download_image_from_api() -> Result<(), Box<dyn std::error::Error>> { | ||
55 | 55 | } |
56 | 56 | |
57 | 57 | // Decode whatever format API sends (webp/jpeg/png) and save as PNG |
58 | - let img = image::load_from_memory(&bytes) | |
59 | - .map_err(|e| format!("Failed to decode image: {}", e))?; | |
58 | + let img = | |
59 | + image::load_from_memory(&bytes).map_err(|e| format!("Failed to decode image: {}", e))?; | |
60 | 60 | |
61 | 61 | // Write to temp file first, then rename — so display never sees a half-written file |
62 | 62 | let cache = cache_dir(); |
| @@ -126,8 +126,7 @@ fn get_hyprland_wallpaper() -> Option<PathBuf> { | ||
126 | 126 | } |
127 | 127 | |
128 | 128 | // Try hyprpaper config |
129 | - let hyprpaper_config = dirs::config_dir() | |
130 | - .map(|d| d.join("hypr/hyprpaper.conf"))?; | |
129 | + let hyprpaper_config = dirs::config_dir().map(|d| d.join("hypr/hyprpaper.conf"))?; | |
131 | 130 | |
132 | 131 | if let Ok(content) = fs::read_to_string(&hyprpaper_config) { |
133 | 132 | for line in content.lines() { |
| @@ -169,8 +168,7 @@ fn get_gnome_wallpaper() -> Option<PathBuf> { | ||
169 | 168 | |
170 | 169 | /// Get KDE wallpaper from config |
171 | 170 | fn get_kde_wallpaper() -> Option<PathBuf> { |
172 | - let kde_config = dirs::config_dir() | |
173 | - .map(|d| d.join("plasmarc"))?; | |
171 | + let kde_config = dirs::config_dir().map(|d| d.join("plasmarc"))?; | |
174 | 172 | |
175 | 173 | if let Ok(content) = fs::read_to_string(&kde_config) { |
176 | 174 | for line in content.lines() { |
| @@ -226,7 +224,6 @@ fn expand_path(path: &str) -> PathBuf { | ||
226 | 224 | } |
227 | 225 | } |
228 | 226 | |
229 | - | |
230 | 227 | pub fn get_available_image() -> Option<PathBuf> { |
231 | 228 | let cache = cached_image_path(); |
232 | 229 | if cache.exists() { |
233 | 230 | |
▼src/main.rs
+12-4
| @@ -389,7 +389,8 @@ fn update_config_image(image_path: &str) { | ||
389 | 389 | let updated = if content.contains("custom_image") { |
390 | 390 | // Simple replacement: find and replace the custom_image line |
391 | 391 | let lines: Vec<&str> = content.lines().collect(); |
392 | - let new_lines: Vec<String> = lines.iter() | |
392 | + let new_lines: Vec<String> = lines | |
393 | + .iter() | |
393 | 394 | .map(|line| { |
394 | 395 | if line.starts_with("custom_image") { |
395 | 396 | format!(r#"custom_image = "{}""#, image_path) |
| @@ -473,8 +474,14 @@ fn show_tray_status() { | ||
473 | 474 | Ok(status) => { |
474 | 475 | // Compact format for tray/widgets |
475 | 476 | let cpu = status.get("cpu").and_then(|v| v.as_str()).unwrap_or("N/A"); |
476 | - let mem = status.get("memory").and_then(|v| v.as_str()).unwrap_or("N/A"); | |
477 | - let host = status.get("hostname").and_then(|v| v.as_str()).unwrap_or("Unknown"); | |
477 | + let mem = status | |
478 | + .get("memory") | |
479 | + .and_then(|v| v.as_str()) | |
480 | + .unwrap_or("N/A"); | |
481 | + let host = status | |
482 | + .get("hostname") | |
483 | + .and_then(|v| v.as_str()) | |
484 | + .unwrap_or("Unknown"); | |
478 | 485 | |
479 | 486 | // Format: Host | CPU: 45% | RAM: 8.2GB/16GB |
480 | 487 | println!("{} | CPU: {} | RAM: {}", host, cpu, mem); |
| @@ -502,7 +509,8 @@ fn init_api_image_config() { | ||
502 | 509 | // Replace existing config |
503 | 510 | let mut lines: Vec<String> = content.lines().map(|s| s.to_string()).collect(); |
504 | 511 | |
505 | - lines = lines.iter() | |
512 | + lines = lines | |
513 | + .iter() | |
506 | 514 | .map(|line| { |
507 | 515 | if line.starts_with("image_backend") { |
508 | 516 | r#"image_backend = "auto""#.to_string() |
509 | 517 | |