commit 19a8fd594436d0c712a306dfd1d4ed947a3e51dd
Author: rani <clagv.randomgames@gmail.com>
Date: Tue Mar 22 18:35:18 2022 +0000
diff --git a/include/io.h b/include/io.h
index 46b4c50..5cdd483 100644
--- a/include/io.h
+++ b/include/io.h
@@ -2114 +2114 @@ enum colors {
COLOR_MEDIA = 9,
COLOR_ARCHIVE = 10,
- CUSTOM_FILE = 11,
- CUSTOM_DIR = 12,
- CUSTOM_FIFO = 13,
- CUSTOM_LINK = 14,
- CUSTOM_BLOCK = 15,
- CUSTOM_SOCK = 16,
- CUSTOM_EXEC = 17,
- CUSTOM_UNKNOWN = 18,
+ CUSTOM_DIR = 11,
+ CUSTOM_LINK = 12,
+ CUSTOM_EXEC = 13,
+ CUSTOM_SOCK = 14,
+ CUSTOM_FIFO = 15,
+ CUSTOM_UNKNOWN = 16,
+ CUSTOM_FILE = 17,
+ CUSTOM_BLOCK = 18,
CUSTOM_MEDIA = 19,
CUSTOM_ARCHIVE = 20,
diff --git a/include/opts.h b/include/opts.h
index 13c9890..52de815 100644
--- a/include/opts.h
+++ b/include/opts.h
@@ -1729 +1732 @@ extern bool color;
#define LONG_VAR "long"
extern bool p_long;
#define DIR_COLOR_VAR "dir_color"
-extern uint32_t dir_color;
+extern int32_t dir_color;
#define REG_COLOR_VAR "reg_color"
-extern uint32_t reg_color;
+extern int32_t reg_color;
#define FIFO_COLOR_VAR "fifo_color"
-extern uint32_t fifo_color;
+extern int32_t fifo_color;
#define LINK_COLOR_VAR "link_color"
-extern uint32_t link_color;
+extern int32_t link_color;
#define BLK_COLOR_VAR "block_color"
-extern uint32_t blk_color;
+extern int32_t blk_color;
#define SOCK_COLOR_VAR "sock_color"
-extern uint32_t sock_color;
+extern int32_t sock_color;
#define UNKNOWN_COLOR_VAR "unknown_color"
-extern uint32_t unknown_color;
+extern int32_t unknown_color;
#define EXEC_COLOR_VAR "exec_color"
-extern uint32_t exec_color;
+extern int32_t exec_color;
#define MEDIA_COLOR_VAR "media_color"
-extern uint32_t media_color;
+extern int32_t media_color;
#define ARCHIVE_COLOR_VAR "archive_color"
-extern uint32_t archive_color;
+extern int32_t archive_color;
+
+extern int32_t custom_colors[10];
bool check_config(void);
void create_config(void);
void read_config(void);
void terminate_opts(void);
+void generate_colors(void);
#endif /* _OPTS_H */
diff --git a/src/io.c b/src/io.c
index bf13eef..796de2c 100644
--- a/src/io.c
+++ b/src/io.c
@@ -226 +2219 @@ bool print_path = false;
int stdout_back = 0;
size_t n_marked_files = false;
+static int default_colors[] = {
+ [COLOR_DIR] = COLOR_BLUE,
+ [COLOR_LINK] = COLOR_CYAN,
+ [COLOR_EXEC] = COLOR_GREEN,
+ [COLOR_SOCK] = COLOR_MAGENTA,
+ [COLOR_FIFO] = COLOR_YELLOW,
+ [COLOR_UNKNOWN] = COLOR_RED,
+ [COLOR_FILE] = COLOR_WHITE,
+ [COLOR_BLOCK] = COLOR_YELLOW,
+ [COLOR_MEDIA] = COLOR_MAGENTA,
+ [COLOR_ARCHIVE] = COLOR_RED,
+};
+
void curses_init(void) {
if (print_path) {
@@ -5749 +7024 @@ void terminate_curses(void) {
void set_color(void) {
if (color) {
- init_color(CUSTOM_DIR, GET_RGB(dir_color));
- init_pair(COLOR_DIR, CUSTOM_DIR, COLOR_BLACK);
-
- init_color(CUSTOM_LINK, GET_RGB(link_color));
- init_pair(COLOR_LINK, CUSTOM_LINK, COLOR_BLACK);
-
- init_color(CUSTOM_EXEC, GET_RGB(exec_color));
- init_pair(COLOR_EXEC, CUSTOM_EXEC, COLOR_BLACK);
-
- init_color(CUSTOM_SOCK, GET_RGB(sock_color));
- init_pair(COLOR_SOCK, CUSTOM_SOCK, COLOR_BLACK);
-
- init_color(CUSTOM_FIFO, GET_RGB(fifo_color));
- init_pair(COLOR_FIFO, CUSTOM_FIFO, COLOR_BLACK);
-
- init_color(CUSTOM_BLOCK, GET_RGB(blk_color));
- init_pair(COLOR_BLOCK, CUSTOM_BLOCK, COLOR_BLACK);
-
- init_color(CUSTOM_UNKNOWN, GET_RGB(unknown_color));
- init_pair(COLOR_UNKNOWN, CUSTOM_UNKNOWN, COLOR_BLACK);
-
- init_color(CUSTOM_MEDIA, GET_RGB(media_color));
- init_pair(COLOR_MEDIA, CUSTOM_MEDIA, COLOR_BLACK);
-
- init_color(CUSTOM_ARCHIVE, GET_RGB(archive_color));
- init_pair(COLOR_ARCHIVE, CUSTOM_ARCHIVE, COLOR_BLACK);
-
- init_color(CUSTOM_FILE, GET_RGB(reg_color));
- init_pair(COLOR_FILE, CUSTOM_FILE, COLOR_BLACK);
+ for (int i = CUSTOM_DIR; i <= CUSTOM_ARCHIVE; i++) {
+ int def = i - CUSTOM_DIR + 1; // default color / index
+ if (custom_colors[def] == -1) {
+ init_pair(def, default_colors[def], COLOR_BLACK);
+ } else {
+ init_color(i, GET_RGB(custom_colors[def - 1]));
+ init_pair(def, i, COLOR_BLACK);
+ }
+ }
init_pair(RED, COLOR_RED, COLOR_BLACK);
init_pair(WHITE, COLOR_WHITE, COLOR_BLACK);
} else {
- init_pair(COLOR_DIR, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_LINK, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_EXEC, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_SOCK, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_FIFO, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_UNKNOWN, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_BLOCK, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_MEDIA, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_ARCHIVE, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_FILE, COLOR_WHITE, COLOR_BLACK);
+ // COLOR_ARCHIVE is highest enum value
+ for (int i = 1; i <= COLOR_ARCHIVE; i++) {
+ init_pair(i, COLOR_WHITE, COLOR_BLACK);
+ }
+
init_pair(RED, COLOR_WHITE, COLOR_BLACK);
init_pair(WHITE, COLOR_WHITE, COLOR_BLACK);
}
diff --git a/src/main.c b/src/main.c
index bb06c17..1331812 100644
--- a/src/main.c
+++ b/src/main.c
@@ -246 +247 @@ int main(int argc, char ** argv) {
if (!check_config()) create_config();
else read_config();
terminate_opts();
+ generate_colors();
if (argc > 1) {
for (int i = 1; i < argc; i++) {
diff --git a/src/opts.c b/src/opts.c
index 74b2f3a..f4af8d8 100644
--- a/src/opts.c
+++ b/src/opts.c
@@ -1716 +1718 @@ bool show_dot_files = false;
bool color = true;
bool p_long = false;
-uint32_t dir_color = RGB(8, 584, 815); // blue
-uint32_t reg_color = RGB(800, 800, 800); // white
-uint32_t fifo_color = RGB(984, 812, 16); // yellow
-uint32_t link_color = RGB(502, 776, 710); // cyan
-uint32_t blk_color = RGB(984, 812, 16); // yellow
-uint32_t sock_color = RGB(573, 8, 353); // magenta
-uint32_t exec_color = RGB(4, 506, 239); // green
-uint32_t unknown_color = RGB(855, 176, 141); // red
-uint32_t media_color = RGB(573, 8, 353); // magenta
-uint32_t archive_color = RGB(855, 176, 141); // red
+int32_t custom_colors[10];
+
+int32_t dir_color = -1;
+int32_t link_color = -1;
+int32_t exec_color = -1;
+int32_t sock_color = -1;
+int32_t fifo_color = -1;
+int32_t unknown_color = -1;
+int32_t reg_color = -1;
+int32_t blk_color = -1;
+int32_t media_color = -1;
+int32_t archive_color = -1;
static char * default_config_dir = NULL;
static char * csc_config_path = NULL;
@@ -427 +447 @@ bool check_config(void) {
char * cfg_path = NULL;
if (!xdg_config) {
char * home = getenv("HOME");
- cfg_path = malloc(strlen(home) + 9 + csc_len);
+ cfg_path = malloc(strlen(home) + 9 + csc_len + 1);
sprintf(cfg_path, "%s/.config", home);
} else {
cfg_path = malloc(strlen(xdg_config) + 2 + csc_len);
@@ -1543 +15617 @@ void terminate_opts(void) {
free(csc_config_path);
free(csc_config_file);
}
+
+
+void generate_colors(void) {
+ custom_colors[0] = dir_color;
+ custom_colors[1] = link_color;
+ custom_colors[2] = exec_color;
+ custom_colors[3] = sock_color;
+ custom_colors[4] = fifo_color;
+ custom_colors[5] = unknown_color;
+ custom_colors[6] = reg_color;
+ custom_colors[7] = blk_color;
+ custom_colors[8] = media_color;
+ custom_colors[9] = archive_color;
+}