use ratatui::style::Color;
use crate::lsp::manager::OutlineKind;
pub struct Icon {
pub glyph: char,
pub color: Color,
}
const fn rgb(r: u8, g: u8, b: u8) -> Color {
Color::Rgb(r, g, b)
}
pub const FOLDER_CLOSED: Icon = Icon {
glyph: '\u{ea83}',
color: rgb(0xdc, 0xb6, 0x7a),
};
pub const FOLDER_OPEN: Icon = Icon {
glyph: '\u{eaf7}',
color: rgb(0xdc, 0xb6, 0x7a),
};
pub const DEFAULT_FILE: Icon = Icon {
glyph: '\u{ea7b}',
color: rgb(0xcc, 0xcc, 0xcc),
};
pub const CHEVRON_CLOSED: char = '▸';
pub const CHEVRON_OPEN: char = '▾';
pub const ACTIVITY_EXPLORER: char = '\u{eaf0}';
pub const ACTIVITY_SEARCH: char = '\u{ea6d}';
pub const ACTIVITY_REMOTE: char = '\u{eb39}';
pub const ACTIVITY_SOURCE_CONTROL: char = '\u{ea68}';
pub const ACTIVITY_RUN_DEBUG: char = '\u{eb91}';
pub const ACTIVITY_EXTENSIONS: char = '\u{eae6}';
pub const ACTIVITY_TESTING: char = '\u{ea79}';
pub const ACTIVITY_CODEQL: char = 'Q';
pub const SEARCH_REPLACE_ALL: char = '\u{eb3c}';
pub const SEARCH_REPLACE: char = '\u{eb3d}';
pub const SEARCH_ELLIPSIS: char = '\u{ea7c}';
pub const SEARCH_REFRESH: char = '\u{eb37}';
pub const SEARCH_CLEAR_ALL: char = '\u{eabf}';
pub const ACTIVITY_SETTINGS: char = '\u{eb51}';
pub const LAYOUT_SIDEBAR_ON: char = '\u{ebf3}';
pub const LAYOUT_SIDEBAR_OFF: char = '\u{ec02}';
pub const LAYOUT_PANEL_ON: char = '\u{ebf2}';
pub const LAYOUT_PANEL_OFF: char = '\u{ec01}';
pub const LAYOUT_CUSTOMIZE: char = '\u{ebeb}';
pub fn for_outline_kind(kind: OutlineKind) -> Icon {
const PURPLE: Color = rgb(0xB1, 0x80, 0xD7); const ORANGE: Color = rgb(0xEE, 0x9D, 0x28); const BLUE: Color = rgb(0x75, 0xBE, 0xFF); const GREY: Color = rgb(0xCC, 0xCC, 0xCC); let (glyph, color) = match kind {
OutlineKind::Method | OutlineKind::Function | OutlineKind::Constructor => {
('\u{ea8c}', PURPLE)
}
OutlineKind::Event => ('\u{ea86}', PURPLE),
OutlineKind::Operator => ('\u{eb64}', PURPLE),
OutlineKind::Class => ('\u{eb5b}', ORANGE),
OutlineKind::Enum => ('\u{ea95}', ORANGE),
OutlineKind::Interface => ('\u{eb61}', BLUE),
OutlineKind::Field => ('\u{eb5f}', BLUE),
OutlineKind::Variable => ('\u{ea88}', BLUE),
OutlineKind::Constant => ('\u{eb5d}', BLUE),
OutlineKind::Property => ('\u{eb65}', BLUE),
OutlineKind::EnumMember => ('\u{eb5e}', BLUE),
OutlineKind::TypeParameter => ('\u{ea92}', BLUE),
OutlineKind::Struct => ('\u{ea91}', ORANGE),
OutlineKind::Module | OutlineKind::Namespace | OutlineKind::Package => ('\u{ea8b}', GREY),
OutlineKind::Object => ('\u{ea8b}', GREY),
OutlineKind::Key => ('\u{ea93}', GREY),
OutlineKind::String => ('\u{eb8d}', GREY),
OutlineKind::Number => ('\u{ea90}', GREY),
OutlineKind::Boolean | OutlineKind::Null => ('\u{ea8f}', GREY),
OutlineKind::Array => ('\u{ea8a}', GREY),
OutlineKind::File => ('\u{eb60}', GREY),
};
Icon { glyph, color }
}
pub fn for_path(name: &str, suffix: &str) -> Icon {
let n = name.to_ascii_lowercase();
if let Some(i) = name_icon(&n) {
return i;
}
ext_icon(&suffix.to_ascii_lowercase()).unwrap_or(DEFAULT_FILE)
}
fn name_icon(n: &str) -> Option<Icon> {
let i = |g, r, gr, b| Icon {
glyph: g,
color: rgb(r, gr, b),
};
Some(match n {
".gitignore" | ".gitattributes" | ".gitmodules" => i('\u{f841}', 0xe8, 0x27, 0x4b),
".python-version" | "pyproject.toml" => i('\u{e235}', 0x35, 0x72, 0xa5),
"uv.lock" | "poetry.lock" | "package-lock.json" => i('\u{ea75}', 0x51, 0x9a, 0xba),
"package.json" => i('\u{ed0d}', 0xcb, 0xcb, 0x41),
"tsconfig.json" => i('\u{e628}', 0x51, 0x9a, 0xba),
"dockerfile" | ".dockerignore" => i('\u{eb29}', 0x38, 0x4d, 0x54),
"makefile" => i('\u{eb6d}', 0xcc, 0x3e, 0x44),
"readme.md" => i('\u{f48a}', 0x51, 0x9a, 0xba),
"license" => i('\u{eb12}', 0xcc, 0xcc, 0xcc),
".env" => i('\u{eb51}', 0xfa, 0xf7, 0x43),
_ => return None,
})
}
fn ext_icon(s: &str) -> Option<Icon> {
let i = |g, r, gr, b| Icon {
glyph: g,
color: rgb(r, gr, b),
};
Some(match s {
".py" | ".pyi" | ".pyc" | ".ipynb" => i('\u{e235}', 0x35, 0x72, 0xa5),
".js" | ".mjs" | ".cjs" => i('\u{e74e}', 0xcb, 0xcb, 0x41),
".jsx" | ".tsx" => i('\u{e7ba}', 0x51, 0x9a, 0xba),
".ts" => i('\u{e628}', 0x51, 0x9a, 0xba),
".html" | ".htm" => i('\u{e736}', 0xe4, 0x4d, 0x26),
".css" | ".tcss" => i('\u{e749}', 0x42, 0xa5, 0xf5),
".scss" | ".sass" => i('\u{e603}', 0xcc, 0x66, 0x99),
".json" | ".jsonc" => i('\u{ed0d}', 0xcb, 0xcb, 0x41),
".md" | ".markdown" => i('\u{f48a}', 0x51, 0x9a, 0xba),
".yaml" | ".yml" => i('\u{e6a8}', 0xcb, 0x17, 0x1e),
".toml" => i('\u{e6b2}', 0x9c, 0x42, 0x21),
".sql" => i('\u{ebb7}', 0xda, 0xd8, 0xd8),
".sh" | ".bash" | ".zsh" | ".fish" => i('\u{ebca}', 0x4d, 0x5a, 0x5e),
".go" => i('\u{e627}', 0x51, 0x9a, 0xba),
".rs" => i('\u{e7a8}', 0xde, 0xa5, 0x84),
".java" => i('\u{e738}', 0xcc, 0x3e, 0x44),
".kt" | ".kts" => i('\u{e634}', 0x7f, 0x52, 0xff),
".c" => i('\u{e61e}', 0x59, 0x9e, 0xff),
".h" => i('\u{e61e}', 0xa0, 0x74, 0xc4),
".cpp" => i('\u{e61d}', 0x51, 0x9a, 0xba),
".hpp" => i('\u{e61d}', 0xa0, 0x74, 0xc4),
".cs" => i('\u{e648}', 0x59, 0x67, 0x06),
".rb" => i('\u{e739}', 0xcc, 0x34, 0x2d),
".php" => i('\u{e73d}', 0xa0, 0x74, 0xc4),
".swift" => i('\u{e755}', 0xe3, 0x79, 0x33),
".lua" => i('\u{e620}', 0x00, 0x00, 0x80),
".ql" | ".qll" => i('\u{eace}', 0x51, 0x9a, 0xba),
".vim" => i('\u{e7c5}', 0x01, 0x98, 0x33),
".xml" => i('\u{eabe}', 0xe3, 0x79, 0x33),
".svg" => i('\u{eabe}', 0xff, 0xb1, 0x3b),
".png" | ".jpg" | ".jpeg" | ".gif" | ".webp" | ".bmp" | ".ico" => {
i('\u{eaea}', 0xa0, 0x74, 0xc4)
}
".pdf" => i('\u{eaeb}', 0xb3, 0x0b, 0x00),
".zip" | ".tar" | ".gz" => i('\u{eaef}', 0xcc, 0xa7, 0x00),
".lock" => i('\u{ea75}', 0x51, 0x9a, 0xba),
".log" => i('\u{eb9d}', 0xda, 0xd8, 0xd8),
".txt" => i('\u{f15c}', 0xcc, 0xcc, 0xcc),
".csv" | ".tsv" => i('\u{ebb7}', 0x7c, 0xb3, 0x42),
".xlsx" | ".xls" | ".xlsb" => i('\u{ebb7}', 0x10, 0x7c, 0x41),
".ods" => i('\u{ebb7}', 0x18, 0xa3, 0x03),
".env" => i('\u{eb51}', 0xfa, 0xf7, 0x43),
_ => return None,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn txt_icon_is_a_document_glyph_not_the_discard_arrow() {
let icon = for_path("notes.txt", ".txt");
assert_ne!(
icon.glyph as u32, 0xea7d,
"U+EA7D is cod-discard, not a text-file icon"
);
assert_eq!(icon.glyph, '\u{f15c}');
}
#[test]
fn ext_lookup_python() {
let icon = for_path("hello.py", ".py");
assert_eq!(icon.glyph, '\u{e235}');
assert_eq!(icon.color, rgb(0x35, 0x72, 0xa5));
}
#[test]
fn ext_lookup_json() {
let icon = for_path("config.json", ".json");
assert_eq!(icon.glyph, '\u{ed0d}');
}
#[test]
fn ext_lookup_is_case_insensitive() {
let lower = for_path("file.rs", ".rs");
let upper = for_path("FILE.RS", ".RS");
assert_eq!(lower.glyph, upper.glyph);
assert_eq!(lower.color, upper.color);
}
#[test]
fn codeql_queries_and_libraries_share_an_icon() {
let query = for_path("q.ql", ".ql");
assert_eq!(query.glyph, '\u{eace}');
assert_eq!(query.glyph, for_path("lib.qll", ".qll").glyph);
}
#[test]
fn unknown_extension_falls_back_to_default() {
let icon = for_path("weird.xyz123", ".xyz123");
assert_eq!(icon.glyph, DEFAULT_FILE.glyph);
assert_eq!(icon.color, DEFAULT_FILE.color);
}
#[test]
fn name_match_beats_extension_match() {
let icon = for_path(".gitignore", "");
assert_eq!(icon.color, rgb(0xe8, 0x27, 0x4b));
}
#[test]
fn pyproject_toml_overrides_generic_toml() {
let generic = for_path("config.toml", ".toml");
let specific = for_path("pyproject.toml", ".toml");
assert_eq!(specific.color, rgb(0x35, 0x72, 0xa5));
assert_eq!(generic.color, rgb(0x9c, 0x42, 0x21));
}
#[test]
fn dockerfile_name_match_is_case_insensitive() {
let lower = for_path("dockerfile", "");
let upper = for_path("Dockerfile", "");
assert_eq!(lower.color, upper.color);
assert_eq!(lower.color, rgb(0x38, 0x4d, 0x54));
}
#[test]
fn folder_icons_are_consistent_color() {
assert_eq!(FOLDER_OPEN.color, FOLDER_CLOSED.color);
}
#[test]
fn default_file_glyph_is_cod_file_not_cod_exclude() {
assert_eq!(
DEFAULT_FILE.glyph, '\u{ea7b}',
"DEFAULT_FILE must be cod-file"
);
assert_ne!(
DEFAULT_FILE.glyph, '\u{eae5}',
"U+EAE5 is cod-exclude, not a file glyph"
);
}
#[test]
fn folder_closed_glyph_is_cod_folder() {
assert_eq!(FOLDER_CLOSED.glyph, '\u{ea83}');
}
#[test]
fn folder_open_glyph_is_cod_folder_opened() {
assert_eq!(FOLDER_OPEN.glyph, '\u{eaf7}');
}
#[test]
fn activity_bar_explorer_glyph_is_cod_files_not_cod_file_pdf() {
assert_eq!(ACTIVITY_EXPLORER, '\u{eaf0}');
assert_ne!(
ACTIVITY_EXPLORER, '\u{eaeb}',
"U+EAEB is cod-file_pdf, not cod-files"
);
}
#[test]
fn activity_bar_search_glyph_is_cod_search() {
assert_eq!(ACTIVITY_SEARCH, '\u{ea6d}');
}
#[test]
fn search_replace_all_glyph_is_cod_replace_all_not_cod_replace() {
assert_eq!(SEARCH_REPLACE_ALL, '\u{eb3c}');
assert_eq!(SEARCH_REPLACE, '\u{eb3d}');
assert_ne!(
SEARCH_REPLACE_ALL, SEARCH_REPLACE,
"replace-all and replace are distinct glyphs"
);
}
#[test]
fn search_ellipsis_glyph_is_cod_ellipsis() {
assert_eq!(SEARCH_ELLIPSIS, '\u{ea7c}');
}
#[test]
fn search_header_action_glyphs_match_upstream_codicons() {
assert_eq!(SEARCH_REFRESH, '\u{eb37}');
assert_eq!(SEARCH_CLEAR_ALL, '\u{eabf}');
assert_ne!(
SEARCH_CLEAR_ALL, '\u{eb80}',
"U+EB80 is not codicon clear-all"
);
}
#[test]
fn activity_bar_remote_glyph_is_cod_remote_explorer() {
assert_eq!(ACTIVITY_REMOTE, '\u{eb39}');
assert_ne!(
ACTIVITY_REMOTE, '\u{eb3c}',
"U+EB3C is not the Remote Explorer glyph"
);
}
#[test]
fn activity_bar_run_debug_glyph_is_cod_debug_alt() {
assert_eq!(ACTIVITY_RUN_DEBUG, '\u{eb91}');
assert_ne!(ACTIVITY_RUN_DEBUG, '\u{ead1}', "U+EAD1 is debug-pause");
assert_ne!(
ACTIVITY_RUN_DEBUG, '\u{ead8}',
"U+EAD8 is debug, no triangle"
);
}
#[test]
fn activity_bar_source_control_glyph_is_cod_source_control_not_link_external() {
assert_eq!(ACTIVITY_SOURCE_CONTROL, '\u{ea68}');
assert_ne!(ACTIVITY_SOURCE_CONTROL, '\u{eafc}');
assert_ne!(
ACTIVITY_SOURCE_CONTROL, '\u{eb14}',
"U+EB14 is cod-link-external (an external-link arrow), not the source-control Y-fork"
);
assert_ne!(
ACTIVITY_SOURCE_CONTROL, '\u{ea84}',
"U+EA84 is cod-github, not the source-control Y-fork"
);
}
#[test]
fn archive_glyph_is_cod_file_zip_not_cod_filter() {
let icon = for_path("foo.zip", ".zip");
assert_ne!(
icon.glyph, '\u{eaf1}',
"U+EAF1 is cod-filter, not an archive"
);
assert_eq!(icon.glyph, '\u{eaef}');
}
#[test]
fn image_glyph_is_cod_file_media_not_cod_mail() {
let icon = for_path("logo.png", ".png");
assert_ne!(
icon.glyph, '\u{eb1c}',
"U+EB1C is cod-mail, not an image glyph"
);
assert_eq!(icon.glyph, '\u{eaea}');
}
#[test]
fn log_glyph_is_cod_output_not_cod_mention() {
let icon = for_path("debug.log", ".log");
assert_ne!(
icon.glyph, '\u{eb1f}',
"U+EB1F is cod-mention, not a log glyph"
);
assert_eq!(icon.glyph, '\u{eb9d}');
}
#[test]
fn csv_glyph_is_cod_table_not_cod_triangle_down() {
let icon = for_path("data.csv", ".csv");
assert_ne!(
icon.glyph, '\u{eb6e}',
"U+EB6E is cod-triangle_down, not a table"
);
assert_eq!(icon.glyph, '\u{ebb7}');
}
#[test]
fn makefile_glyph_is_cod_tools_not_cod_play() {
let icon = for_path("makefile", "");
assert_ne!(icon.glyph, '\u{eb2c}', "U+EB2C is cod-play, not a wrench");
assert_eq!(icon.glyph, '\u{eb6d}');
}
#[test]
fn env_glyph_is_settings_gear_not_circle_filled() {
let icon = for_path(".env", "");
assert_ne!(icon.glyph, '\u{ea71}', "U+EA71 is just a filled circle");
assert_eq!(icon.glyph, '\u{eb51}');
}
#[test]
fn dockerfile_glyph_is_cod_package_not_workspace_trusted() {
let icon = for_path("dockerfile", "");
assert_ne!(icon.glyph, '\u{ebc1}');
assert_eq!(icon.glyph, '\u{eb29}');
}
#[test]
fn xlsx_uses_table_glyph_in_excel_green() {
let icon = for_path("data.xlsx", ".xlsx");
assert_eq!(icon.glyph, '\u{ebb7}');
assert_eq!(icon.color, rgb(0x10, 0x7c, 0x41));
}
#[test]
fn xls_and_xlsb_share_xlsx_styling() {
let xls = for_path("legacy.xls", ".xls");
let xlsb = for_path("binary.xlsb", ".xlsb");
let xlsx = for_path("modern.xlsx", ".xlsx");
assert_eq!(xls.glyph, xlsx.glyph);
assert_eq!(xls.color, xlsx.color);
assert_eq!(xlsb.glyph, xlsx.glyph);
assert_eq!(xlsb.color, xlsx.color);
}
#[test]
fn ods_uses_table_glyph_in_libreoffice_green() {
let icon = for_path("data.ods", ".ods");
assert_eq!(icon.glyph, '\u{ebb7}');
assert_eq!(icon.color, rgb(0x18, 0xa3, 0x03));
}
#[test]
fn bmp_inherits_image_media_glyph() {
let icon = for_path("logo.bmp", ".bmp");
assert_eq!(icon.glyph, '\u{eaea}');
}
#[test]
fn sql_glyph_is_cod_database_not_workspace_trusted() {
let icon = for_path("query.sql", ".sql");
assert_ne!(icon.glyph, '\u{ebc1}');
}
}