summaryrefslogtreecommitdiffstats
path: root/cmd-select-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-01-04 00:42:46 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-01-04 00:42:46 +0000
commit7502cb3adbb26a2f94445a35626e64041d6769f9 (patch)
tree6ae4f33f69dc0a470dbe905b5140216fb19b8f01 /cmd-select-window.c
parentac3b78a84178a308536a56ea114b0f6f8ce6fb47 (diff)
Clean up and simplify tmux command argument parsing.
Originally, tmux commands were parsed in the client process into a struct with the command data which was then serialised and sent to the server to be executed. The parsing was later moved into the server (an argv was sent from the client), but the parse step and intermediate struct was kept. This change removes that struct and the separate parse step. Argument parsing and printing is now common to all commands (in arguments.c) with each command left with just an optional check function (to validate the arguments at parse time), the exec function and a function to set up any key bindings (renamed from the old init function). This is overall more simple and consistent. There should be no changes to any commands behaviour or syntax although as this touches every command please watch for any unexpected changes.
Diffstat (limited to 'cmd-select-window.c')
-rw-r--r--cmd-select-window.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/cmd-select-window.c b/cmd-select-window.c
index 6aeaad22..c414af3a 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -26,39 +26,38 @@
* Select window by index.
*/
-void cmd_select_window_init(struct cmd *, int);
+void cmd_select_window_key_binding(struct cmd *, int);
int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw",
+ "t:", 0, 0,
CMD_TARGET_WINDOW_USAGE,
- 0, "",
- cmd_select_window_init,
- cmd_target_parse,
- cmd_select_window_exec,
- cmd_target_free,
- cmd_target_print
+ 0,
+ cmd_select_window_key_binding,
+ NULL,
+ cmd_select_window_exec
};
void
-cmd_select_window_init(struct cmd *self, int key)
+cmd_select_window_key_binding(struct cmd *self, int key)
{
- struct cmd_target_data *data;
+ char tmp[16];
- cmd_target_init(self, key);
- data = self->data;
+ xsnprintf(tmp, sizeof tmp, ":%d", key - '0');
- xasprintf(&data->target, ":%d", key - '0');
+ self->args = args_create(0);
+ args_set(self->args, 't', tmp);
}
int
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
- struct cmd_target_data *data = self->data;
- struct winlink *wl;
- struct session *s;
+ struct args *args = self->args;
+ struct winlink *wl;
+ struct session *s;
- if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
+ if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
return (-1);
if (session_select(s, wl->idx) == 0)