diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-05 12:04:51 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-05 12:04:51 +0000 |
commit | ef15b0d921140a942200e931b61dc9ecac63cbf9 (patch) | |
tree | 1d226632fc514f69ec9e0149c1f08e0fb149f525 /usr.bin | |
parent | feae79e5bc5f90d7b310b8e9c05102c388571843 (diff) |
key_string_lookup_key uses a static buffer, so copy its output into the working
buffer before calling the command print function which can also use it (eg
send-keys).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-list-keys.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c index f4b73e9017c..2d2baa88552 100644 --- a/usr.bin/tmux/cmd-list-keys.c +++ b/usr.bin/tmux/cmd-list-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-keys.c,v 1.7 2009/07/28 17:05:10 nicm Exp $ */ +/* $OpenBSD: cmd-list-keys.c,v 1.8 2009/11/05 12:04:50 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -47,7 +47,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx) struct cmd_target_data *data = self->data; struct key_binding *bd; const char *key; - char tmp[BUFSIZ], keytmp[64]; + char tmp[BUFSIZ]; + size_t used; int width, keywidth; if (data->target != NULL) @@ -70,14 +71,15 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx) key = key_string_lookup_key(bd->key & ~KEYC_PREFIX); if (key == NULL) continue; + if (!(bd->key & KEYC_PREFIX)) + used = xsnprintf(tmp, sizeof tmp, "[%s]: ", key); + else + used = xsnprintf(tmp, sizeof tmp, "%*s: ", width, key); + if (used >= sizeof tmp) + continue; - *tmp = '\0'; - cmd_list_print(bd->cmdlist, tmp, sizeof tmp); - if (!(bd->key & KEYC_PREFIX)) { - xsnprintf(keytmp, sizeof keytmp, "[%s]", key); - key = keytmp; - } - ctx->print(ctx, "%*s: %s", width, key, tmp); + cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used); + ctx->print(ctx, "%s", tmp); } return (0); |