diff --git a/backend.c b/backend.c index b4c2b5b..629f7ab 100644 --- a/backend.c +++ b/backend.c @@ -54,24 +54,27 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten lstat(dir_content[i].file_name, file); if (S_ISDIR(file->st_mode)) { - dir_content[i].file_type = COLOR_DIR; + dir_content[i].file_type = FILE_TYPE_DIR; dir_content[i].color_pair = COLOR_DIR; + } else if (file->st_mode & S_IXUSR) { + dir_content[i].file_type = FILE_TYPE_EXEC; + dir_content[i].color_pair = COLOR_EXEC; } else if (S_ISBLK(file->st_mode)) { - dir_content[i].file_type = COLOR_BLOCK; + dir_content[i].file_type = FILE_TYPE_BLOCK; dir_content[i].color_pair = COLOR_BLOCK; /*} else if (S_ISCHR(file->st_mode)) { dir_content[i].file_type = COLOR_CHARDEV; */ } else if (S_ISLNK(file->st_mode)) { - dir_content[i].file_type = COLOR_SYMLINK; + dir_content[i].file_type = FILE_TYPE_SYMLINK; dir_content[i].color_pair = COLOR_SYMLINK; } else if (S_ISFIFO(file->st_mode)) { - dir_content[i].file_type = COLOR_FIFO; + dir_content[i].file_type = FILE_TYPE_FIFO; dir_content[i].color_pair = COLOR_FIFO; } else if (S_ISSOCK(file->st_mode)) { - dir_content[i].file_type = COLOR_SOCK; + dir_content[i].file_type = FILE_TYPE_SOCK; dir_content[i].color_pair = COLOR_SOCK; } else if (S_ISREG(file->st_mode)) { - dir_content[i].file_type = COLOR_REGULAR; + dir_content[i].file_type = FILE_TYPE_REGULAR; dir_content[i].color_pair = COLOR_REGULAR; unsigned long j = 0; char *extension = strrchr(entry[i]->d_name, '.'); diff --git a/colors.c b/colors.c index a824fc0..a39c3ac 100644 --- a/colors.c +++ b/colors.c @@ -12,6 +12,7 @@ extern file *rgt_content; extern unsigned long rgt_file_count; extern unsigned int settings; +extern unsigned int status; void parse_colors(char *line, short *fg, short *bg){ int tmp; @@ -38,6 +39,12 @@ void colors_init() { init_pair(0, COLOR_WHITE, COLOR_BLACK); /* unknown file */ + if (status & STATUS_USER_ROOT) { + init_pair(10, COLOR_RED, COLOR_BLACK); /* path */ + } else { + init_pair(10, COLOR_GREEN, COLOR_BLACK); /* path */ + } + FILE *dircolors = fopen("/etc/DIR_COLORS", "r"); @@ -50,48 +57,50 @@ void colors_init() { short fg; short bg; - char supported_filetype_count = 8; + char supported_filetype_count = 9; char initial_pass = 0; while ((tmp = getline(&line, &size, dircolors)) != -1 && initial_pass != supported_filetype_count) { fg = 7; bg = 0; token = strtok(line, " "); - if (!strcmp(token, "DIR")) { - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(1, fg, bg); /* directory */ - } else if (!strcmp(token, "RESET")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(2, fg, bg); /* regular file */ - } else if (!strcmp(token, "LINK")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(3, fg, bg); /* symlink */ - } else if (!strcmp(token, "SOCK")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(7, fg, bg); /* socket */ - } else if (!strcmp(token, "FIFO")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(6, fg, bg); /* fifo */ - } else if (!strcmp(token, "BLK")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(4, fg, bg); /* block device */ - } else if (!strcmp(token, "CHR")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(5, fg, bg); /* character device */ - } else if (!strcmp(token, "ORPHAN")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(8, fg, bg); /* orphan */ - } else if (!strcmp(token, "EXEC")){ - initial_pass++; - parse_colors(line, &fg, &bg); - init_pair(9, fg, bg); /* exec */ + if (token[0] != '#' && token[0] != '\n') { + if (!strcmp(token, "DIR")) { + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(1, fg, bg); /* directory */ + } else if (!strcmp(token, "EXEC")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(2, fg, bg); /* exec */ + } else if (!strcmp(token, "RESET")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(3, fg, bg); /* regular file */ + } else if (!strcmp(token, "LINK")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(4, fg, bg); /* symlink */ + } else if (!strcmp(token, "BLK")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(5, fg, bg); /* block device */ + } else if (!strcmp(token, "CHR")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(6, fg, bg); /* character device */ + } else if (!strcmp(token, "SOCK")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(7, fg, bg); /* socket */ + } else if (!strcmp(token, "FIFO")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(8, fg, bg); /* fifo */ + } else if (!strcmp(token, "ORPHAN")){ + initial_pass++; + parse_colors(line, &fg, &bg); + init_pair(9, fg, bg); /* orphan */ + } } } @@ -114,9 +123,9 @@ void colors_init() { colors[i].file_extension = malloc(sizeof(extension)); strcpy(colors[i].file_extension, extension); - colors[i].color_pair = i+9; + colors[i].color_pair = i+11; parse_colors(line, &fg, &bg); - init_pair(i+10, fg, bg); + init_pair(i+11, fg, bg); i++; } diff --git a/defines.h b/defines.h index 28c2d8b..1c1c0ca 100644 --- a/defines.h +++ b/defines.h @@ -3,6 +3,7 @@ #define STATUS_UPDATE_SCREEN_MASK 12 /* 1100*/ #define STATUS_UPDATE_SCREEN_0 4 #define STATUS_UPDATE_SCREEN_RESIZE 8 +#define STATUS_USER_ROOT 16 #define SETTINGS_HAS_COLOR 1 @@ -20,15 +21,28 @@ #define FILE_STATUS_SELECTED 2; #define FILE_STATUS_IS_REGULAR_FILE 4 +#define COLOR_UNKNOWN 0 #define COLOR_DIR 1 -#define COLOR_EXEC 2 +#define COLOR_EXEC 2 /* not really a filetype, moreso if it is executable */ #define COLOR_REGULAR 3 #define COLOR_SYMLINK 4 #define COLOR_BLOCK 5 #define COLOR_CHARDEV 6 -#define COLOR_FIFO 0 -#define COLOR_SOCK 8 -#define COLOR_PATH 9 +#define COLOR_SOCK 7 +#define COLOR_FIFO 8 +#define COLOR_ORPHAN 9 +#define COLOR_PATH 10 + +#define FILE_TYPE_UNKNOWN COLOR_UNKNOWN +#define FILE_TYPE_DIR COLOR_DIR +#define FILE_TYPE_EXEC COLOR_EXEC +#define FILE_TYPE_REGULAR COLOR_REGULAR +#define FILE_TYPE_SYMLINK COLOR_SYMLINK +#define FILE_TYPE_BLOCK COLOR_BLOCK +#define FILE_TYPE_CHARDEV COLOR_CHARDEV +#define FILE_TYPE_SOCK COLOR_SOCK +#define FILE_TYPE_FIFO COLOR_FIFO +#define FILE_TYPE_ORPHAN COLOR_ORPHAN #ifndef GUARD #define GUARD diff --git a/main.c b/main.c index d41e666..ec065ba 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "threading.h" #include "window.h" @@ -146,6 +147,9 @@ void init() { /*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/ status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); + if (getuid() == 0) { + status += STATUS_USER_ROOT; + } threading_init(); /* found in threading.c */ colors_init(); diff --git a/window.c b/window.c index 4a268bb..d0799c5 100644 --- a/window.c +++ b/window.c @@ -32,9 +32,9 @@ void window_top(WINDOW *win){ status |= STATUS_UPDATE_SCREEN_0; } else { - for (i = 0; i < top_width; i++) { - mvwprintw(win, 0, i, "%c", top_content[i]); - } + wattron(win, COLOR_PAIR(COLOR_PATH)); + mvwprintw(win, i, 0, "%s", top_content); + wattroff(win, COLOR_PAIR(COLOR_PATH)); pthread_mutex_unlock(&mutex_top); } }