toggle file icons

This commit is contained in:
Night Kaly 2024-04-02 00:18:34 +00:00
parent 4fdeb8c56b
commit 60d9928459
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
3 changed files with 22 additions and 7 deletions

9
ccc.c
View file

@ -44,6 +44,7 @@ bool to_open_file = false;
bool dirs_size = DIRS_SIZE;
bool show_hidden = SHOW_HIDDEN;
bool file_details = SHOW_DETAILS;
bool show_icons = SHOW_ICONS;
char *argv_cp;
char *trash_dir;
char *cwd;
@ -291,6 +292,11 @@ int main(int argc, char** argv)
change_dir(cwd, 0, 0);
break;
case 'w':
show_icons = !show_icons;
change_dir(cwd, 0, 0);
break;
case 'X':
toggle_executable();
break;
@ -376,6 +382,7 @@ int main(int argc, char** argv)
break;
}
}
free(argv_cp);
arraylist_free(files);
arraylist_free(marked);
endwin();
@ -752,7 +759,7 @@ void highlight_current_line()
}
}
/* print the actual filename and stats */
char *line = get_line(files, i, file_details);
char *line = get_line(files, i, file_details, show_icons);
int color = files->items[i].color;
/* check is file marked for action */
bool is_marked = arraylist_search(marked, files->items[i].path, false) != -1;

16
file.c
View file

@ -127,7 +127,7 @@ void arraylist_add(ArrayList *list, char *name, char *path, char *stats, char *t
/*
* Construct a formatted line for display
*/
char *get_line(ArrayList *list, long index, bool detail)
char *get_line(ArrayList *list, long index, bool detail, bool icons)
{
file file = list->items[index];
char *name = estrdup(file.name);
@ -144,11 +144,19 @@ char *get_line(ArrayList *list, long index, bool detail)
}
char *line = memalloc(length * sizeof(char));
line[0] = '\0';
if (detail) {
snprintf(line, length, "%s %ls %s", stats, icon, name);
} else {
snprintf(line, length, "%ls %s", icon, name);
strcat(line, stats);
strcat(line, " ");
}
if (icons) {
char *tmp = memalloc(8 * sizeof(char));
snprintf(tmp, 8, "%ls", icon);
strcat(line, tmp);
strcat(line, " ");
free(tmp);
}
strcat(line, name);
return line;
}

2
file.h
View file

@ -23,6 +23,6 @@ void arraylist_free(ArrayList *list);
long arraylist_search(ArrayList *list, char *filepath, bool bname);
void arraylist_remove(ArrayList *list, long index);
void arraylist_add(ArrayList *list, char *filename, char *path, char *stats, char *type, wchar_t *icon, int color, bool marked, bool force);
char *get_line(ArrayList *list, long index, bool detail);
char *get_line(ArrayList *list, long index, bool detail, bool icons);
#endif