--execute
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
histui
|
histui
|
||||||
|
.gdb_history
|
||||||
object/
|
object/
|
||||||
|
*.out
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
+ make (potentially slow) queries cancel using multi threading
|
+ make (potentially slow) queries cancel using multi threading
|
||||||
+ instant run mode
|
|
||||||
+ scroll lags
|
+ scroll lags
|
||||||
+ technical dept in tui.cpp
|
+ technical dept in tui.cpp
|
||||||
+ migrate to C
|
+ migrate to C
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
%token HELP VERSION
|
%token HELP VERSION EXECUTE
|
||||||
%token TUI ENABLE
|
%token TUI ENABLE
|
||||||
%token LEVENSTEIN CASELESS
|
%token LEVENSTEIN CASELESS
|
||||||
%{
|
%{
|
||||||
#include "cli.hpp"
|
#include "cli.hpp"
|
||||||
#include "storage.hpp"
|
#include "storage.hpp"
|
||||||
|
extern bool do_execute;
|
||||||
%}
|
%}
|
||||||
%%
|
%%
|
||||||
histui_args: global_args verb_and_args
|
histui_args: global_args verb_and_args
|
||||||
@ -19,6 +20,7 @@ verb_and_args: ENABLE { enable(); exit(0); }
|
|||||||
;
|
;
|
||||||
|
|
||||||
tui_args: %empty
|
tui_args: %empty
|
||||||
|
| EXECUTE tui_args { do_execute = true; }
|
||||||
| LEVENSTEIN tui_args { is_levenstein = true; }
|
| LEVENSTEIN tui_args { is_levenstein = true; }
|
||||||
| CASELESS tui_args { is_caseless = 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")) {
|
if (!strcmp(argv[i], "enable")) {
|
||||||
tokens[token_empty_head++] = ENABLE;
|
tokens[token_empty_head++] = ENABLE;
|
||||||
} else
|
} else
|
||||||
|
if (!strcmp(argv[i], "--execute")) {
|
||||||
|
tokens[token_empty_head++] = EXECUTE;
|
||||||
|
} else
|
||||||
if (!strcmp(argv[i], "--levenstein")) {
|
if (!strcmp(argv[i], "--levenstein")) {
|
||||||
tokens[token_empty_head++] = LEVENSTEIN;
|
tokens[token_empty_head++] = LEVENSTEIN;
|
||||||
} else
|
} else
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include "cli.hpp"
|
#include "cli.hpp"
|
||||||
#include "bash_history.yy.hpp"
|
#include "bash_history.yy.hpp"
|
||||||
#include "storage.hpp"
|
#include "storage.hpp"
|
||||||
#include "tui.hpp"
|
#include "tui.hpp"
|
||||||
|
|
||||||
bool do_run = true;
|
bool do_run = true;
|
||||||
|
bool do_execute = false;
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
void deinit(void);
|
void deinit(void);
|
||||||
@ -38,11 +40,29 @@ void deinit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void export_result(const char * const result) {
|
void export_result(const char * const result) {
|
||||||
int fd[2];
|
if (do_execute) {
|
||||||
pipe(fd);
|
/* Inject the command and a newline to STDIN directly.
|
||||||
dprintf(3, result);
|
* Some systems could theoretically be configured to disallow it.
|
||||||
close(fd[0]);
|
* Not my problem.
|
||||||
close(fd[1]);
|
*/
|
||||||
|
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) {
|
signed main(const int argc, const char * const * const argv) {
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
|
|
||||||
extern bool do_run;
|
|
||||||
|
|
||||||
size_t entry_lines;
|
size_t entry_lines;
|
||||||
bool is_input_changed = true;
|
bool is_input_changed = true;
|
||||||
|
|
||||||
@ -127,6 +125,7 @@ void tui_refresh(void) {
|
|||||||
|
|
||||||
|
|
||||||
void tui_take_input(void) {
|
void tui_take_input(void) {
|
||||||
|
extern bool do_run;
|
||||||
const size_t paging_size = entry_lines / 2;
|
const size_t paging_size = entry_lines / 2;
|
||||||
|
|
||||||
input = wgetch(stdscr);
|
input = wgetch(stdscr);
|
||||||
|
Reference in New Issue
Block a user