Add icons to TUI.

This commit is contained in:
2026-02-22 11:35:25 -05:00
parent 784592658a
commit 01de2390ac
7 changed files with 24 additions and 12 deletions

View File

@@ -7,3 +7,4 @@ edition = "2024"
anyhow = { workspace = true }
strum = { workspace = true }
log = { workspace = true }
devicons = { workspace = true }

View File

@@ -3,3 +3,16 @@
// SPDX-License-Identifier: GNU General Public License v3.0 or later
pub mod entry_meta;
use devicons::FileIcon;
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

@@ -3,6 +3,7 @@
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use anyhow::{Context, Result};
use devicons::FileIcon;
use std::path::{Path, PathBuf};
#[derive(Debug)]
@@ -10,6 +11,7 @@ pub struct EntryMeta {
pub abs_path: String,
pub file_name: String,
pub is_dir: bool,
pub icon: FileIcon,
}
impl EntryMeta {
@@ -41,10 +43,12 @@ impl EntryMeta {
.context(format!("Failed to get file name for path: {abs_path:?}"))?
.to_string_lossy()
.to_string();
let icon = crate::fs::icon(&abs_path);
Ok(EntryMeta {
abs_path,
file_name,
is_dir,
icon,
})
}
}