diff options
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-command-prompt.c | 24 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-confirm-before.c | 33 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-select-prompt.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 31 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 9 |
6 files changed, 67 insertions, 40 deletions
diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c index 1e0012e945c..f0e6e9d5948 100644 --- a/usr.bin/tmux/cmd-command-prompt.c +++ b/usr.bin/tmux/cmd-command-prompt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-command-prompt.c,v 1.3 2009/07/15 17:39:00 nicm Exp $ */ +/* $OpenBSD: cmd-command-prompt.c,v 1.4 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -31,6 +31,7 @@ void cmd_command_prompt_init(struct cmd *, int); int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *); int cmd_command_prompt_callback(void *, const char *); +void cmd_command_prompt_free(void *); const struct cmd_entry cmd_command_prompt_entry = { "command-prompt", NULL, @@ -96,7 +97,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) cdata->template = NULL; hdr = xstrdup(":"); } - status_prompt_set(c, hdr, cmd_command_prompt_callback, cdata, 0); + status_prompt_set(c, hdr, + cmd_command_prompt_callback, cmd_command_prompt_free, cdata, 0); xfree(hdr); return (0); @@ -112,10 +114,8 @@ cmd_command_prompt_callback(void *data, const char *s) char *cause, *ptr, *buf, ch; size_t len, slen; - if (s == NULL) { - xfree(cdata); + if (s == NULL) return (0); - } slen = strlen(s); len = 0; @@ -139,12 +139,10 @@ cmd_command_prompt_callback(void *data, const char *s) break; } } - xfree(cdata->template); buf[len] = '\0'; s = buf; } - xfree(cdata); if (cmd_string_parse(s, &cmdlist, &cause) != 0) { if (cause == NULL) @@ -172,7 +170,17 @@ cmd_command_prompt_callback(void *data, const char *s) cmd_list_exec(cmdlist, &ctx); cmd_list_free(cmdlist); - if (c->prompt_callback != (void *) &cmd_command_prompt_callback) + if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback) return (1); return (0); } + +void +cmd_command_prompt_free(void *data) +{ + struct cmd_command_prompt_data *cdata = data; + + if (cdata->template != NULL) + xfree(cdata->template); + xfree(cdata); +} diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index 103f373c350..9f044b653e5 100644 --- a/usr.bin/tmux/cmd-confirm-before.c +++ b/usr.bin/tmux/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-confirm-before.c,v 1.3 2009/07/15 17:39:00 nicm Exp $ */ +/* $OpenBSD: cmd-confirm-before.c,v 1.4 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -29,11 +29,7 @@ int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *); void cmd_confirm_before_init(struct cmd *, int); int cmd_confirm_before_callback(void *, const char *); - -struct cmd_confirm_before_data { - struct client *c; - char *cmd; -}; +void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", @@ -48,6 +44,11 @@ const struct cmd_entry cmd_confirm_before_entry = { cmd_target_print }; +struct cmd_confirm_before_data { + struct client *c; + char *cmd; +}; + void cmd_confirm_before_init(struct cmd *self, int key) { @@ -91,8 +92,9 @@ cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(data->arg); cdata->c = c; - status_prompt_set( - cdata->c, buf, cmd_confirm_before_callback, cdata, PROMPT_SINGLE); + status_prompt_set(cdata->c, buf, + cmd_confirm_before_callback, cmd_confirm_before_free, cdata, + PROMPT_SINGLE); xfree(buf); return (1); @@ -108,7 +110,7 @@ cmd_confirm_before_callback(void *data, const char *s) char *cause; if (s == NULL || tolower((u_char) s[0]) != 'y' || s[1] != '\0') - goto out; + return (0); if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) { if (cause != NULL) { @@ -116,7 +118,7 @@ cmd_confirm_before_callback(void *data, const char *s) status_message_set(c, "%s", cause); xfree(cause); } - goto out; + return (0); } ctx.msgdata = NULL; @@ -132,10 +134,15 @@ cmd_confirm_before_callback(void *data, const char *s) cmd_list_exec(cmdlist, &ctx); cmd_list_free(cmdlist); -out: + return (0); +} + +void +cmd_confirm_before_free(void *data) +{ + struct cmd_confirm_before_data *cdata = data; + if (cdata->cmd != NULL) xfree(cdata->cmd); xfree(cdata); - - return (0); } diff --git a/usr.bin/tmux/cmd-select-prompt.c b/usr.bin/tmux/cmd-select-prompt.c index d070a1c8488..76618175484 100644 --- a/usr.bin/tmux/cmd-select-prompt.c +++ b/usr.bin/tmux/cmd-select-prompt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-prompt.c,v 1.3 2009/07/15 17:39:00 nicm Exp $ */ +/* $OpenBSD: cmd-select-prompt.c,v 1.4 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -55,7 +55,7 @@ cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) if (c->prompt_string != NULL) return (0); - status_prompt_set(c, "index ", cmd_select_prompt_callback, c, 0); + status_prompt_set(c, "index ", cmd_select_prompt_callback, NULL, c, 0); return (0); } diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 8be90654abe..37473e78c83 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.5 2009/07/14 06:59:06 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.6 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -171,8 +171,8 @@ server_lock(void) continue; status_prompt_clear(c); - status_prompt_set( - c, "Password: ", server_lock_callback, c, PROMPT_HIDDEN); + status_prompt_set(c, + "Password: ", server_lock_callback, c, NULL, PROMPT_HIDDEN); server_redraw_client(c); } server_locked = 1; diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 107a73a64fb..ca9bbd482ae 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.11 2009/07/16 23:25:21 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.12 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -468,6 +468,9 @@ status_message_set(struct client *c, const char *fmt, ...) va_list ap; int delay; + status_prompt_clear(c); + status_message_clear(c); + delay = options_get_number(&c->session->options, "display-time"); tv.tv_sec = delay / 1000; tv.tv_usec = (delay % 1000) * 1000L; @@ -493,7 +496,7 @@ status_message_clear(struct client *c) c->message_string = NULL; c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE); - c->flags |= CLIENT_STATUS; + c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */ screen_reinit(&c->status); } @@ -540,15 +543,20 @@ status_message_redraw(struct client *c) } void -status_prompt_set(struct client *c, - const char *msg, int (*fn)(void *, const char *), void *data, int flags) +status_prompt_set(struct client *c, const char *msg, + int (*callbackfn)(void *, const char *), void (*freefn)(void *), + void *data, int flags) { + status_message_clear(c); + status_prompt_clear(c); + c->prompt_string = xstrdup(msg); c->prompt_buffer = xstrdup(""); c->prompt_index = 0; - c->prompt_callback = fn; + c->prompt_callbackfn = callbackfn; + c->prompt_freefn = freefn; c->prompt_data = data; c->prompt_hindex = 0; @@ -566,9 +574,12 @@ status_prompt_set(struct client *c, void status_prompt_clear(struct client *c) { - if (c->prompt_string == NULL) + if (c->prompt_string == NULL) return; + if (c->prompt_freefn != NULL && c->prompt_data != NULL) + c->prompt_freefn(c->prompt_data); + mode_key_free(&c->prompt_mdata); xfree(c->prompt_string); @@ -580,7 +591,7 @@ status_prompt_clear(struct client *c) c->prompt_buffer = NULL; c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE); - c->flags |= CLIENT_STATUS; + c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */ screen_reinit(&c->status); } @@ -832,14 +843,14 @@ status_prompt_key(struct client *c, int key) case MODEKEYCMD_CHOOSE: if (*c->prompt_buffer != '\0') { status_prompt_add_history(c); - if (c->prompt_callback( + if (c->prompt_callbackfn( c->prompt_data, c->prompt_buffer) == 0) status_prompt_clear(c); break; } /* FALLTHROUGH */ case MODEKEYCMD_QUIT: - if (c->prompt_callback(c->prompt_data, NULL) == 0) + if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) status_prompt_clear(c); break; case MODEKEYCMD_OTHERKEY: @@ -858,7 +869,7 @@ status_prompt_key(struct client *c, int key) } if (c->prompt_flags & PROMPT_SINGLE) { - if (c->prompt_callback( + if (c->prompt_callbackfn( c->prompt_data, c->prompt_buffer) == 0) status_prompt_clear(c); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index be342780ee9..8afe464f34e 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.32 2009/07/15 17:39:00 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.33 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -802,7 +802,8 @@ struct client { char *prompt_string; char *prompt_buffer; size_t prompt_index; - int (*prompt_callback)(void *, const char *); + int (*prompt_callbackfn)(void *, const char *); + void (*prompt_freefn)(void *); void *prompt_data; #define PROMPT_HIDDEN 0x1 @@ -1278,8 +1279,8 @@ int status_redraw(struct client *); void printflike2 status_message_set(struct client *, const char *, ...); void status_message_clear(struct client *); int status_message_redraw(struct client *); -void status_prompt_set(struct client *, - const char *, int (*)(void *, const char *), void *, int); +void status_prompt_set(struct client *, const char *, + int (*)(void *, const char *), void (*)(void *), void *, int); void status_prompt_clear(struct client *); int status_prompt_redraw(struct client *); void status_prompt_key(struct client *, int); |