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    pub workspace: &'static str,
16}
17
18impl Icons {
19    pub fn new(use_nerd_fonts: bool) -> Self {
20        if use_nerd_fonts {
21            Self {
22                directory: "󰉋",
23                directory_up: "󰁝",
24                note: "󰈙",
25                journal: "󰃭",
26                attachment: "",
27                info: "󰋽",
28                workspace: " ",
29            }
30        } else {
31            Self {
32                directory: "[D]",
33                directory_up: "[^]",
34                note: "[-]",
35                journal: "[J]",
36                attachment: "   ",
37                info: "(i)",
38                workspace: "W",
39            }
40        }
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn nerd_fonts_info_icon_is_not_ascii() {
50        let icons = Icons::new(true);
51        assert!(!icons.info.is_ascii());
52    }
53
54    #[test]
55    fn plain_icons_are_ascii() {
56        let icons = Icons::new(false);
57        assert!(icons.info.is_ascii());
58        assert!(icons.directory.is_ascii());
59        assert!(icons.directory_up.is_ascii());
60        assert!(icons.note.is_ascii());
61        assert!(icons.journal.is_ascii());
62    }
63}