Fixed up ctrl-a and esc for select all and clear
This commit is contained in:
parent
2d90cc8fd6
commit
e2fe374f92
91
bb.c
91
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,38 +837,37 @@ 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, '/');
|
if (p) strcpy(to_select, p+1);
|
||||||
if (p) strcpy(to_select, p+1);
|
else to_select[0] = '\0';
|
||||||
else to_select[0] = '\0';
|
} else to_select[0] = '\0';
|
||||||
} else to_select[0] = '\0';
|
|
||||||
|
|
||||||
char tmp[MAX_PATH];
|
char tmp[MAX_PATH];
|
||||||
if (!realpath(state.files[picked]->d_fullname, tmp))
|
if (!realpath(state.files[picked]->d_fullname, tmp))
|
||||||
err("realpath failed");
|
err("realpath failed");
|
||||||
free(path);
|
free(path);
|
||||||
path = calloc(strlen(tmp) + 1, sizeof(char));
|
path = calloc(strlen(tmp) + 1, sizeof(char));
|
||||||
strcpy(path, tmp);
|
strcpy(path, tmp);
|
||||||
goto tail_call;
|
goto tail_call;
|
||||||
} else {
|
} else {
|
||||||
char *name = state.files[picked]->d_name;
|
char *name = state.files[picked]->d_name;
|
||||||
close_term();
|
close_term();
|
||||||
pid_t child = run_cmd(NULL, NULL,
|
pid_t child = run_cmd(NULL, NULL,
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
"if file -bI %s | grep '^text/' >/dev/null; then $EDITOR %s; else open %s; fi",
|
"if file -bI %s | grep '^text/' >/dev/null; then $EDITOR %s; else open %s; fi",
|
||||||
#else
|
#else
|
||||||
"if file -bi %s | grep '^text/' >/dev/null; then $EDITOR %s; else xdg-open %s; fi",
|
"if file -bi %s | grep '^text/' >/dev/null; then $EDITOR %s; else xdg-open %s; fi",
|
||||||
#endif
|
#endif
|
||||||
name, name, name);
|
name, name, name);
|
||||||
waitpid(child, NULL, 0);
|
waitpid(child, NULL, 0);
|
||||||
init_term();
|
init_term();
|
||||||
goto redraw;
|
goto redraw;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (state.nselected) {
|
if (state.nselected) {
|
||||||
@ -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