Move icon helper.

This commit is contained in:
2026-02-22 11:44:55 -05:00
parent 01de2390ac
commit 98aafb3249
2 changed files with 11 additions and 12 deletions

View File

@@ -4,15 +4,4 @@
pub mod entry_meta; pub mod entry_meta;
use devicons::FileIcon; pub use entry_meta::icon;
use std::path::Path;
pub fn icon<P: AsRef<str>>(p: P) -> FileIcon {
let path = p.as_ref();
if Path::new(&path).is_dir() {
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
// For example, a directory named `cpp` would otherwise return a C++ icon.
return FileIcon::from("dir/");
}
FileIcon::from(path)
}

View File

@@ -52,3 +52,13 @@ impl EntryMeta {
}) })
} }
} }
pub fn icon<P: AsRef<str>>(p: P) -> FileIcon {
let path = p.as_ref();
if Path::new(&path).is_dir() {
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
// For example, a directory named `cpp` would otherwise return a C++ icon.
return FileIcon::from("dir/");
}
FileIcon::from(path)
}