diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-22 12:38:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-22 12:38:11 +0000 |
commit | 1f7e7007af7bfef7a9dc88c2a09832a90603076f (patch) | |
tree | 1aacba34d320ef343052c32237caa928513afd82 /usr.bin/tmux/options-cmd.c | |
parent | 849dd7297d7a8729f4fc89b9322ebaad270aa091 (diff) |
Permit multiple prefix keys to be defined, separated by commas, for example:
set -g prefix ^a,^b
Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.
Diffstat (limited to 'usr.bin/tmux/options-cmd.c')
-rw-r--r-- | usr.bin/tmux/options-cmd.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/usr.bin/tmux/options-cmd.c b/usr.bin/tmux/options-cmd.c index e6107f9b3c1..7aeae3b63d1 100644 --- a/usr.bin/tmux/options-cmd.c +++ b/usr.bin/tmux/options-cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-cmd.c,v 1.4 2009/09/21 14:56:03 nicm Exp $ */ +/* $OpenBSD: options-cmd.c,v 1.5 2009/09/22 12:38:10 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -28,6 +28,8 @@ set_option_print(const struct set_option_entry *entry, struct options_entry *o) { static char out[BUFSIZ]; const char *s; + struct keylist *keylist; + u_int i; *out = '\0'; switch (entry->type) { @@ -37,9 +39,14 @@ set_option_print(const struct set_option_entry *entry, struct options_entry *o) case SET_OPTION_NUMBER: xsnprintf(out, sizeof out, "%lld", o->num); break; - case SET_OPTION_KEY: - s = key_string_lookup_key(o->num); - xsnprintf(out, sizeof out, "%s", s); + case SET_OPTION_KEYS: + keylist = o->data; + for (i = 0; i < ARRAY_LENGTH(keylist); i++) { + strlcat(out, key_string_lookup_key( + ARRAY_ITEM(keylist, i)), sizeof out); + if (i != ARRAY_LENGTH(keylist) - 1) + strlcat(out, ",", sizeof out); + } break; case SET_OPTION_COLOUR: s = colour_tostring(o->num); @@ -114,23 +121,35 @@ set_option_number(struct cmd_ctx *ctx, struct options *oo, } void -set_option_key(struct cmd_ctx *ctx, struct options *oo, +set_option_keys(struct cmd_ctx *ctx, struct options *oo, const struct set_option_entry *entry, char *value) { struct options_entry *o; - int key; + struct keylist *keylist; + char *copyvalue, *ptr, *str; + int key; if (value == NULL) { ctx->error(ctx, "empty value"); return; } - if ((key = key_string_lookup_string(value)) == KEYC_NONE) { - ctx->error(ctx, "unknown key: %s", value); - return; + keylist = xmalloc(sizeof *keylist); + ARRAY_INIT(keylist); + + ptr = copyvalue = xstrdup(value); + while ((str = strsep(&ptr, ",")) != NULL) { + if ((key = key_string_lookup_string(str)) == KEYC_NONE) { + xfree(keylist); + ctx->error(ctx, "unknown key: %s", str); + xfree(copyvalue); + return; + } + ARRAY_ADD(keylist, key); } + xfree(copyvalue); - o = options_set_number(oo, entry->name, key); + o = options_set_data(oo, entry->name, keylist, xfree); ctx->info( ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); } |