Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sidestep readline when executing a script #703

Merged
merged 1 commit into from
May 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if defining this is actually necessary. read_prompt_incremental allows to pass a NULL handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a smarter way to do it, but the NULL handler doesn't recognize newlines.

{
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