Skip to content

Commit

Permalink
sidestep readline when executing a script
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker committed Aug 12, 2017
1 parent f7b4319 commit 2718278
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/tig/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void open_editor(const char *file, unsigned int lineno);
void enable_mouse(bool enable);

enum status_code open_script(const char *path);
bool is_script_executing(void);

#define get_cursor_pos(cursor_y, cursor_x) getyx(newscr, cursor_y, cursor_x)
#define set_cursor_pos(cursor_y, cursor_x) wmove(newscr, cursor_y, cursor_x)
Expand Down
2 changes: 1 addition & 1 deletion src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static FILE *opt_tty;

static struct io script_io = { -1 };

static bool
bool
is_script_executing(void)
{
return script_io.pipe != -1;
Expand Down
21 changes: 20 additions & 1 deletion src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ prompt_default_handler(struct input *input, struct key *key)
}
}

static enum input_status
prompt_script_handler(struct input *input, struct key *key)
{
switch (key_to_value(key)) {
case KEY_RETURN:
case KEY_ENTER:
case '\n':
return INPUT_STOP;

default:
return INPUT_OK;
}
}

static enum input_status
prompt_yesno_handler(struct input *input, struct key *key)
{
Expand Down Expand Up @@ -1120,10 +1134,15 @@ exec_run_request(struct view *view, struct run_request *req)
enum request
open_prompt(struct view *view)
{
char *cmd = read_prompt(":");
char *cmd;
const char *argv[SIZEOF_ARG] = { NULL };
int argc = 0;

if (is_script_executing())
cmd = read_prompt_incremental(" ", false, true, prompt_script_handler, NULL);
else
cmd = read_prompt(":");

if (cmd && *cmd && !argv_from_string(argv, &argc, cmd)) {
report("Too many arguments");
return REQ_NONE;
Expand Down

0 comments on commit 2718278

Please sign in to comment.