List keys command.

This commit is contained in:
Nicholas Marriott 2007-10-04 00:18:59 +00:00
parent 815815989a
commit 292ad55fbe
5 changed files with 102 additions and 15 deletions

View File

@ -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 .SUFFIXES: .c .o .y .h
.PHONY: clean .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 \ 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 \ 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-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 YACC= yacc -d

59
cmd-list-keys.c Normal file
View File

@ -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);
}

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
#include "tmux.h" #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_error(struct cmd_ctx *, const char *, ...);
void key_bindings_print(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 }, { 'd', &cmd_detach_session_entry },
{ 'S', &cmd_list_sessions_entry }, { 'S', &cmd_list_sessions_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 },
{ 'c', &cmd_new_window_entry }, { 'c', &cmd_new_window_entry },
{ 'N', &cmd_next_window_entry }, { 'N', &cmd_next_window_entry },
@ -108,6 +110,8 @@ key_bindings_init(void)
u_int i; u_int i;
struct cmd *cmd; struct cmd *cmd;
ARRAY_INIT(&key_bindings);
for (i = 0; i < (sizeof table / sizeof table[0]); i++) { for (i = 0; i < (sizeof table / sizeof table[0]); i++) {
cmd = xmalloc(sizeof *cmd); cmd = xmalloc(sizeof *cmd);
cmd->entry = table[i].entry; cmd->entry = table[i].entry;

View File

@ -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> * 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]) #define NKEYSTRINGS (sizeof key_string_table / sizeof key_string_table[0])
int int
key_string_lookup(const char *string) key_string_lookup_string(const char *string)
{ {
u_int i; u_int i;
@ -221,3 +221,22 @@ key_string_lookup(const char *string)
} }
return (KEYC_NONE); 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);
}

23
tmux.h
View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -459,6 +459,7 @@ struct client_ctx {
enum cmd_type { enum cmd_type {
CMD_DETACHSESSION, CMD_DETACHSESSION,
CMD_LASTWINDOW, CMD_LASTWINDOW,
CMD_LISTKEYS,
CMD_LISTSESSIONS, CMD_LISTSESSIONS,
CMD_NEWSESSION, CMD_NEWSESSION,
CMD_NEWWINDOW, CMD_NEWWINDOW,
@ -504,6 +505,7 @@ struct binding {
int key; int key;
struct cmd *cmd; struct cmd *cmd;
}; };
ARRAY_DECL(bindings, struct binding *);
/* tmux.c */ /* tmux.c */
extern volatile sig_atomic_t sigwinch; extern volatile sig_atomic_t sigwinch;
@ -525,13 +527,14 @@ struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *); void cmd_free(struct cmd *);
void cmd_send_string(struct buffer *, const char *); void cmd_send_string(struct buffer *, const char *);
char *cmd_recv_string(struct buffer *); char *cmd_recv_string(struct buffer *);
extern const struct cmd_entry cmd_detach_session_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_last_window_entry;
extern const struct cmd_entry cmd_list_sessions_entry; extern const struct cmd_entry cmd_list_keys_entry;
extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_list_sessions_entry;
extern const struct cmd_entry cmd_new_window_entry; extern const struct cmd_entry cmd_new_session_entry;
extern const struct cmd_entry cmd_next_window_entry; extern const struct cmd_entry cmd_new_window_entry;
extern const struct cmd_entry cmd_previous_window_entry; extern const struct cmd_entry cmd_next_window_entry;
extern const struct cmd_entry cmd_previous_window_entry;
/* bind.c */ /* bind.c */
const struct bind *cmdx_lookup_bind(const char *); const struct bind *cmdx_lookup_bind(const char *);
@ -556,6 +559,7 @@ void client_write_server2(
void client_fill_sessid(struct sessid *, char [MAXNAMELEN]); void client_fill_sessid(struct sessid *, char [MAXNAMELEN]);
/* key-bindings.c */ /* key-bindings.c */
extern struct bindings key_bindings;
void key_bindings_add(int, struct cmd *); void key_bindings_add(int, struct cmd *);
void key_bindings_remove(int); void key_bindings_remove(int);
void key_bindings_init(void); void key_bindings_init(void);
@ -563,7 +567,8 @@ void key_bindings_free(void);
void key_bindings_dispatch(int, struct client *); void key_bindings_dispatch(int, struct client *);
/* key-string.c */ /* 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 */ /* server.c */
extern struct clients clients; extern struct clients clients;