--execute
This commit is contained in:
parent
733d8580dd
commit
191b3e0d8b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
histui
|
||||
.gdb_history
|
||||
object/
|
||||
*.out
|
||||
|
@ -1,5 +1,4 @@
|
||||
+ make (potentially slow) queries cancel using multi threading
|
||||
+ instant run mode
|
||||
+ scroll lags
|
||||
+ technical dept in tui.cpp
|
||||
+ migrate to C
|
||||
|
@ -1,9 +1,10 @@
|
||||
%token HELP VERSION
|
||||
%token HELP VERSION EXECUTE
|
||||
%token TUI ENABLE
|
||||
%token LEVENSTEIN CASELESS
|
||||
%{
|
||||
#include "cli.hpp"
|
||||
#include "storage.hpp"
|
||||
extern bool do_execute;
|
||||
%}
|
||||
%%
|
||||
histui_args: global_args verb_and_args
|
||||
@ -19,6 +20,7 @@ verb_and_args: ENABLE { enable(); exit(0); }
|
||||
;
|
||||
|
||||
tui_args: %empty
|
||||
| EXECUTE tui_args { do_execute = true; }
|
||||
| LEVENSTEIN tui_args { is_levenstein = true; }
|
||||
| CASELESS tui_args { is_caseless = true; }
|
||||
;
|
||||
|
@ -92,6 +92,9 @@ void parse_arguments(const int argc, const char * const * const argv) {
|
||||
if (!strcmp(argv[i], "enable")) {
|
||||
tokens[token_empty_head++] = ENABLE;
|
||||
} else
|
||||
if (!strcmp(argv[i], "--execute")) {
|
||||
tokens[token_empty_head++] = EXECUTE;
|
||||
} else
|
||||
if (!strcmp(argv[i], "--levenstein")) {
|
||||
tokens[token_empty_head++] = LEVENSTEIN;
|
||||
} else
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include <locale.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "cli.hpp"
|
||||
#include "bash_history.yy.hpp"
|
||||
#include "storage.hpp"
|
||||
#include "tui.hpp"
|
||||
|
||||
bool do_run = true;
|
||||
bool do_execute = false;
|
||||
|
||||
void init(void);
|
||||
void deinit(void);
|
||||
@ -38,11 +40,29 @@ void deinit(void) {
|
||||
}
|
||||
|
||||
void export_result(const char * const result) {
|
||||
int fd[2];
|
||||
pipe(fd);
|
||||
dprintf(3, result);
|
||||
close(fd[0]);
|
||||
close(fd[1]);
|
||||
if (do_execute) {
|
||||
/* Inject the command and a newline to STDIN directly.
|
||||
* Some systems could theoretically be configured to disallow it.
|
||||
* Not my problem.
|
||||
*/
|
||||
for (size_t i = 0; i < strlen(result); i++) {
|
||||
if (ioctl(STDIN_FILENO, TIOCSTI, &result[i]) == -1) {
|
||||
perror("ioctl TIOCSTI");
|
||||
}
|
||||
}
|
||||
const char newline = '\n';
|
||||
ioctl(STDIN_FILENO, TIOCSTI, &newline);
|
||||
} else {
|
||||
/* Copy to a 3th pipe file descriptor which we can
|
||||
* scoop up from a file and copy with READLINE_LINE.
|
||||
* XXX: if anyone knows a better method, please tell me
|
||||
*/
|
||||
int fd[2];
|
||||
pipe(fd);
|
||||
dprintf(3, result);
|
||||
close(fd[0]);
|
||||
close(fd[1]);
|
||||
}
|
||||
}
|
||||
|
||||
signed main(const int argc, const char * const * const argv) {
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <ncurses.h>
|
||||
#include <readline/readline.h>
|
||||
|
||||
extern bool do_run;
|
||||
|
||||
size_t entry_lines;
|
||||
bool is_input_changed = true;
|
||||
|
||||
@ -127,6 +125,7 @@ void tui_refresh(void) {
|
||||
|
||||
|
||||
void tui_take_input(void) {
|
||||
extern bool do_run;
|
||||
const size_t paging_size = entry_lines / 2;
|
||||
|
||||
input = wgetch(stdscr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user