diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-04 00:42:48 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-04 00:42:48 +0000 |
commit | 16cb3f3755ad38847f98c31f447e46392ac712fa (patch) | |
tree | 38c22cdaf8c376adff22781d854c9c5c67ed42ed /usr.bin/tmux/cmd-copy-mode.c | |
parent | 8e6a3ab86e7918f82355f33fa944cca1df578195 (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 'usr.bin/tmux/cmd-copy-mode.c')
-rw-r--r-- | usr.bin/tmux/cmd-copy-mode.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/usr.bin/tmux/cmd-copy-mode.c b/usr.bin/tmux/cmd-copy-mode.c index 93fe93aaa9b..f437cf6af94 100644 --- a/usr.bin/tmux/cmd-copy-mode.c +++ b/usr.bin/tmux/cmd-copy-mode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-copy-mode.c,v 1.11 2010/08/11 07:41:05 nicm Exp $ */ +/* $OpenBSD: cmd-copy-mode.c,v 1.12 2011/01/04 00:42:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -24,48 +24,40 @@ * Enter copy mode. */ -void cmd_copy_mode_init(struct cmd *, int); +void cmd_copy_mode_key_binding(struct cmd *, int); int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_copy_mode_entry = { "copy-mode", NULL, + "t:u", 0, 0, "[-u] " CMD_TARGET_PANE_USAGE, - 0, "u", - cmd_copy_mode_init, - cmd_target_parse, - cmd_copy_mode_exec, - cmd_target_free, - cmd_target_print + 0, + cmd_copy_mode_key_binding, + NULL, + cmd_copy_mode_exec }; void -cmd_copy_mode_init(struct cmd *self, int key) +cmd_copy_mode_key_binding(struct cmd *self, int key) { - struct cmd_target_data *data; - - cmd_target_init(self, key); - data = self->data; - - switch (key) { - case KEYC_PPAGE: - cmd_set_flag(&data->chflags, 'u'); - break; - } + self->args = args_create(0); + if (key == KEYC_PPAGE) + args_set(self->args, 'u', NULL); } int cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_target_data *data = self->data; + struct args *args = self->args; struct window_pane *wp; - if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL) + if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) return (-1); if (window_pane_set_mode(wp, &window_copy_mode) != 0) return (0); window_copy_init_from_pane(wp); - if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u')) + if (wp->mode == &window_copy_mode && args_has(self->args, 'u')) window_copy_pageup(wp); return (0); |