Use enum to customise colors

This commit is contained in:
Night Kaly 2024-11-13 00:28:17 +00:00
parent fc83b825e9
commit 43591378e8
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 26 additions and 11 deletions

24
ccc.c
View file

@ -599,7 +599,8 @@ void add_file_stat(char *filename, char *path, int ftype)
if (stat(path, &file_stat) == -1) { if (stat(path, &file_stat) == -1) {
/* can't be triggered? */ /* can't be triggered? */
if (errno == EACCES) if (errno == EACCES)
arraylist_add(files, filename, path, NULL, REG, NULL, 37, false, false); arraylist_add(files, filename, path, NULL, REG, NULL, DEF_COLOR, false,
false);
} }
int type; int type;
@ -620,37 +621,38 @@ void add_file_stat(char *filename, char *path, int ftype)
else else
memcpy(icon_str, ext_icon->icon, 5); memcpy(icon_str, ext_icon->icon, 5);
int color = 37; int color = DEF_COLOR;
if (S_ISDIR(file_stat.st_mode)) { if (S_ISDIR(file_stat.st_mode)) {
type = DRY; /* dir */ type = DRY; /* dir */
color = 34; color = DIR_COLOR;
memcpy(icon_str, "󰉋", 5); memcpy(icon_str, "󰉋", 5);
} else if (S_ISREG(file_stat.st_mode)) { } else if (S_ISREG(file_stat.st_mode)) {
type = REG; /* regular file */ type = REG; /* regular file */
color = 37; color = REG_COLOR;
} else if (S_ISLNK(file_stat.st_mode)) { } else if (S_ISLNK(file_stat.st_mode)) {
type = LNK; /* symbolic link */ type = LNK; /* symbolic link */
color = 32; color = LNK_COLOR;
} else if (S_ISCHR(file_stat.st_mode)) { } else if (S_ISCHR(file_stat.st_mode)) {
type = CHR; /* character device */ type = CHR; /* character device */
color = 33; color = CHR_COLOR;
} else if (S_ISSOCK(file_stat.st_mode)) { } else if (S_ISSOCK(file_stat.st_mode)) {
type = SOC; /* socket */ type = SOC; /* socket */
color = 35; color = SOC_COLOR;
} else if (S_ISBLK(file_stat.st_mode)) { } else if (S_ISBLK(file_stat.st_mode)) {
type = BLK; /* block device */ type = BLK; /* block device */
color = 33; color = BLK_COLOR;
} else if (S_ISFIFO(file_stat.st_mode)) { } else if (S_ISFIFO(file_stat.st_mode)) {
type = FIF; /* FIFO */ type = FIF; /* FIFO */
color = 35; color = FIF_COLOR;
} }
/* If file is to be marked */ /* If file is to be marked */
if (ftype == 1 || ftype == 2) { if (ftype == 1 || ftype == 2) {
/* Force if user is marking all files */ /* Force if user is marking all files */
bool force = ftype == 2 ? true : false; bool force = ftype == 2 ? true : false;
arraylist_add(marked, filename, path, NULL, type, icon_str, 37, true, force); arraylist_add(marked, filename, path, NULL, type, icon_str, DEF_COLOR, true,
force);
/* free type and return without allocating more stuff */ /* free type and return without allocating more stuff */
return; return;
} }
@ -692,7 +694,7 @@ void add_file_stat(char *filename, char *path, int ftype)
/* get file mode string */ /* get file mode string */
char *mode_str = get_file_mode(file_stat.st_mode); char *mode_str = get_file_mode(file_stat.st_mode);
if (mode_str[0] == '-' && (mode_str[3] == 'x' || mode_str[6] == 'x' || mode_str[9] == 'x')) { if (mode_str[0] == '-' && (mode_str[3] == 'x' || mode_str[6] == 'x' || mode_str[9] == 'x')) {
color = 32; color = EXE_COLOR;
} }
/* mode_str(11) + time(17) + size_size + 2 spaces + 1 null */ /* mode_str(11) + time(17) + size_size + 2 spaces + 1 null */

View file

@ -4,6 +4,19 @@ static int panel_height = 1; /* panel height */
static int jump_num = 14; /* Length of ctrl + u/d jump */ static int jump_num = 14; /* Length of ctrl + u/d jump */
static int decimal_place = 1; /* Number of decimal places size can be shown */ static int decimal_place = 1; /* Number of decimal places size can be shown */
/* Colors for files */
enum files_colors {
DIR_COLOR = 34, /* Directory */
REG_COLOR = 37, /* Regular file */
LNK_COLOR = 32, /* Symbolic link */
CHR_COLOR = 33, /* Character device */
SOC_COLOR = 35, /* Socket */
BLK_COLOR = 33, /* Block device */
FIF_COLOR = 35, /* FIFO */
DEF_COLOR = 37, /* Default */
EXE_COLOR = 32, /* Executable file */
};
/* Set width offset for windows: /* Set width offset for windows:
+-------------%-------------+ +-------------%-------------+
| % | | % |