commit 0d65decf3091706a595c691941b0f18e2708c74e
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Fri Jan 07 21:13:31 2022 +0000
diff --git a/include/type.h b/include/type.h
index dac50ec..2bc531b 100644
--- a/include/type.h
+++ b/include/type.h
@@ -110 +16 @@
#ifndef TYPE_H
#define TYPE_H
-#define ICON_DIR "\uf74a"
-#define ICON_GEAR "\uf013"
-#define ICON_GENERIC "\uf15b"
-
#include "dir.h"
struct icon_pair {
@@ -166 +126 @@ struct icon_pair {
char * get_ext(char *);
void lowers(char *);
enum mime_type_t get_mime(char *);
-char * get_icon(char *);
+char * get_icon(struct dir_entry_t *);
#endif /* TYPE_H */
diff --git a/src/io.c b/src/io.c
index 4a30b52..5febc73 100644
--- a/src/io.c
+++ b/src/io.c
@@ -14610 +1469 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
#if ICONS
// find icon if it is not a dir
- if (!icon && show_icons) {
- icon = get_icon(dir_entry->name);
+ if (show_icons) {
+ icon = get_icon(dir_entry);
}
- if (!icon && dir_entry->file_type == FILE_DIR) icon = ICON_DIR;
#endif
if ((dir_entry->mode & POWNER(M_EXEC)) &&
@@ -15718 +15611 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
dir_entry->file_type != FILE_DIR) {
cp = GREEN;
if (f_ident == NO_IDENT) f_ident = '*';
-#if ICONS
- if (!icon) icon = ICON_GEAR;
-#endif
} else if (cp == -1) {
cp = WHITE;
f_ident = ' ';
}
-#if ICONS
- if (!icon) icon = ICON_GENERIC;
-#endif
-
cp = COLOR_PAIR((unsigned)cp);
if (highlight) cp |= A_REVERSE;
diff --git a/src/type.c b/src/type.c
index c470140..a18f6aa 100644
--- a/src/type.c
+++ b/src/type.c
@@ -16 +17 @@
#include <string.h>
#include <stdlib.h>
+#include "dir.h"
#include "type.h"
#include "icons.h"
@@ -4117 +4224 @@ enum mime_type_t get_mime(char * file) {
else return MIME_UNKNOWN;
}
-char * get_icon(char * file) {
- char * t_ext = get_ext(file);
- if (!t_ext) return NULL;
+#if ICONS
+char * get_icon(struct dir_entry_t * f) {
+ char * t_ext = get_ext(f->name);
+ struct icon_pair * t = NULL;
+ if (t_ext) {
+ char * ext = malloc(strlen(t_ext));
+ strcpy(ext, t_ext);
+ lowers(ext);
- char * ext = malloc(strlen(t_ext));
- strcpy(ext, t_ext);
- lowers(ext);
+ t = bsearch(&ext, icons, n_icons, sizeof(icons[0]), icmp);
+ free(ext);
+ }
- struct icon_pair * t =
- bsearch(&ext, icons, n_icons, sizeof(icons[0]), icmp);
- free(ext);
- if (!t) return NULL;
+ if (!t) {
+ if (f->file_type == FILE_DIR) return ICON_DIR;
+ if (f->mode & POWNER(M_EXEC)) return ICON_GEAR;
+ return ICON_GENERIC;
+ }
return t->icon;
}
+#endif