diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-05-21 22:41:22 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-05-21 22:41:22 -0700 |
| commit | b7b6b6cc74a477a3745d06bce64e284e5b2dd880 (patch) | |
| tree | 7eb0fbada09039ec8ffa5b0fb7895c625db8964f | |
| parent | bff00bf75513cefc8e0814ba88777f13811c8a6d (diff) | |
Added ctrl-z for suspend and added a sort of hybrid mode for running
commands at the bottom of the screen instead of in a full terminal mode.
| -rw-r--r-- | bb.c | 31 | ||||
| -rw-r--r-- | config.h | 19 |
2 files changed, 30 insertions, 20 deletions
@@ -535,6 +535,12 @@ static void explore(char *path, int print_dir, int print_selection) _exit(1); return; + case KEY_CTRL_Z: + close_term(); + raise(SIGTSTP); + init_term(); + goto redraw; + case 'q': case 'Q': goto done; @@ -807,26 +813,29 @@ static void explore(char *path, int print_dir, int print_selection) default: for (int i = 0; bindings[i].key; i++) { if (key == bindings[i].key) { - if (!(bindings[i].flags & SILENT)) + term_move(0, height-1); + if (!(bindings[i].flags & ONSCREEN)) close_term(); + else { + // Show cursor: + writez(termfd, "\e[?25h"); + tcsetattr(termfd, TCSAFLUSH, &orig_termios); + close(termfd); + } - int fd; + int scriptinfd; pid_t child; - child = run_cmd(NULL, &fd, bindings[i].command); - + child = run_cmd(NULL, &scriptinfd, bindings[i].command); if (!(bindings[i].flags & NO_FILES)) { if (state.nselected > 0) { - write_selection(fd, state.firstselected); + write_selection(scriptinfd, state.firstselected); } else if (strcmp(state.files[state.cursor]->d_name, "..") != 0) { - write(fd, state.files[state.cursor]->d_name, state.files[state.cursor]->d_namlen); + write(scriptinfd, state.files[state.cursor]->d_name, state.files[state.cursor]->d_namlen); } } - - close(fd); + close(scriptinfd); waitpid(child, NULL, 0); - - if (!(bindings[i].flags & SILENT)) - init_term(); + init_term(); if (bindings[i].flags & CLEAR_SELECTION) clear_selection(&state); @@ -9,7 +9,7 @@ #define CD_TO_RESULT (1<<1) #define REFRESH (1<<2) #define CLEAR_SELECTION (1<<3) -#define SILENT (1<<4) +#define ONSCREEN (1<<4) #define DEVNULL " >/dev/null" @@ -17,18 +17,19 @@ struct { int key; const char *command; int flags; - const char *prompt; } bindings[] = { {'?', "less"}, - {'D', "xargs rm -rf" DEVNULL, CLEAR_SELECTION | REFRESH | SILENT}, - {'d', "xargs -I @ sh -c 'rm -rfi @ </dev/tty'", CLEAR_SELECTION | REFRESH}, - {'+', "xargs -n1 -I @ cp @ @.copy" DEVNULL, REFRESH | SILENT}, - {'m', "xargs -I @ mv -i @ . </dev/tty" DEVNULL, CLEAR_SELECTION | REFRESH | SILENT}, - {'p', "xargs -I @ cp -i @ . </dev/tty" DEVNULL, CLEAR_SELECTION | REFRESH | SILENT}, - {'n', "touch \"`printf '\\033[33;1mNew file:\\033[0m '`\"", SILENT | REFRESH | NO_FILES, "New file: "}, + {'D', "xargs rm -rf" DEVNULL, CLEAR_SELECTION | REFRESH | ONSCREEN}, + {'d', "xargs -I @ sh -c 'rm -rfi @ </dev/tty'", CLEAR_SELECTION | REFRESH | ONSCREEN}, + {'+', "xargs -n1 -I @ cp @ @.copy" DEVNULL, REFRESH | ONSCREEN}, + {'m', "xargs -I @ mv -i @ . </dev/tty" DEVNULL, CLEAR_SELECTION | REFRESH | ONSCREEN}, + {'p', "xargs -I @ cp -i @ . </dev/tty" DEVNULL, CLEAR_SELECTION | REFRESH | ONSCREEN}, + {'n', "touch \"`printf '\\033[33;1mNew file:\\033[0m ' >/dev/tty && head -n1 /dev/tty`\"", ONSCREEN | REFRESH | NO_FILES}, {'|', "sh -c \"`printf '> ' >/dev/tty && head -n1 /dev/tty`\"", REFRESH}, {'>', "sh -c \"`printf '> ' >/dev/tty && head -n1 /dev/tty`\"", NO_FILES | REFRESH}, + {'r', "xargs -I @ -n1 sh -c 'mv \"@\" \"`printf \"\e[1mRename \e[0;33m%%s\e[0m: \" \"@\" >&2 && head -n1 </dev/tty`\"'", + REFRESH | CLEAR_SELECTION | ONSCREEN}, {'r', "xargs -I @ -n1 sh -c 'mv \"@\" \"`printf \"\\033[1mRename \\033[0;33m%%s\\033[0m: \" \"@\" >&2 && head -n1 </dev/tty`\"'", - REFRESH | CLEAR_SELECTION}, + REFRESH | CLEAR_SELECTION | ONSCREEN}, {0}, }; |
