aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-10-04 00:18:59 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-10-04 00:18:59 +0000
commit292ad55fbef698de9e6e8c66b10bbcdc2a39e212 (patch)
treea9f75ad5ad9174217b858b0a25891364f702458d
parent815815989a103cda0d88fa0670b774b1e3530509 (diff)
downloadrtmux-292ad55fbef698de9e6e8c66b10bbcdc2a39e212.tar.gz
rtmux-292ad55fbef698de9e6e8c66b10bbcdc2a39e212.tar.bz2
rtmux-292ad55fbef698de9e6e8c66b10bbcdc2a39e212.zip
List keys command.
-rw-r--r--Makefile4
-rw-r--r--cmd-list-keys.c59
-rw-r--r--key-bindings.c8
-rw-r--r--key-string.c23
-rw-r--r--tmux.h23
5 files changed, 102 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index db78143d..3580c27e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.15 2007-10-04 00:02:10 nicm Exp $
+# $Id: Makefile,v 1.16 2007-10-04 00:18:59 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean
@@ -21,7 +21,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
session.c local.c log.c client.c client-msg.c client-fn.c key-string.c \
key-bindings.c cmd.c cmd-new-session.c cmd-detach-session.c \
cmd-list-sessions.c cmd-new-window.c cmd-next-window.c \
- cmd-previous-window.c cmd-last-window.c
+ cmd-previous-window.c cmd-last-window.c cmd-list-keys.c
YACC= yacc -d
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
new file mode 100644
index 00000000..9134db40
--- /dev/null
+++ b/cmd-list-keys.c
@@ -0,0 +1,59 @@
+/* $Id: cmd-list-keys.c,v 1.1 2007-10-04 00:18:59 nicm Exp $ */
+
+/*
+ * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <getopt.h>
+#include <string.h>
+
+#include "tmux.h"
+
+/*
+ * List key bindings.
+ */
+
+void cmd_list_keys_exec(void *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_list_keys_entry = {
+ CMD_LISTKEYS, "list-keys", "lsk", CMD_NOSESSION,
+ NULL,
+ NULL,
+ cmd_list_keys_exec,
+ NULL,
+ NULL,
+ NULL
+};
+
+void
+cmd_list_keys_exec(unused void *ptr, struct cmd_ctx *ctx)
+{
+ struct client *c = ctx->client;
+ struct binding *bd;
+ const char *key;
+ u_int i;
+
+ for (i = 0; i < ARRAY_LENGTH(&key_bindings); i++) {
+ bd = ARRAY_ITEM(&key_bindings, i);
+ if ((key = key_string_lookup_key(bd->key)) == NULL)
+ continue;
+ ctx->print(ctx, "%11s: %s", key, bd->cmd->entry->name);
+ }
+
+ if (!(ctx->flags & CMD_KEY))
+ server_write_client(c, MSG_EXIT, NULL, 0);
+}
diff --git a/key-bindings.c b/key-bindings.c
index 6693a583..0c802a95 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -1,4 +1,4 @@
-/* $Id: key-bindings.c,v 1.3 2007-10-04 00:02:10 nicm Exp $ */
+/* $Id: key-bindings.c,v 1.4 2007-10-04 00:18:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,7 +24,7 @@
#include "tmux.h"
-ARRAY_DECL(, struct binding *) key_bindings;
+struct bindings key_bindings;
void key_bindings_error(struct cmd_ctx *, const char *, ...);
void key_bindings_print(struct cmd_ctx *, const char *, ...);
@@ -80,6 +80,8 @@ key_bindings_init(void)
{ 'd', &cmd_detach_session_entry },
{ 'S', &cmd_list_sessions_entry },
{ 's', &cmd_list_sessions_entry },
+ { '?', &cmd_list_keys_entry },
+ { '/', &cmd_list_keys_entry },
{ 'C', &cmd_new_window_entry },
{ 'c', &cmd_new_window_entry },
{ 'N', &cmd_next_window_entry },
@@ -108,6 +110,8 @@ key_bindings_init(void)
u_int i;
struct cmd *cmd;
+ ARRAY_INIT(&key_bindings);
+
for (i = 0; i < (sizeof table / sizeof table[0]); i++) {
cmd = xmalloc(sizeof *cmd);
cmd->entry = table[i].entry;
diff --git a/key-string.c b/key-string.c
index 5740ef6b..5ce1aa59 100644
--- a/key-string.c
+++ b/key-string.c
@@ -1,4 +1,4 @@
-/* $Id: key-string.c,v 1.1 2007-10-03 11:26:34 nicm Exp $ */
+/* $Id: key-string.c,v 1.2 2007-10-04 00:18:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -206,7 +206,7 @@ struct {
#define NKEYSTRINGS (sizeof key_string_table / sizeof key_string_table[0])
int
-key_string_lookup(const char *string)
+key_string_lookup_string(const char *string)
{
u_int i;
@@ -221,3 +221,22 @@ key_string_lookup(const char *string)
}
return (KEYC_NONE);
}
+
+const char *
+key_string_lookup_key(int key)
+{
+ static char tmp[2];
+ u_int i;
+
+ if (key > 31 && key < 256) {
+ tmp[0] = key;
+ tmp[1] = '\0';
+ return (tmp);
+ }
+
+ for (i = 0; i < NKEYSTRINGS; i++) {
+ if (key == key_string_table[i].key)
+ return (key_string_table[i].string);
+ }
+ return (NULL);
+}
diff --git a/tmux.h b/tmux.h
index cb6805ce..e78bc107 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.40 2007-10-04 00:02:10 nicm Exp $ */
+/* $Id: tmux.h,v 1.41 2007-10-04 00:18:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -459,6 +459,7 @@ struct client_ctx {
enum cmd_type {
CMD_DETACHSESSION,
CMD_LASTWINDOW,
+ CMD_LISTKEYS,
CMD_LISTSESSIONS,
CMD_NEWSESSION,
CMD_NEWWINDOW,
@@ -504,6 +505,7 @@ struct binding {
int key;
struct cmd *cmd;
};
+ARRAY_DECL(bindings, struct binding *);
/* tmux.c */
extern volatile sig_atomic_t sigwinch;
@@ -525,13 +527,14 @@ struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *);
void cmd_send_string(struct buffer *, const char *);
char *cmd_recv_string(struct buffer *);
-extern const struct cmd_entry cmd_detach_session_entry;
-extern const struct cmd_entry cmd_last_window_entry;
-extern const struct cmd_entry cmd_list_sessions_entry;
-extern const struct cmd_entry cmd_new_session_entry;
-extern const struct cmd_entry cmd_new_window_entry;
-extern const struct cmd_entry cmd_next_window_entry;
-extern const struct cmd_entry cmd_previous_window_entry;
+extern const struct cmd_entry cmd_detach_session_entry;
+extern const struct cmd_entry cmd_last_window_entry;
+extern const struct cmd_entry cmd_list_keys_entry;
+extern const struct cmd_entry cmd_list_sessions_entry;
+extern const struct cmd_entry cmd_new_session_entry;
+extern const struct cmd_entry cmd_new_window_entry;
+extern const struct cmd_entry cmd_next_window_entry;
+extern const struct cmd_entry cmd_previous_window_entry;
/* bind.c */
const struct bind *cmdx_lookup_bind(const char *);
@@ -556,6 +559,7 @@ void client_write_server2(
void client_fill_sessid(struct sessid *, char [MAXNAMELEN]);
/* key-bindings.c */
+extern struct bindings key_bindings;
void key_bindings_add(int, struct cmd *);
void key_bindings_remove(int);
void key_bindings_init(void);
@@ -563,7 +567,8 @@ void key_bindings_free(void);
void key_bindings_dispatch(int, struct client *);
/* key-string.c */
-int key_string_lookup(const char *);
+int key_string_lookup_string(const char *);
+const char *key_string_lookup_key(int);
/* server.c */
extern struct clients clients;