diff options
| author | verdant <im@verdant.ee> | 2026-08-03 21:01:05 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-08-03 21:01:05 +0800 |
| commit | 8fa00affda48e06a759915bf12e01a5ffca65e45 (patch) | |
| tree | 52b2098af1d97b15c76a262388fc1d28bdf24fa6 /src/icon.c | |
| parent | 55e02a195373325216a47ebddc98039faf59b51c (diff) | |
| download | sf-8fa00affda48e06a759915bf12e01a5ffca65e45.tar.gz sf-8fa00affda48e06a759915bf12e01a5ffca65e45.zip | |
Add width character and icon support
Diffstat (limited to 'src/icon.c')
| -rw-r--r-- | src/icon.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 <stdbool.h> +#include <string.h> + +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; +} |
