Skip to main content

cargo_plot/theme/
for_path_tree.rs

1// [ENG]: Path classification and icon mapping for tree visualization.
2// [POL]: Klasyfikacja ścieżek i mapowanie ikon dla wizualizacji drzewa.
3
4/// [ENG]: Global icon used for directory nodes.
5/// [POL]: Globalna ikona używana dla węzłów będących folderami.
6pub const DIR_ICON: &str = "📂";
7
8pub const FILE_ICON: &str = "📄";
9
10/// [ENG]: Defines visual and metadata properties for a file type.
11/// [POL]: Definiuje wizualne i metadanowe właściwości dla typu pliku.
12pub struct PathFileType {
13    pub icon: &'static str,
14    pub md_lang: &'static str,
15}
16
17/// [ENG]: Returns file properties based on its extension.
18/// [POL]: Zwraca właściwości pliku na podstawie jego rozszerzenia.
19#[must_use]
20pub fn get_file_type(ext: &str) -> PathFileType {
21    match ext {
22        "rs" => PathFileType {
23            icon: "🦀",
24            md_lang: "rust",
25        },
26        "toml" => PathFileType {
27            icon: "⚙️",
28            md_lang: "toml",
29        },
30        "slint" => PathFileType {
31            icon: "🎨",
32            md_lang: "slint",
33        },
34        "md" => PathFileType {
35            icon: "📝",
36            md_lang: "markdown",
37        },
38        "json" => PathFileType {
39            icon: "🔣",
40            md_lang: "json",
41        },
42        "yaml" | "yml" => PathFileType {
43            icon: "🛠️",
44            md_lang: "yaml",
45        },
46        "html" => PathFileType {
47            icon: "📖",
48            md_lang: "html",
49        },
50        "css" => PathFileType {
51            icon: "🖌️",
52            md_lang: "css",
53        },
54        "js" => PathFileType {
55            icon: "📜",
56            md_lang: "javascript",
57        },
58        "ts" => PathFileType {
59            icon: "📘",
60            md_lang: "typescript",
61        },
62        // [ENG]: Default fallback for unknown file types.
63        // [POL]: Domyślny fallback dla nieznanych typów plików.
64        _ => PathFileType {
65            icon: "📄",
66            md_lang: "text",
67        },
68    }
69}
70
71/// [ENG]: Character set used for drawing tree branches and indents.
72/// [POL]: Zestaw znaków używanych do rysowania gałęzi drzewa i wcięć.
73#[derive(Debug, Clone)]
74pub struct TreeStyle {
75    // [ENG]: Directories (d)
76    // [POL]: Foldery (d)
77    pub dir_last_with_children: String, // └──┬
78    pub dir_last_no_children: String,   // └───
79    pub dir_mid_with_children: String,  // ├──┬
80    pub dir_mid_no_children: String,    // ├───
81
82    // [ENG]: Files (f)
83    // [POL]: Pliki (f)
84    pub file_last: String, // └──•
85    pub file_mid: String,  // ├──•
86
87    // [ENG]: Indentations for subsequent levels (i)
88    // [POL]: Wcięcia dla kolejnych poziomów (i)
89    pub indent_last: String, // "   "
90    pub indent_mid: String,  // "│  "
91}
92
93impl Default for TreeStyle {
94    fn default() -> Self {
95        Self {
96            dir_last_with_children: "└──┬".to_string(),
97            dir_last_no_children: "└───".to_string(),
98            dir_mid_with_children: "├──┬".to_string(),
99            dir_mid_no_children: "├───".to_string(),
100
101            file_last: "└──•".to_string(),
102            file_mid: "├──•".to_string(),
103
104            indent_last: "   ".to_string(),
105            indent_mid: "│  ".to_string(),
106        }
107    }
108}