mirror of
https://github.com/tmux/tmux.git
synced 2024-12-04 19:58:48 +00:00
Preserve argument type in command and convert to string on demand.
This commit is contained in:
parent
326d2ef234
commit
069f5925af
@ -50,6 +50,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_parse_result *pr;
|
||||
char **argv;
|
||||
int argc, repeat;
|
||||
struct args_value *value;
|
||||
u_int count = args_count(args);
|
||||
|
||||
key = key_string_lookup_string(args_string(args, 0));
|
||||
@ -66,24 +67,32 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
tablename = "prefix";
|
||||
repeat = args_has(args, 'r');
|
||||
|
||||
if (count != 1) {
|
||||
if (count == 2)
|
||||
pr = cmd_parse_from_string(args_string(args, 1), NULL);
|
||||
else {
|
||||
args_vector(args, &argc, &argv);
|
||||
pr = cmd_parse_from_arguments(argc - 1, argv + 1, NULL);
|
||||
cmd_free_argv(argc, argv);
|
||||
}
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
||||
} else
|
||||
if (count == 1) {
|
||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_value(args, 1);
|
||||
if (count == 2 && value->type == ARGS_COMMANDS) {
|
||||
key_bindings_add(tablename, key, note, repeat, value->cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (count == 2)
|
||||
pr = cmd_parse_from_string(args_string(args, 1), NULL);
|
||||
else {
|
||||
args_vector(args, &argc, &argv);
|
||||
pr = cmd_parse_from_arguments(argc - 1, argv + 1, NULL);
|
||||
cmd_free_argv(argc, argv);
|
||||
}
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *s = args_string(args, 0), *suffix = "";
|
||||
char *filter;
|
||||
struct args_value *filter;
|
||||
int C, N, T;
|
||||
|
||||
C = args_has(args, 'C');
|
||||
@ -65,31 +65,41 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!C && !N && !T)
|
||||
C = N = T = 1;
|
||||
|
||||
filter = xcalloc(1, sizeof *filter);
|
||||
filter->type = ARGS_STRING;
|
||||
|
||||
if (C && N && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:"
|
||||
"#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}}",
|
||||
suffix, s, suffix, s, suffix, s);
|
||||
} else if (C && N) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (C && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (N && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{m%s:*%s*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (C)
|
||||
xasprintf(&filter, "#{C%s:%s}", suffix, s);
|
||||
else if (N)
|
||||
xasprintf(&filter, "#{m%s:*%s*,#{window_name}}", suffix, s);
|
||||
else
|
||||
xasprintf(&filter, "#{m%s:*%s*,#{pane_title}}", suffix, s);
|
||||
} else if (C) {
|
||||
xasprintf(&filter->string,
|
||||
"#{C%s:%s}",
|
||||
suffix, s);
|
||||
} else if (N) {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:*%s*,#{window_name}}",
|
||||
suffix, s);
|
||||
} else {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:*%s*,#{pane_title}}",
|
||||
suffix, s);
|
||||
}
|
||||
|
||||
new_args = args_create();
|
||||
if (args_has(args, 'Z'))
|
||||
@ -97,9 +107,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
args_set(new_args, 'f', filter);
|
||||
|
||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||
|
||||
args_free(new_args);
|
||||
free(filter);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
@ -804,7 +804,8 @@ cmd_parse_build_command(struct cmd_parse_command *cmd,
|
||||
return (cmdlist);
|
||||
|
||||
TAILQ_FOREACH(arg, &cmd->arguments, entry) {
|
||||
values = xreallocarray(values, count + 1, sizeof *values);
|
||||
values = xrecallocarray(values, count, count + 1,
|
||||
sizeof *values);
|
||||
switch (arg->type) {
|
||||
case CMD_PARSE_STRING:
|
||||
values[count].type = ARGS_STRING;
|
||||
|
4
tmux.h
4
tmux.h
@ -1369,6 +1369,7 @@ struct args_value {
|
||||
char *string;
|
||||
struct cmd_list *cmdlist;
|
||||
};
|
||||
char *cached;
|
||||
TAILQ_ENTRY(args_value) entry;
|
||||
};
|
||||
|
||||
@ -2196,7 +2197,7 @@ void tty_keys_free(struct tty *);
|
||||
int tty_keys_next(struct tty *);
|
||||
|
||||
/* arguments.c */
|
||||
void args_set(struct args *, u_char, const char *);
|
||||
void args_set(struct args *, u_char, struct args_value *);
|
||||
struct args *args_create(void);
|
||||
struct args *args_parse(const struct args_parse *, struct args_value *,
|
||||
u_int);
|
||||
@ -2210,6 +2211,7 @@ const char *args_get(struct args *, u_char);
|
||||
u_char args_first(struct args *, struct args_entry **);
|
||||
u_char args_next(struct args_entry **);
|
||||
u_int args_count(struct args *);
|
||||
struct args_value *args_value(struct args *, u_int);
|
||||
const char *args_string(struct args *, u_int);
|
||||
struct args_value *args_first_value(struct args *, u_char);
|
||||
struct args_value *args_next_value(struct args_value *);
|
||||
|
Loading…
Reference in New Issue
Block a user