improvenment to color managenment
This commit is contained in:
87
colors.c
87
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++;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user