Skip to main content

rom_core/
icons.rs

1//! Icon sets for ROM display output.
2//!
3//! Two sets are available: Unicode (standard, widely supported) and Nerd Fonts
4//! (requires a patched font, detected automatically via `has-nerd-font`).
5
6/// A complete set of display icons.
7pub struct Icons {
8  pub running:  &'static str,
9  pub done:     &'static str,
10  pub planned:  &'static str,
11  pub failed:   &'static str,
12  pub download: &'static str,
13  pub upload:   &'static str,
14  pub clock:    &'static str,
15  pub estimate: &'static str,
16  pub summary:  &'static str,
17}
18
19/// Standard Unicode icons are always available, no special font required.
20pub static UNICODE: Icons = Icons {
21  running:  "⏵",
22  done:     "✔",
23  planned:  "⏸",
24  failed:   "✗",
25  download: "↓",
26  upload:   "↑",
27  clock:    "⏱",
28  estimate: "∅",
29  summary:  "∑",
30};
31
32/// Nerd Fonts icons.
33///
34/// Requires a Nerd Font–patched terminal font. Detected automatically via
35/// the `has-nerd-font` crate, but can be forced with `NERD_FONTS=1` (or
36/// disabled with `NERD_FONTS=0`).
37pub static NERD: Icons = Icons {
38  running:  "\u{f04b}",  // 
39  done:     "\u{f00c}",  // 
40  planned:  "\u{f04c}",  // 
41  failed:   "\u{f071}",  // 
42  download: "\u{f063}",  // 
43  upload:   "\u{f062}",  // 
44  clock:    "\u{f1da}",  // 
45  estimate: "\u{f252}",  // 
46  summary:  "\u{f04a0}", // 󰒠
47};
48
49/// Detect the best icon set for the current terminal session.
50///
51/// Checks `NERD_FONTS` env override first (`1` forces Nerd, `0` forces
52/// Unicode), then delegates to `has-nerd-font` for automatic detection.
53pub fn detect() -> &'static Icons {
54  // Manual override takes precedence
55  if let Ok(v) = std::env::var("NERD_FONTS") {
56    match v.trim() {
57      "1" | "true" | "yes" => return &NERD,
58      "0" | "false" | "no" => return &UNICODE,
59      _ => {},
60    }
61  }
62
63  let vars: Vec<(String, String)> = std::env::vars().collect();
64  match has_nerd_font::detect(&vars).detected {
65    Some(true) => &NERD,
66    _ => &UNICODE,
67  }
68}