fix mark files printing at panel

This commit is contained in:
Night Kaly 2024-03-14 19:56:36 +00:00
parent 3ac8fad187
commit cf5cc41034
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE

15
ccc.c
View file

@ -107,7 +107,7 @@ int main(int argc, char** argv)
die("ccc: Terminal size needs to be at least 80x24\n"); die("ccc: Terminal size needs to be at least 80x24\n");
} }
ch = getch(); ch = getch();
printf("%d ",ch); /* printf("%d ",ch); */
switch (ch) { switch (ch) {
/* quit */ /* quit */
case 'q': case 'q':
@ -241,6 +241,7 @@ int main(int argc, char** argv)
/* mark files by space */ /* mark files by space */
case SPACE: case SPACE:
add_file_stat(get_filepath(current_selection), 1); add_file_stat(get_filepath(current_selection), 1);
highlight_current_line();
break; break;
/* escape */ /* escape */
@ -496,14 +497,16 @@ void highlight_current_line()
wclear(panel); wclear(panel);
long num_marked = marked_len(); long num_marked = marked_len();
if (num_marked > 0) { if (num_marked > 0) {
/* largest long is 2147483647, 10 characters /* Determine length of formatted string */
* (x selected), 11 characters */ int m_len = snprintf(NULL, 0, "(%ld selected)", num_marked);
char *selected = memalloc(21 * sizeof(char)); char *selected = memalloc((m_len + 1) * sizeof(char));
snprintf(selected, 21, "(selected )", num_marked);
snprintf(selected, m_len + 1, "(%ld selected)", num_marked);
wprintw(panel, "(%ld/%ld) %s %s", current_selection + 1, files_len(), selected, cwd); wprintw(panel, "(%ld/%ld) %s %s", current_selection + 1, files_len(), selected, cwd);
} } else {
wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd); wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd);
} }
}
/* print the actual filename and stats */ /* print the actual filename and stats */
char *line = get_line(i); char *line = get_line(i);
int color = get_color(i); int color = get_color(i);