diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-07-21 22:41:00 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-07-21 22:41:00 +0000 |
commit | e43b6a2dd2a52b49cd92481fc09074b595e83386 (patch) | |
tree | b599b7ff19d429229cffcd1ff31ca7f1f3bfaf46 /cmd-list-keys.c | |
parent | 3eb6080de39f995cc2fb90c63dc314e98ac169df (diff) | |
download | rtmux-e43b6a2dd2a52b49cd92481fc09074b595e83386.tar.gz rtmux-e43b6a2dd2a52b49cd92481fc09074b595e83386.tar.bz2 rtmux-e43b6a2dd2a52b49cd92481fc09074b595e83386.zip |
Adjust field width to fit longest key when listing.
Diffstat (limited to 'cmd-list-keys.c')
-rw-r--r-- | cmd-list-keys.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 17612449..af3a0208 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -18,6 +18,8 @@ #include <sys/types.h> +#include <string.h> + #include "tmux.h" /* @@ -45,6 +47,18 @@ cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx) struct key_binding *bd; const char *key; char tmp[BUFSIZ]; + int width, keywidth; + + width = 0; + SPLAY_FOREACH(bd, key_bindings, &key_bindings) { + if ((key = key_string_lookup_key(bd->key)) == NULL) + continue; + + keywidth = strlen(key) + 1; + if (keywidth > width) + width = keywidth; + } + SPLAY_FOREACH(bd, key_bindings, &key_bindings) { if ((key = key_string_lookup_key(bd->key)) == NULL) @@ -52,7 +66,8 @@ cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx) *tmp = '\0'; cmd_list_print(bd->cmdlist, tmp, sizeof tmp); - ctx->print(ctx, "%11s: %s", key, tmp); + + ctx->print(ctx, "%*s: %s", width, key, tmp); } return (0); |