Allow use of alt keys. move-window command.

This commit is contained in:
Nicholas Marriott 2008-06-25 20:33:20 +00:00
parent eb5638f3e7
commit 7836298f29
9 changed files with 104 additions and 83 deletions

View File

@ -1,5 +1,8 @@
25 June 2008 25 June 2008
* move-window command.
* Support binding alt keys (prefixed with M-). Change default to use
C- for ctrl keys (^ is still accepted as an alternative).
* Slim down default key bindings: support lowercase only. * Slim down default key bindings: support lowercase only.
* Handle escaped keys properly (parse eg \033b into a single key code) and * Handle escaped keys properly (parse eg \033b into a single key code) and
use this to change copy mode next/previous work to M-f and M-b to match use this to change copy mode next/previous work to M-f and M-b to match
@ -567,4 +570,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.142 2008-06-25 19:18:20 nicm Exp $ $Id: CHANGES,v 1.143 2008-06-25 20:33:20 nicm Exp $

View File

@ -1,4 +1,4 @@
# $Id: GNUmakefile,v 1.33 2008-06-23 22:24:16 nicm Exp $ # $Id: GNUmakefile,v 1.34 2008-06-25 20:33:20 nicm Exp $
.PHONY: clean .PHONY: clean
@ -28,7 +28,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \ cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \
cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \ cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \
cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \ cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \
cmd-list-commands.c \ cmd-list-commands.c cmd-move-window.c \
window-scroll.c window-more.c window-copy.c options.c paste.c \ window-scroll.c window-more.c window-copy.c options.c paste.c \
tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.66 2008-06-23 22:24:16 nicm Exp $ # $Id: Makefile,v 1.67 2008-06-25 20:33:20 nicm Exp $
.SUFFIXES: .c .o .y .h .SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html .PHONY: clean update-index.html upload-index.html
@ -32,7 +32,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \ cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \
cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \ cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \
cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \ cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \
cmd-list-commands.c \ cmd-list-commands.c cmd-move-window.c \
window-scroll.c window-more.c window-copy.c options.c paste.c \ window-scroll.c window-more.c window-copy.c options.c paste.c \
tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c

2
TODO
View File

@ -49,7 +49,7 @@
-- For 0.4 -------------------------------------------------------------------- -- For 0.4 --------------------------------------------------------------------
- document list-commands. document switch-client - document list-commands. document switch-client. document move-window
- document buffer stuff - document buffer stuff
- document next/prev word - document next/prev word
- commands: - commands:

View File

@ -1,4 +1,4 @@
/* $Id: cmd-link-window.c,v 1.23 2008-06-18 22:21:51 nicm Exp $ */ /* $Id: cmd-link-window.c,v 1.24 2008-06-25 20:33:20 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -46,29 +46,29 @@ void
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_srcdst_data *data = self->data; struct cmd_srcdst_data *data = self->data;
struct session *s; struct session *dst;
struct winlink *wl_src, *wl_dst; struct winlink *wl_src, *wl_dst;
int idx; int idx;
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL) if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
return; return;
if (arg_parse_window(data->dst, &s, &idx) != 0) { if (arg_parse_window(data->dst, &dst, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->dst); ctx->error(ctx, "bad window: %s", data->dst);
return; return;
} }
if (s == NULL) if (dst == NULL)
s = ctx->cursession; dst = ctx->cursession;
if (s == NULL) if (dst == NULL)
s = cmd_current_session(ctx); dst = cmd_current_session(ctx);
if (s == NULL) { if (dst == NULL) {
ctx->error(ctx, "session not found: %s", data->dst); ctx->error(ctx, "session not found: %s", data->dst);
return; return;
} }
wl_dst = NULL; wl_dst = NULL;
if (idx != -1) if (idx != -1)
wl_dst = winlink_find_by_index(&s->windows, idx); wl_dst = winlink_find_by_index(&dst->windows, idx);
if (wl_dst != NULL) { if (wl_dst != NULL) {
if (wl_dst->window == wl_src->window) if (wl_dst->window == wl_src->window)
goto out; goto out;
@ -78,35 +78,30 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
* Can't use session_detach as it will destroy session * Can't use session_detach as it will destroy session
* if this makes it empty. * if this makes it empty.
*/ */
session_alert_cancel(s, wl_dst); session_alert_cancel(dst, wl_dst);
winlink_remove(&s->windows, wl_dst); winlink_remove(&dst->windows, wl_dst);
/* Force select/redraw if current. */ /* Force select/redraw if current. */
if (wl_dst == s->curw) { if (wl_dst == dst->curw) {
data->flags &= ~CMD_DFLAG; data->flags &= ~CMD_DFLAG;
s->curw = NULL; dst->curw = NULL;
} }
if (wl_dst == s->lastw) if (wl_dst == dst->lastw)
s->lastw = NULL; dst->lastw = NULL;
/*
* Can't error out after this or there could be an
* empty session!
*/
} }
} }
wl_dst = session_attach(s, wl_src->window, idx); wl_dst = session_attach(dst, wl_src->window, idx);
if (wl_dst == NULL) { if (wl_dst == NULL) {
ctx->error(ctx, "index in use: %d", idx); ctx->error(ctx, "index in use: %d", idx);
return; return;
} }
if (data->flags & CMD_DFLAG) if (data->flags & CMD_DFLAG)
server_status_session(s); server_status_session(dst);
else { else {
session_select(s, wl_dst->idx); session_select(dst, wl_dst->idx);
server_redraw_session(s); server_redraw_session(dst);
} }
recalculate_sizes(); recalculate_sizes();

3
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.56 2008-06-23 22:24:16 nicm Exp $ */ /* $Id: cmd.c,v 1.57 2008-06-25 20:33:20 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -45,6 +45,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_list_keys_entry, &cmd_list_keys_entry,
&cmd_list_sessions_entry, &cmd_list_sessions_entry,
&cmd_list_windows_entry, &cmd_list_windows_entry,
&cmd_move_window_entry,
&cmd_new_session_entry, &cmd_new_session_entry,
&cmd_new_window_entry, &cmd_new_window_entry,
&cmd_next_window_entry, &cmd_next_window_entry,

View File

@ -1,4 +1,4 @@
/* $Id: key-string.c,v 1.5 2008-06-04 20:01:36 nicm Exp $ */ /* $Id: key-string.c,v 1.6 2008-06-25 20:33:20 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -173,39 +173,7 @@ struct {
{ "SUNDO", KEYC_SUNDO }, { "SUNDO", KEYC_SUNDO },
{ "SUSPEND", KEYC_SUSPEND }, { "SUSPEND", KEYC_SUSPEND },
{ "UNDO", KEYC_UNDO }, { "UNDO", KEYC_UNDO },
{ "UP", KEYC_UP }, { "UP", KEYC_UP }
{ "^ ", 0 },
{ "^A", 1 },
{ "^B", 2 },
{ "^C", 3 },
{ "^D", 4 },
{ "^E", 5 },
{ "^F", 6 },
{ "^G", 7 },
{ "^H", 8 },
{ "^I", 9 },
{ "^J", 10 },
{ "^K", 11 },
{ "^L", 12 },
{ "^M", 13 },
{ "^N", 14 },
{ "^O", 15 },
{ "^P", 16 },
{ "^Q", 17 },
{ "^R", 18 },
{ "^S", 19 },
{ "^T", 20 },
{ "^U", 21 },
{ "^V", 22 },
{ "^W", 23 },
{ "^X", 24 },
{ "^Y", 25 },
{ "^Z", 26 },
{ "^[", 27 },
{ "^\\", 28 },
{ "^]", 29 },
{ "^^", 30 },
{ "^_", 31 }
}; };
#define NKEYSTRINGS (sizeof key_string_table / sizeof key_string_table[0]) #define NKEYSTRINGS (sizeof key_string_table / sizeof key_string_table[0])
@ -213,12 +181,39 @@ int
key_string_lookup_string(const char *string) key_string_lookup_string(const char *string)
{ {
u_int i; u_int i;
int key;
if (string[0] == '\0') if (string[0] == '\0')
return (KEYC_NONE); return (KEYC_NONE);
if (string[1] == '\0') if (string[1] == '\0')
return (string[0]); return (string[0]);
if (string[0] == 'C' && string[1] == '-') {
if (string[2] == '\0' || string[3] != '\0')
return (KEYC_NONE);
if (string[2] >= 64 && string[2] <= 95)
return (string[2] - 64);
if (string[2] >= 97 && string[2] <= 122)
return (string[2] - 96);
return (KEYC_NONE);
}
if (string[0] == '^') {
if (string[1] == '\0' || string[2] != '\0')
return (KEYC_NONE);
if (string[1] >= 64 && string[1] <= 95)
return (string[1] - 64);
if (string[1] >= 97 && string[1] <= 122)
return (string[1] - 96);
return (KEYC_NONE);
}
if (string[0] == 'M' && string[1] == '-') {
if ((key = key_string_lookup_string(string + 2)) == KEYC_NONE)
return (KEYC_NONE);
return (KEYC_ADDESCAPE(key));
}
for (i = 0; i < NKEYSTRINGS; i++) { for (i = 0; i < NKEYSTRINGS; i++) {
if (strcasecmp(string, key_string_table[i].string) == 0) if (strcasecmp(string, key_string_table[i].string) == 0)
return (key_string_table[i].key); return (key_string_table[i].key);
@ -229,15 +224,34 @@ key_string_lookup_string(const char *string)
const char * const char *
key_string_lookup_key(int key) key_string_lookup_key(int key)
{ {
static char tmp[2]; static char tmp[24], tmp2[24];
const char *s;
u_int i; u_int i;
if (key > 31 && key < 256) { if (key == 127)
return (NULL);
if (KEYC_ISESCAPE(key)) {
if ((s = key_string_lookup_key(KEYC_REMOVEESCAPE(key))) == NULL)
return (NULL);
xsnprintf(tmp2, sizeof tmp2, "M-%s", s);
return (tmp2);
}
if (key >= 32 && key <= 255) {
tmp[0] = key; tmp[0] = key;
tmp[1] = '\0'; tmp[1] = '\0';
return (tmp); return (tmp);
} }
if (key >= 0 && key <= 32) {
if (key == 0 || key > 26)
xsnprintf(tmp, sizeof tmp, "C-%c", 64 + key);
else
xsnprintf(tmp, sizeof tmp, "C-%c", 96 + key);
return (tmp);
}
for (i = 0; i < NKEYSTRINGS; i++) { for (i = 0; i < NKEYSTRINGS; i++) {
if (key == key_string_table[i].key) if (key == key_string_table[i].key)
return (key_string_table[i].string); return (key_string_table[i].string);

37
tmux.1
View File

@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.42 2008-06-19 22:14:12 nicm Exp $ .\" $Id: tmux.1,v 1.43 2008-06-25 20:33:20 nicm Exp $
.\" .\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\" .\"
@ -112,30 +112,30 @@ $
.Ed .Ed
.Pp .Pp
Within an active session, a new window may be created by typing Within an active session, a new window may be created by typing
.Ql ^B .Ql C-b
(ctrl-B, known as the prefix key) (ctrl-b, known as the prefix key)
followed by the followed by the
.Ql c .Ql c
key. key.
.Pp .Pp
Windows may be navigated with: Windows may be navigated with:
.Ql ^B 0 .Ql C-b 0
(to select window 0), (to select window 0),
.Ql ^B 1 .Ql C-b 1
(to select window 1), and so on; (to select window 1), and so on;
.Ql ^B n .Ql C-b n
to select the next window; and to select the next window; and
.Ql ^B p .Ql C-b p
to select the previous window. to select the previous window.
.Pp .Pp
A session may be detached using A session may be detached using
.Ql ^B d .Ql C-b d
and reattached with: and reattached with:
.Pp .Pp
.Dl $ tmux attach-session .Dl $ tmux attach-session
.Pp .Pp
Typing Typing
.Ql ^B \&? .Ql C-b \&?
lists the current key bindings in the current window; up and down may be used lists the current key bindings in the current window; up and down may be used
to navigate the list or to navigate the list or
.Ql Q .Ql Q
@ -144,8 +144,8 @@ to exit from it.
.Nm .Nm
may be controlled from an attached client by using a key combination of a may be controlled from an attached client by using a key combination of a
prefix key, prefix key,
.Ql ^B .Ql C-b
(ctrl-B) by default, followed by a command key. (ctrl-b) by default, followed by a command key.
.Pp .Pp
Some of the default key bindings include: Some of the default key bindings include:
.Pp .Pp
@ -227,9 +227,9 @@ This permits a section of a window or its history to be copied to the
for later insertion into another window. for later insertion into another window.
The navigation keys move the cursor around the window, scrolling as necessary. The navigation keys move the cursor around the window, scrolling as necessary.
In addition, In addition,
.Ql ^A .Ql C-a
and and
.Ql ^E .Ql C-e
(or the (or the
.Xr vi 1 .Xr vi 1
style style
@ -238,7 +238,7 @@ and
.Ql $ .Ql $
keys) move to the start and end of the line; the space key begins a selection; keys) move to the start and end of the line; the space key begins a selection;
and the enter key or and the enter key or
.Ql ^W .Ql C-w
copies the selection to the paste buffer and exits copy mode. copies the selection to the paste buffer and exits copy mode.
.Pp .Pp
This mode is entered with the This mode is entered with the
@ -333,6 +333,13 @@ Bind key
.Ar key .Ar key
to to
.Ar command . .Ar command .
Keys may be specified prefixed with
.Ql C-
or
.Ql ^
for ctrl keys, or
.Ql M-
for alt (meta) keys.
.It Xo Ic command-prompt .It Xo Ic command-prompt
.Op Fl t Ar target-client .Op Fl t Ar target-client
.Xc .Xc
@ -525,7 +532,7 @@ Send a key or keys to a window.
Each argument Each argument
.Ar key .Ar key
is the name of the key (such as is the name of the key (such as
.Ql ^A .Ql C-a
or or
.Ql npage .Ql npage
) to send; if the string is not recognised as a key, it is sent as a series of ) to send; if the string is not recognised as a key, it is sent as a series of

3
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.168 2008-06-25 07:30:08 nicm Exp $ */ /* $Id: tmux.h,v 1.169 2008-06-25 20:33:20 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -958,6 +958,7 @@ extern const struct cmd_entry cmd_list_commands_entry;
extern const struct cmd_entry cmd_list_keys_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_list_sessions_entry;
extern const struct cmd_entry cmd_list_windows_entry; extern const struct cmd_entry cmd_list_windows_entry;
extern const struct cmd_entry cmd_move_window_entry;
extern const struct cmd_entry cmd_new_session_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_new_window_entry;
extern const struct cmd_entry cmd_next_window_entry; extern const struct cmd_entry cmd_next_window_entry;