From 60d9928459810fcc45626a3afedf2183db95d82c Mon Sep 17 00:00:00 2001 From: night0721 Date: Tue, 2 Apr 2024 00:18:34 +0000 Subject: [PATCH] toggle file icons --- ccc.c | 9 ++++++++- file.c | 18 +++++++++++++----- file.h | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ccc.c b/ccc.c index 28171ef..0550362 100644 --- a/ccc.c +++ b/ccc.c @@ -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; diff --git a/file.c b/file.c index bc31852..2039d82 100644 --- a/file.c +++ b/file.c @@ -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; } diff --git a/file.h b/file.h index 5ab34b0..b90a925 100644 --- a/file.h +++ b/file.h @@ -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