diff options
author | Thomas Adam <thomas@xteddy.org> | 2012-11-27 18:12:04 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2012-11-27 18:12:04 +0000 |
commit | 39631edb98a542be53fce6f1eeef41880c9a76b4 (patch) | |
tree | c25708a37d4c79d1dbbc89a91d34296df689d934 /cmd-run-shell.c | |
parent | 1bc910a963ab3c39a03ed3e6b4795c6b5d5b6d18 (diff) | |
parent | 9b8998aeec9c4dff695ae4108965677d90d9c9c7 (diff) | |
download | rtmux-39631edb98a542be53fce6f1eeef41880c9a76b4.tar.gz rtmux-39631edb98a542be53fce6f1eeef41880c9a76b4.tar.bz2 rtmux-39631edb98a542be53fce6f1eeef41880c9a76b4.zip |
Merge branch 'obsd-master'
Sync from OpenBSD.
Diffstat (limited to 'cmd-run-shell.c')
-rw-r--r-- | cmd-run-shell.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/cmd-run-shell.c b/cmd-run-shell.c index 130a5411..44e796df 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -30,13 +30,15 @@ */ enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *); -void cmd_run_shell_callback(struct job *); -void cmd_run_shell_free(void *); + +void cmd_run_shell_callback(struct job *); +void cmd_run_shell_free(void *); +void cmd_run_shell_print(struct job *, const char *); const struct cmd_entry cmd_run_shell_entry = { "run-shell", "run", - "", 1, 1, - "command", + "t:", 1, 1, + CMD_TARGET_PANE_USAGE " command", 0, NULL, NULL, @@ -46,17 +48,42 @@ const struct cmd_entry cmd_run_shell_entry = { struct cmd_run_shell_data { char *cmd; struct cmd_ctx ctx; + u_int wp_id; }; +void +cmd_run_shell_print(struct job *job, const char *msg) +{ + struct cmd_run_shell_data *cdata = job->data; + struct cmd_ctx *ctx = &cdata->ctx; + struct window_pane *wp; + + wp = window_pane_find_by_id(cdata->wp_id); + if (wp == NULL) { + ctx->print(ctx, "%s", msg); + return; + } + + if (window_pane_set_mode(wp, &window_copy_mode) == 0) + window_copy_init_for_output(wp); + if (wp->mode == &window_copy_mode) + window_copy_add(wp, "%s", msg); +} + enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct cmd_run_shell_data *cdata; const char *shellcmd = args->argv[0]; + struct window_pane *wp; + + if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) + return (CMD_RETURN_ERROR); cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); + cdata->wp_id = wp->id; memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); if (ctx->cmdclient != NULL) @@ -87,7 +114,7 @@ cmd_run_shell_callback(struct job *job) lines = 0; do { if ((line = evbuffer_readline(job->event->input)) != NULL) { - ctx->print(ctx, "%s", line); + cmd_run_shell_print (job, line); lines++; } } while (line != NULL); @@ -98,7 +125,7 @@ cmd_run_shell_callback(struct job *job) memcpy(line, EVBUFFER_DATA(job->event->input), size); line[size] = '\0'; - ctx->print(ctx, "%s", line); + cmd_run_shell_print(job, line); lines++; free(line); @@ -115,10 +142,10 @@ cmd_run_shell_callback(struct job *job) xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode); } if (msg != NULL) { - if (lines != 0) - ctx->print(ctx, "%s", msg); - else + if (lines == 0) ctx->info(ctx, "%s", msg); + else + cmd_run_shell_print(job, msg); free(msg); } } |