diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2011-01-04 00:42:46 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2011-01-04 00:42:46 +0000 |
commit | 7502cb3adbb26a2f94445a35626e64041d6769f9 (patch) | |
tree | 6ae4f33f69dc0a470dbe905b5140216fb19b8f01 /cmd-swap-pane.c | |
parent | ac3b78a84178a308536a56ea114b0f6f8ce6fb47 (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-swap-pane.c')
-rw-r--r-- | cmd-swap-pane.c | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index bf4b048e..8e0662dd 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -26,66 +26,58 @@ * Swap two panes. */ -void cmd_swap_pane_init(struct cmd *, int); +void cmd_swap_pane_key_binding(struct cmd *, int); int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_swap_pane_entry = { "swap-pane", "swapp", + "dDs:t:U", 0, 0, "[-dDU] " CMD_SRCDST_PANE_USAGE, - 0, "dDU", - cmd_swap_pane_init, - cmd_srcdst_parse, - cmd_swap_pane_exec, - cmd_srcdst_free, - cmd_srcdst_print + 0, + cmd_swap_pane_key_binding, + NULL, + cmd_swap_pane_exec }; void -cmd_swap_pane_init(struct cmd *self, int key) +cmd_swap_pane_key_binding(struct cmd *self, int key) { - struct cmd_target_data *data; - - cmd_srcdst_init(self, key); - data = self->data; - + self->args = args_create(0); if (key == '{') - cmd_set_flag(&data->chflags, 'U'); + args_set(self->args, 'U', NULL); else if (key == '}') - cmd_set_flag(&data->chflags, 'D'); + args_set(self->args, 'D', NULL); } - int cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_srcdst_data *data = self->data; + struct args *args = self->args; struct winlink *src_wl, *dst_wl; struct window *src_w, *dst_w; struct window_pane *tmp_wp, *src_wp, *dst_wp; struct layout_cell *src_lc, *dst_lc; u_int sx, sy, xoff, yoff; - if (data == NULL) - return (0); - - if ((dst_wl = cmd_find_pane(ctx, data->dst, NULL, &dst_wp)) == NULL) + dst_wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &dst_wp); + if (dst_wl == NULL) return (-1); dst_w = dst_wl->window; - if (data->src == NULL) { + if (!args_has(args, 's')) { src_w = dst_w; - if (cmd_check_flag(data->chflags, 'D')) { + if (args_has(self->args, 'D')) { src_wp = TAILQ_NEXT(dst_wp, entry); if (src_wp == NULL) src_wp = TAILQ_FIRST(&dst_w->panes); - } else if (cmd_check_flag(data->chflags, 'U')) { + } else if (args_has(self->args, 'U')) { src_wp = TAILQ_PREV(dst_wp, window_panes, entry); if (src_wp == NULL) src_wp = TAILQ_LAST(&dst_w->panes, window_panes); } else return (0); } else { - src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp); + src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp); if (src_wl == NULL) return (-1); src_w = src_wl->window; @@ -121,7 +113,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx) dst_wp->xoff = xoff; dst_wp->yoff = yoff; window_pane_resize(dst_wp, sx, sy); - if (!cmd_check_flag(data->chflags, 'd')) { + if (!args_has(self->args, 'd')) { if (src_w != dst_w) { window_set_active_pane(src_w, dst_wp); window_set_active_pane(dst_w, src_wp); |