mirror of
https://github.com/tmux/tmux.git
synced 2025-03-29 10:18:49 +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;
|
struct cmd_parse_result *pr;
|
||||||
char **argv;
|
char **argv;
|
||||||
int argc, repeat;
|
int argc, repeat;
|
||||||
|
struct args_value *value;
|
||||||
u_int count = args_count(args);
|
u_int count = args_count(args);
|
||||||
|
|
||||||
key = key_string_lookup_string(args_string(args, 0));
|
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";
|
tablename = "prefix";
|
||||||
repeat = args_has(args, 'r');
|
repeat = args_has(args, 'r');
|
||||||
|
|
||||||
if (count != 1) {
|
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
|
|
||||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
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);
|
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 cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *s = args_string(args, 0), *suffix = "";
|
const char *s = args_string(args, 0), *suffix = "";
|
||||||
char *filter;
|
struct args_value *filter;
|
||||||
int C, N, T;
|
int C, N, T;
|
||||||
|
|
||||||
C = args_has(args, 'C');
|
C = args_has(args, 'C');
|
||||||
@ -65,31 +65,41 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (!C && !N && !T)
|
if (!C && !N && !T)
|
||||||
C = N = T = 1;
|
C = N = T = 1;
|
||||||
|
|
||||||
|
filter = xcalloc(1, sizeof *filter);
|
||||||
|
filter->type = ARGS_STRING;
|
||||||
|
|
||||||
if (C && N && T) {
|
if (C && N && T) {
|
||||||
xasprintf(&filter,
|
xasprintf(&filter->string,
|
||||||
"#{||:"
|
"#{||:"
|
||||||
"#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}},"
|
"#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}},"
|
||||||
"#{m%s:*%s*,#{pane_title}}}}",
|
"#{m%s:*%s*,#{pane_title}}}}",
|
||||||
suffix, s, suffix, s, suffix, s);
|
suffix, s, suffix, s, suffix, s);
|
||||||
} else if (C && N) {
|
} else if (C && N) {
|
||||||
xasprintf(&filter,
|
xasprintf(&filter->string,
|
||||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}",
|
"#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}",
|
||||||
suffix, s, suffix, s);
|
suffix, s, suffix, s);
|
||||||
} else if (C && T) {
|
} else if (C && T) {
|
||||||
xasprintf(&filter,
|
xasprintf(&filter->string,
|
||||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}",
|
"#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}",
|
||||||
suffix, s, suffix, s);
|
suffix, s, suffix, s);
|
||||||
} else if (N && T) {
|
} else if (N && T) {
|
||||||
xasprintf(&filter,
|
xasprintf(&filter->string,
|
||||||
"#{||:#{m%s:*%s*,#{window_name}},"
|
"#{||:#{m%s:*%s*,#{window_name}},"
|
||||||
"#{m%s:*%s*,#{pane_title}}}",
|
"#{m%s:*%s*,#{pane_title}}}",
|
||||||
suffix, s, suffix, s);
|
suffix, s, suffix, s);
|
||||||
} else if (C)
|
} else if (C) {
|
||||||
xasprintf(&filter, "#{C%s:%s}", suffix, s);
|
xasprintf(&filter->string,
|
||||||
else if (N)
|
"#{C%s:%s}",
|
||||||
xasprintf(&filter, "#{m%s:*%s*,#{window_name}}", suffix, s);
|
suffix, s);
|
||||||
else
|
} else if (N) {
|
||||||
xasprintf(&filter, "#{m%s:*%s*,#{pane_title}}", suffix, s);
|
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();
|
new_args = args_create();
|
||||||
if (args_has(args, 'Z'))
|
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);
|
args_set(new_args, 'f', filter);
|
||||||
|
|
||||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||||
|
|
||||||
args_free(new_args);
|
args_free(new_args);
|
||||||
free(filter);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
@ -804,7 +804,8 @@ cmd_parse_build_command(struct cmd_parse_command *cmd,
|
|||||||
return (cmdlist);
|
return (cmdlist);
|
||||||
|
|
||||||
TAILQ_FOREACH(arg, &cmd->arguments, entry) {
|
TAILQ_FOREACH(arg, &cmd->arguments, entry) {
|
||||||
values = xreallocarray(values, count + 1, sizeof *values);
|
values = xrecallocarray(values, count, count + 1,
|
||||||
|
sizeof *values);
|
||||||
switch (arg->type) {
|
switch (arg->type) {
|
||||||
case CMD_PARSE_STRING:
|
case CMD_PARSE_STRING:
|
||||||
values[count].type = ARGS_STRING;
|
values[count].type = ARGS_STRING;
|
||||||
|
4
tmux.h
4
tmux.h
@ -1369,6 +1369,7 @@ struct args_value {
|
|||||||
char *string;
|
char *string;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
};
|
};
|
||||||
|
char *cached;
|
||||||
TAILQ_ENTRY(args_value) entry;
|
TAILQ_ENTRY(args_value) entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2196,7 +2197,7 @@ void tty_keys_free(struct tty *);
|
|||||||
int tty_keys_next(struct tty *);
|
int tty_keys_next(struct tty *);
|
||||||
|
|
||||||
/* arguments.c */
|
/* 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_create(void);
|
||||||
struct args *args_parse(const struct args_parse *, struct args_value *,
|
struct args *args_parse(const struct args_parse *, struct args_value *,
|
||||||
u_int);
|
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_first(struct args *, struct args_entry **);
|
||||||
u_char args_next(struct args_entry **);
|
u_char args_next(struct args_entry **);
|
||||||
u_int args_count(struct args *);
|
u_int args_count(struct args *);
|
||||||
|
struct args_value *args_value(struct args *, u_int);
|
||||||
const char *args_string(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_first_value(struct args *, u_char);
|
||||||
struct args_value *args_next_value(struct args_value *);
|
struct args_value *args_next_value(struct args_value *);
|
||||||
|
Loading…
Reference in New Issue
Block a user