Fixed up ctrl-a and esc for select all and clear
This commit is contained in:
parent
2d90cc8fd6
commit
e2fe374f92
41
bb.c
41
bb.c
@ -540,6 +540,7 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
entry->d_reclen = dp->d_reclen;
|
entry->d_reclen = dp->d_reclen;
|
||||||
entry->d_type = dp->d_type;
|
entry->d_type = dp->d_type;
|
||||||
entry->d_isdir = dp->d_type == DT_DIR;
|
entry->d_isdir = dp->d_type == DT_DIR;
|
||||||
|
entry->visible = 1;
|
||||||
if (!entry->d_isdir && entry->d_type == DT_LNK) {
|
if (!entry->d_isdir && entry->d_type == DT_LNK) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if (stat(entry->d_fullname, &statbuf) == 0)
|
if (stat(entry->d_fullname, &statbuf) == 0)
|
||||||
@ -687,7 +688,8 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
case ' ':
|
case ' ':
|
||||||
picked = state.cursor;
|
picked = state.cursor;
|
||||||
toggle:
|
toggle:
|
||||||
if (picked == 0) goto skip_redraw;
|
if (strcmp(state.files[picked]->d_name, "..") == 0)
|
||||||
|
goto skip_redraw;
|
||||||
if (IS_SELECTED(state.files[picked])) {
|
if (IS_SELECTED(state.files[picked])) {
|
||||||
toggle_off:;
|
toggle_off:;
|
||||||
entry_t *e = state.files[picked];
|
entry_t *e = state.files[picked];
|
||||||
@ -707,14 +709,35 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
}
|
}
|
||||||
goto redraw;
|
goto redraw;
|
||||||
|
|
||||||
case KEY_ESC:
|
case KEY_CTRL_A:
|
||||||
for (entry_t *e = state.firstselected; e; e = e->next) {
|
for (int i = 0; i < state.nfiles; i++) {
|
||||||
e->next = NULL;
|
entry_t *e = state.files[i];
|
||||||
e->atme = NULL;
|
if (e->atme) continue;
|
||||||
if (!e->visible) free(e);
|
if (strcmp(e->d_name, "..") == 0)
|
||||||
|
continue;
|
||||||
|
if (state.firstselected)
|
||||||
|
state.firstselected->atme = &e->next;
|
||||||
|
e->next = state.firstselected;
|
||||||
|
e->atme = &state.firstselected;
|
||||||
|
state.firstselected = e;
|
||||||
|
++state.nselected;
|
||||||
}
|
}
|
||||||
|
goto redraw;
|
||||||
|
|
||||||
|
case KEY_ESC: {
|
||||||
|
entry_t **tofree = calloc(state.nselected, sizeof(entry_t*));
|
||||||
|
int i = 0;
|
||||||
|
for (entry_t *e = state.firstselected; e; e = e->next) {
|
||||||
|
if (!e->visible) tofree[i++] = e;
|
||||||
|
*e->atme = NULL;
|
||||||
|
e->atme = NULL;
|
||||||
|
}
|
||||||
|
if (state.firstselected) err("???");
|
||||||
|
while (i) free(tofree[--i]);
|
||||||
|
free(tofree);
|
||||||
state.nselected = 0;
|
state.nselected = 0;
|
||||||
goto redraw;
|
goto redraw;
|
||||||
|
}
|
||||||
|
|
||||||
case 'j':
|
case 'j':
|
||||||
if (state.cursor >= state.nfiles - 1)
|
if (state.cursor >= state.nfiles - 1)
|
||||||
@ -814,8 +837,7 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
|
|
||||||
case 'l': case '\r':
|
case 'l': case '\r':
|
||||||
picked = state.cursor;
|
picked = state.cursor;
|
||||||
open_file:
|
open_file: {
|
||||||
{
|
|
||||||
if (state.files[picked]->d_isdir) {
|
if (state.files[picked]->d_isdir) {
|
||||||
if (strcmp(state.files[picked]->d_name, "..") == 0) {
|
if (strcmp(state.files[picked]->d_name, "..") == 0) {
|
||||||
char *p = strrchr(state.path, '/');
|
char *p = strrchr(state.path, '/');
|
||||||
@ -863,6 +885,7 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
write_selection(fd, state.firstselected);
|
write_selection(fd, state.firstselected);
|
||||||
for (entry_t *e = state.firstselected; e; e = e->next) {
|
for (entry_t *e = state.firstselected; e; e = e->next) {
|
||||||
e->next = NULL;
|
e->next = NULL;
|
||||||
|
*(e->atme) = NULL;
|
||||||
e->atme = NULL;
|
e->atme = NULL;
|
||||||
if (!e->visible) free(e);
|
if (!e->visible) free(e);
|
||||||
}
|
}
|
||||||
@ -911,7 +934,7 @@ static void explore(char *path, int print_dir, int print_selection)
|
|||||||
close(fd);
|
close(fd);
|
||||||
waitpid(child, NULL, 0);
|
waitpid(child, NULL, 0);
|
||||||
|
|
||||||
printf("press any key to continue...");
|
printf("\npress any key to continue...\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user