toggle file details

This commit is contained in:
Night Kaly 2024-03-25 21:49:25 +00:00
parent a7e9f9ea14
commit 95fd5fb964
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE
2 changed files with 18 additions and 5 deletions

1
ccc.c
View file

@ -268,6 +268,7 @@ int main(int argc, char** argv)
case 'i': case 'i':
file_details = !file_details; file_details = !file_details;
change_dir(cwd, 0, 0); change_dir(cwd, 0, 0);
break;
/* mark one file */ /* mark one file */
case SPACE: case SPACE:

20
file.c
View file

@ -132,15 +132,27 @@ char *get_line(ArrayList *list, long index, bool detail)
{ {
file file = list->items[index]; file file = list->items[index];
char *name = strdup(file.path); char *name = strdup(file.path);
char *stats = strdup(file.stats); char *stats = NULL;
size_t length = strlen(name) + strlen(stats) + 2; /* one for space and one for null */ size_t length;
if (detail) {
stats = strdup(file.stats);
length = strlen(name) + strlen(stats) + 2; /* one for space and one for null */
if (stats == NULL) {
perror("ccc");
}
} else {
length = strlen(name) + 2; /* one for space and one for null */
}
char *line = memalloc(length * sizeof(char)); char *line = memalloc(length * sizeof(char));
name = basename(name); name = basename(name);
if (name == NULL || stats == NULL) if (name == NULL)
perror("ccc"); perror("ccc");
if (detail) {
snprintf(line, length, "%s %s", stats, name); snprintf(line, length, "%s %s", stats, name);
} else {
snprintf(line, length, "%s", name);
}
return line; return line;
} }