From 8fa00affda48e06a759915bf12e01a5ffca65e45 Mon Sep 17 00:00:00 2001 From: verdant Date: Mon, 3 Aug 2026 21:01:05 +0800 Subject: Add width character and icon support --- src/icon.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/icon.c (limited to 'src/icon.c') diff --git a/src/icon.c b/src/icon.c new file mode 100644 index 0000000..d131307 --- /dev/null +++ b/src/icon.c @@ -0,0 +1,32 @@ +#include "icon.h" +#include +#include + +const char * +get_file_icon(const char *filename, bool is_dir) +{ + if (is_dir) { + return DEFAULT_DIR_ICON; + } + + size_t exact_count = + sizeof(exact_match_icons) / sizeof(exact_match_icons[0]); + for (size_t i = 0; i < exact_count; i++) { + if (strcmp(filename, exact_match_icons[i].key) == 0) { + return exact_match_icons[i].icon; + } + } + + const char *ext = strrchr(filename, '.'); + if (ext && ext != filename) { + ext++; // skip "." + size_t ext_count = sizeof(ext_icons) / sizeof(ext_icons[0]); + for (size_t i = 0; i < ext_count; i++) { + if (strcasecmp(ext, ext_icons[i].key) == 0) { + return ext_icons[i].icon; + } + } + } + + return DEFAULT_FILE_ICON; +} -- cgit v1.2.3