lx_cli/
icon.rs

1/// Handles file type icons and their associated colors.
2use crate::config::{ColorConfig, IconColorConfig, IconConfig};
3use colored::Color;
4
5#[derive(Debug, Clone, Copy)]
6pub enum FileIcon {
7    Directory,
8    Executable,
9    RegularFile,
10}
11
12impl FileIcon {
13    pub fn as_str(&self) -> &str {
14        match self {
15            FileIcon::Directory => "",
16            FileIcon::Executable => "",
17            FileIcon::RegularFile => "",
18        }
19    }
20
21    pub fn as_str_custom(&self, config: &IconConfig) -> String {
22        match self {
23            FileIcon::Directory => config.get_directory_icon(),
24            FileIcon::Executable => config.get_executable_icon(),
25            FileIcon::RegularFile => config.get_regular_icon(),
26        }
27    }
28
29    pub fn get_color(&self, config: &ColorConfig) -> Color {
30        match self {
31            FileIcon::Directory => config.get_directory_color(),
32            FileIcon::Executable => config.get_executable_color(),
33            FileIcon::RegularFile => config.get_regular_color(),
34        }
35    }
36
37    pub fn get_icon_color(&self, config: &IconColorConfig) -> Color {
38        match self {
39            FileIcon::Directory => config.get_directory_color(),
40            FileIcon::Executable => config.get_executable_color(),
41            FileIcon::RegularFile => config.get_regular_color(),
42        }
43    }
44}