1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-26 06:48:48 +00:00

Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2017-05-17 18:01:14 +01:00
commit d1497527c6
4 changed files with 35 additions and 40 deletions

View File

@ -32,7 +32,8 @@
static enum cmd_retval cmd_command_prompt_exec(struct cmd *, static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
struct cmdq_item *); struct cmdq_item *);
static int cmd_command_prompt_callback(void *, const char *, int); static int cmd_command_prompt_callback(struct client *, void *,
const char *, int);
static void cmd_command_prompt_free(void *); static void cmd_command_prompt_free(void *);
const struct cmd_entry cmd_command_prompt_entry = { const struct cmd_entry cmd_command_prompt_entry = {
@ -48,17 +49,16 @@ const struct cmd_entry cmd_command_prompt_entry = {
}; };
struct cmd_command_prompt_cdata { struct cmd_command_prompt_cdata {
struct client *c; int flags;
int flags;
char *inputs; char *inputs;
char *next_input; char *next_input;
char *prompts; char *prompts;
char *next_prompt; char *next_prompt;
char *template; char *template;
int idx; int idx;
}; };
static enum cmd_retval static enum cmd_retval
@ -78,7 +78,6 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
cdata->c = c;
cdata->inputs = NULL; cdata->inputs = NULL;
cdata->next_input = NULL; cdata->next_input = NULL;
@ -142,10 +141,10 @@ cmd_command_prompt_error(struct cmdq_item *item, void *data)
} }
static int static int
cmd_command_prompt_callback(void *data, const char *s, int done) cmd_command_prompt_callback(struct client *c, void *data, const char *s,
int done)
{ {
struct cmd_command_prompt_cdata *cdata = data; struct cmd_command_prompt_cdata *cdata = data;
struct client *c = cdata->c;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmdq_item *new_item; struct cmdq_item *new_item;
char *cause, *new_template, *prompt, *ptr; char *cause, *new_template, *prompt, *ptr;
@ -193,7 +192,7 @@ cmd_command_prompt_callback(void *data, const char *s, int done)
if (!done) if (!done)
free(new_template); free(new_template);
if (c->prompt_callbackfn != cmd_command_prompt_callback) if (c->prompt_inputcb != cmd_command_prompt_callback)
return (1); return (1);
return (0); return (0);
} }

View File

@ -31,7 +31,8 @@
static enum cmd_retval cmd_confirm_before_exec(struct cmd *, static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
struct cmdq_item *); struct cmdq_item *);
static int cmd_confirm_before_callback(void *, const char *, int); static int cmd_confirm_before_callback(struct client *, void *,
const char *, int);
static void cmd_confirm_before_free(void *); static void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = { const struct cmd_entry cmd_confirm_before_entry = {
@ -46,8 +47,7 @@ const struct cmd_entry cmd_confirm_before_entry = {
}; };
struct cmd_confirm_before_data { struct cmd_confirm_before_data {
char *cmd; char *cmd;
struct client *client;
}; };
static enum cmd_retval static enum cmd_retval
@ -74,9 +74,6 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]); cdata->cmd = xstrdup(args->argv[0]);
cdata->client = c;
cdata->client->references++;
status_prompt_set(c, new_prompt, NULL, status_prompt_set(c, new_prompt, NULL,
cmd_confirm_before_callback, cmd_confirm_before_free, cdata, cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
PROMPT_SINGLE); PROMPT_SINGLE);
@ -97,10 +94,10 @@ cmd_confirm_before_error(struct cmdq_item *item, void *data)
} }
static int static int
cmd_confirm_before_callback(void *data, const char *s, __unused int done) cmd_confirm_before_callback(struct client *c, void *data, const char *s,
__unused int done)
{ {
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
struct client *c = cdata->client;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmdq_item *new_item; struct cmdq_item *new_item;
char *cause; char *cause;
@ -135,9 +132,6 @@ static void
cmd_confirm_before_free(void *data) cmd_confirm_before_free(void *data)
{ {
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
struct client *c = cdata->client;
server_client_unref(c);
free(cdata->cmd); free(cdata->cmd);
free(cdata); free(cdata);

View File

@ -656,8 +656,7 @@ status_message_redraw(struct client *c)
/* Enable status line prompt. */ /* Enable status line prompt. */
void void
status_prompt_set(struct client *c, const char *msg, const char *input, status_prompt_set(struct client *c, const char *msg, const char *input,
int (*callbackfn)(void *, const char *, int), void (*freefn)(void *), prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags)
void *data, int flags)
{ {
struct format_tree *ft; struct format_tree *ft;
time_t t; time_t t;
@ -677,8 +676,8 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
c->prompt_buffer = utf8_fromcstr(tmp); c->prompt_buffer = utf8_fromcstr(tmp);
c->prompt_index = utf8_strlen(c->prompt_buffer); c->prompt_index = utf8_strlen(c->prompt_buffer);
c->prompt_callbackfn = callbackfn; c->prompt_inputcb = inputcb;
c->prompt_freefn = freefn; c->prompt_freecb = freecb;
c->prompt_data = data; c->prompt_data = data;
c->prompt_hindex = 0; c->prompt_hindex = 0;
@ -692,7 +691,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
if ((flags & PROMPT_INCREMENTAL) && *tmp != '\0') { if ((flags & PROMPT_INCREMENTAL) && *tmp != '\0') {
xasprintf(&cp, "=%s", tmp); xasprintf(&cp, "=%s", tmp);
c->prompt_callbackfn(c->prompt_data, cp, 0); c->prompt_inputcb(c, c->prompt_data, cp, 0);
free(cp); free(cp);
} }
@ -707,8 +706,8 @@ status_prompt_clear(struct client *c)
if (c->prompt_string == NULL) if (c->prompt_string == NULL)
return; return;
if (c->prompt_freefn != NULL && c->prompt_data != NULL) if (c->prompt_freecb != NULL && c->prompt_data != NULL)
c->prompt_freefn(c->prompt_data); c->prompt_freecb(c->prompt_data);
free(c->prompt_string); free(c->prompt_string);
c->prompt_string = NULL; c->prompt_string = NULL;
@ -995,7 +994,7 @@ status_prompt_key(struct client *c, key_code key)
if (key >= '0' && key <= '9') if (key >= '0' && key <= '9')
goto append_key; goto append_key;
s = utf8_tocstr(c->prompt_buffer); s = utf8_tocstr(c->prompt_buffer);
c->prompt_callbackfn(c->prompt_data, s, 1); c->prompt_inputcb(c, c->prompt_data, s, 1);
status_prompt_clear(c); status_prompt_clear(c);
free(s); free(s);
return (1); return (1);
@ -1276,13 +1275,13 @@ process_key:
s = utf8_tocstr(c->prompt_buffer); s = utf8_tocstr(c->prompt_buffer);
if (*s != '\0') if (*s != '\0')
status_prompt_add_history(s); status_prompt_add_history(s);
if (c->prompt_callbackfn(c->prompt_data, s, 1) == 0) if (c->prompt_inputcb(c, c->prompt_data, s, 1) == 0)
status_prompt_clear(c); status_prompt_clear(c);
free(s); free(s);
break; break;
case '\033': /* Escape */ case '\033': /* Escape */
case '\003': /* C-c */ case '\003': /* C-c */
if (c->prompt_callbackfn(c->prompt_data, NULL, 1) == 0) if (c->prompt_inputcb(c, c->prompt_data, NULL, 1) == 0)
status_prompt_clear(c); status_prompt_clear(c);
break; break;
case '\022': /* C-r */ case '\022': /* C-r */
@ -1330,7 +1329,7 @@ append_key:
s = utf8_tocstr(c->prompt_buffer); s = utf8_tocstr(c->prompt_buffer);
if (strlen(s) != 1) if (strlen(s) != 1)
status_prompt_clear(c); status_prompt_clear(c);
else if (c->prompt_callbackfn(c->prompt_data, s, 1) == 0) else if (c->prompt_inputcb(c, c->prompt_data, s, 1) == 0)
status_prompt_clear(c); status_prompt_clear(c);
free(s); free(s);
} }
@ -1340,7 +1339,7 @@ changed:
if (c->prompt_flags & PROMPT_INCREMENTAL) { if (c->prompt_flags & PROMPT_INCREMENTAL) {
s = utf8_tocstr(c->prompt_buffer); s = utf8_tocstr(c->prompt_buffer);
xasprintf(&cp, "%c%s", prefix, s); xasprintf(&cp, "%c%s", prefix, s);
c->prompt_callbackfn(c->prompt_data, cp, 0); c->prompt_inputcb(c, c->prompt_data, cp, 0);
free(cp); free(cp);
free(s); free(s);
} }

11
tmux.h
View File

@ -1288,6 +1288,8 @@ struct cmd_entry {
}; };
/* Client connection. */ /* Client connection. */
typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
typedef void (*prompt_free_cb)(void *);
struct client { struct client {
const char *name; const char *name;
struct tmuxpeer *peer; struct tmuxpeer *peer;
@ -1357,7 +1359,8 @@ struct client {
struct key_table *keytable; struct key_table *keytable;
struct event identify_timer; struct event identify_timer;
void (*identify_callback)(struct client *, struct window_pane *); void (*identify_callback)(struct client *,
struct window_pane *);
void *identify_callback_data; void *identify_callback_data;
char *message_string; char *message_string;
@ -1368,8 +1371,8 @@ struct client {
char *prompt_string; char *prompt_string;
struct utf8_data *prompt_buffer; struct utf8_data *prompt_buffer;
size_t prompt_index; size_t prompt_index;
int (*prompt_callbackfn)(void *, const char *, int); prompt_input_cb prompt_inputcb;
void (*prompt_freefn)(void *); prompt_free_cb prompt_freecb;
void *prompt_data; void *prompt_data;
u_int prompt_hindex; u_int prompt_hindex;
enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode; enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode;
@ -1893,7 +1896,7 @@ void printflike(2, 3) status_message_set(struct client *, const char *, ...);
void status_message_clear(struct client *); void status_message_clear(struct client *);
int status_message_redraw(struct client *); int status_message_redraw(struct client *);
void status_prompt_set(struct client *, const char *, const char *, void status_prompt_set(struct client *, const char *, const char *,
int (*)(void *, const char *, int), void (*)(void *), void *, int); prompt_input_cb, prompt_free_cb, void *, int);
void status_prompt_clear(struct client *); void status_prompt_clear(struct client *);
int status_prompt_redraw(struct client *); int status_prompt_redraw(struct client *);
int status_prompt_key(struct client *, key_code); int status_prompt_key(struct client *, key_code);