diff options
author | Tiago Cunha <tcunha@gmx.com> | 2011-01-07 14:45:34 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2011-01-07 14:45:34 +0000 |
commit | 1df427bc7b1a458f4d3fe6f9255010708a8d8634 (patch) | |
tree | 6d47a72a426bb3e18146c682591d398607a8a211 /cmd-select-layout.c | |
parent | 219442cff707a1febb6a75ba2cfe48b02ae0a22e (diff) |
Sync OpenBSD patchset 829:
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-layout.c')
-rw-r--r-- | cmd-select-layout.c | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/cmd-select-layout.c b/cmd-select-layout.c index e66a180f..a0d157dc 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-layout.c,v 1.12 2010-07-02 02:54:52 tcunha Exp $ */ +/* $Id: cmd-select-layout.c,v 1.13 2011-01-07 14:45:34 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -24,43 +24,40 @@ * Switch window to selected layout. */ -void cmd_select_layout_init(struct cmd *, int); +void cmd_select_layout_key_binding(struct cmd *, int); int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_layout_entry = { "select-layout", "selectl", + "t:", 0, 1, CMD_TARGET_WINDOW_USAGE " [layout-name]", - CMD_ARG01, "", - cmd_select_layout_init, - cmd_target_parse, - cmd_select_layout_exec, - cmd_target_free, - cmd_target_print + 0, + cmd_select_layout_key_binding, + NULL, + cmd_select_layout_exec }; void -cmd_select_layout_init(struct cmd *self, int key) +cmd_select_layout_key_binding(struct cmd *self, int key) { - struct cmd_target_data *data; - - cmd_target_init(self, key); - data = self->data; - switch (key) { - case ('1' | KEYC_ESCAPE): - data->arg = xstrdup("even-horizontal"); + case '1' | KEYC_ESCAPE: + self->args = args_create(1, "even-horizontal"); + break; + case '2' | KEYC_ESCAPE: + self->args = args_create(1, "even-vertical"); break; - case ('2' | KEYC_ESCAPE): - data->arg = xstrdup("even-vertical"); + case '3' | KEYC_ESCAPE: + self->args = args_create(1, "main-horizontal"); break; - case ('3' | KEYC_ESCAPE): - data->arg = xstrdup("main-horizontal"); + case '4' | KEYC_ESCAPE: + self->args = args_create(1, "main-vertical"); break; - case ('4' | KEYC_ESCAPE): - data->arg = xstrdup("main-vertical"); + case '5' | KEYC_ESCAPE: + self->args = args_create(1, "tiled"); break; - case ('5' | KEYC_ESCAPE): - data->arg = xstrdup("tiled"); + default: + self->args = args_create(0); break; } } @@ -68,26 +65,32 @@ cmd_select_layout_init(struct cmd *self, int key) int cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_target_data *data = self->data; - struct winlink *wl; - int layout; + struct args *args = self->args; + struct winlink *wl; + const char *layoutname; + int layout; - if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) + if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); - if (data->arg == NULL) { + if (args->argc == 0) layout = wl->window->lastlayout; - if (layout == -1) - return (0); - } else if ((layout = layout_set_lookup(data->arg)) != -1) { + else + layout = layout_set_lookup(args->argv[0]); + if (layout != -1) { layout = layout_set_select(wl->window, layout); ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); - } else { - if (layout_parse(wl->window, data->arg) == -1) { - ctx->error(ctx, "can't set layout: %s", data->arg); + return (0); + } + + if (args->argc != 0) { + layoutname = args->argv[0]; + if (layout_parse(wl->window, layoutname) == -1) { + ctx->error(ctx, "can't set layout: %s", layoutname); return (-1); } - ctx->info(ctx, "arranging in: %s", data->arg); + ctx->info(ctx, "arranging in: %s", layoutname); + return (0); } return (0); |