Files · Items: one icon map, file icon, file row and file grid

The crate had two maps from a file's name to its icon, in chat and in the
file tree, and they disagreed. One map now lives in primitives, over the
Lucide file-* icons, and chat, agent, the file tree and the directory
listing use it. FileIcon draws it for a file or a folder. FileItem is a
file's row, a ListItem with its size and when it changed. FileList is the
directory listing. FileGrid lays tiles in the order given, with a cursor
seeded from the owner's pick: arrows by tile and by row, Home, End, Enter
and a double press to open. The count of what fits a width has one home,
layout's columns_for, and fit builds on it.
This commit is contained in:
ZacharyZhang-NY committed 2026-09-26 19:40:10 -04:00
1 parent e75171c995
commit a846e10847
36 files changed
+1024 -77

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
use super::IconName;
/// The icon a file's name suggests, by its extension.
pub(crate) fn file_icon(name: &str) -> IconName {
let extension = name.rsplit_once('.').map(|(_, ext)| ext.to_lowercase());
match extension.as_deref() {
Some(
"rs" | "ts" | "tsx" | "js" | "jsx" | "py" | "go" | "swift" | "c" | "h" | "cpp" | "java"
| "kt" | "rb" | "php" | "css" | "html",
) => IconName::FileCode,
Some("sh" | "zsh" | "bash" | "command") => IconName::FileTerminal,
Some("toml" | "yaml" | "yml" | "ini" | "lock" | "env" | "conf") => IconName::FileCog,
Some("json") => IconName::FileJson,
Some("png" | "jpg" | "jpeg" | "gif" | "webp" | "svg" | "heic" | "bmp" | "tiff") => {
IconName::FileImage
}
Some("mp3" | "wav" | "flac" | "aac" | "m4a" | "ogg" | "aiff") => IconName::FileAudio,
Some("mp4" | "mov" | "mkv" | "webm" | "avi") => IconName::FileVideoCamera,
Some("zip" | "tar" | "gz" | "tgz" | "rar" | "7z") => IconName::FileArchive,
Some("csv" | "xls" | "xlsx" | "numbers") => IconName::FileSpreadsheet,
Some("ttf" | "otf" | "woff" | "woff2") => IconName::FileType,
Some("md" | "txt" | "rtf" | "pdf" | "doc" | "docx" | "pages") => IconName::FileText,
_ => IconName::File,
}
}
#[cfg(test)]
mod tests {
use super::{IconName, file_icon};
#[test]
fn a_name_picks_its_icon_by_its_last_extension() {
assert_eq!(file_icon("main.RS"), IconName::FileCode);
assert_eq!(file_icon("lift.PNG"), IconName::FileImage);
assert_eq!(file_icon("notes.md"), IconName::FileText);
assert_eq!(file_icon("backup.tar.gz"), IconName::FileArchive);
assert_eq!(file_icon(".env"), IconName::FileCog);
assert_eq!(file_icon("take.mov"), IconName::FileVideoCamera);
assert_eq!(file_icon("Makefile"), IconName::File);
}
}
+10
View File
@@ -129,9 +129,19 @@ icons! {
ExternalLink => "external-link",
EyeOff => "eye-off",
Eye => "eye",
FileArchive => "file-archive",
FileAudio => "file-audio",
FileCode => "file-code",
FileCog => "file-cog",
FileImage => "file-image",
FileJson => "file-json",
FilePlus => "file-plus",
FileSpreadsheet => "file-spreadsheet",
FileTerminal => "file-terminal",
FileText => "file-text",
File => "file",
FileType => "file-type",
FileVideoCamera => "file-video-camera",
Filter => "filter",
Fingerprint => "fingerprint",
Flag => "flag",
+2
View File
@@ -1,6 +1,7 @@
mod backdrop;
mod disclosure;
mod divider;
mod files;
mod focus;
mod ghost;
mod icon;
@@ -13,6 +14,7 @@ mod tooltip;
pub use backdrop::{Backdrop, Place};
pub use disclosure::Disclosure;
pub use divider::Divider;
pub(crate) use files::file_icon;
pub use focus::{FocusNext, FocusPrev, FocusRing, FocusScope};
pub(crate) use focus::{Takeover, give_back, hand_back, hold_focus, tab_stop, take_focus};
pub use ghost::DragGhost;