Skip to main content

kimun_notes/settings/
icons.rs

1/// All icon strings used across the UI, resolved once from the `use_nerd_fonts` setting.
2///
3/// Build with [`Icons::new`] after loading settings, then pass `&Icons` (or a clone)
4/// wherever an icon is needed — no `use_nerd_fonts` checks at render time.
5#[derive(Clone)]
6pub struct Icons {
7    // File-list entry icons
8    pub directory: &'static str,
9    pub directory_up: &'static str,
10    pub note: &'static str,
11    pub journal: &'static str,
12    pub attachment: &'static str,
13    // UI chrome icons
14    pub info: &'static str,
15}
16
17impl Icons {
18    pub fn new(use_nerd_fonts: bool) -> Self {
19        if use_nerd_fonts {
20            Self {
21                directory: "󰉋",
22                directory_up: "󰁝",
23                note: "󰈙",
24                journal: "󰃭",
25                attachment: "",
26                info: "󰋽",
27            }
28        } else {
29            Self {
30                directory: "[D]",
31                directory_up: "[^]",
32                note: "[-]",
33                journal: "[J]",
34                attachment: "   ",
35                info: "(i)",
36            }
37        }
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn nerd_fonts_info_icon_is_not_ascii() {
47        let icons = Icons::new(true);
48        assert!(!icons.info.is_ascii());
49    }
50
51    #[test]
52    fn plain_icons_are_ascii() {
53        let icons = Icons::new(false);
54        assert!(icons.info.is_ascii());
55        assert!(icons.directory.is_ascii());
56        assert!(icons.directory_up.is_ascii());
57        assert!(icons.note.is_ascii());
58        assert!(icons.journal.is_ascii());
59    }
60}