mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-27 02:23:15 +01:00
Sort out escape key handling so it works.
This commit is contained in:
parent
792b4db4a7
commit
57f5f44d0f
7
CHANGES
7
CHANGES
@ -1,3 +1,8 @@
|
|||||||
|
02 March 2009
|
||||||
|
|
||||||
|
* Make escape key timer work properly so escape+key can be used without
|
||||||
|
lightning fast key presses.
|
||||||
|
|
||||||
13 February 2009
|
13 February 2009
|
||||||
|
|
||||||
* Redo mode keys slightly more cleanly and apply them to command prompt
|
* Redo mode keys slightly more cleanly and apply them to command prompt
|
||||||
@ -1114,7 +1119,7 @@
|
|||||||
(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.255 2009-02-13 21:39:45 nicm Exp $
|
$Id: CHANGES,v 1.256 2009-03-02 16:55:23 nicm Exp $
|
||||||
|
|
||||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||||
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||||
|
5
tmux.h
5
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.274 2009-02-21 17:46:13 nicm Exp $ */
|
/* $Id: tmux.h,v 1.275 2009-03-02 16:55:23 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -126,6 +126,9 @@ extern const char *__progname;
|
|||||||
/* Automatic name refresh interval, in milliseconds. */
|
/* Automatic name refresh interval, in milliseconds. */
|
||||||
#define NAME_INTERVAL 500
|
#define NAME_INTERVAL 500
|
||||||
|
|
||||||
|
/* Escape timer period, in milliseconds. */
|
||||||
|
#define ESCAPE_PERIOD 250
|
||||||
|
|
||||||
/* Fatal errors. */
|
/* Fatal errors. */
|
||||||
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
|
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
|
||||||
#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
|
#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
|
||||||
|
80
tty-keys.c
80
tty-keys.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tty-keys.c,v 1.22 2009-02-16 18:43:07 nicm Exp $ */
|
/* $Id: tty-keys.c,v 1.23 2009-03-02 16:55:23 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -239,41 +239,35 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse)
|
|||||||
/* If a normal key, return it. */
|
/* If a normal key, return it. */
|
||||||
if (*buf != '\033') {
|
if (*buf != '\033') {
|
||||||
*key = buffer_read8(tty->in);
|
*key = buffer_read8(tty->in);
|
||||||
return (0);
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for matching key string and return if found. */
|
/* Look for matching key string and return if found. */
|
||||||
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
||||||
if (tk != NULL) {
|
if (tk != NULL) {
|
||||||
*key = tk->key;
|
|
||||||
buffer_remove(tty->in, size + 1);
|
buffer_remove(tty->in, size + 1);
|
||||||
|
*key = tk->key;
|
||||||
tty->flags &= ~TTY_ESCAPE;
|
goto found;
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not found. Is this a mouse key press? */
|
/* Not found. Is this a mouse key press? */
|
||||||
*key = tty_keys_parse_mouse(tty, buf, len, &size, mouse);
|
*key = tty_keys_parse_mouse(tty, buf, len, &size, mouse);
|
||||||
if (*key != KEYC_NONE) {
|
if (*key != KEYC_NONE) {
|
||||||
buffer_remove(tty->in, size);
|
buffer_remove(tty->in, size);
|
||||||
|
goto found;
|
||||||
tty->flags &= ~TTY_ESCAPE;
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not found. Try to parse xterm-type arguments. */
|
/* Not found. Try to parse xterm-type arguments. */
|
||||||
*key = tty_keys_parse_xterm(tty, buf, len, &size);
|
*key = tty_keys_parse_xterm(tty, buf, len, &size);
|
||||||
if (*key != KEYC_NONE) {
|
if (*key != KEYC_NONE) {
|
||||||
buffer_remove(tty->in, size);
|
buffer_remove(tty->in, size);
|
||||||
|
goto found;
|
||||||
tty->flags &= ~TTY_ESCAPE;
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Escape but no key string. If the timer isn't started, start it. */
|
/* Escape but no key string. If the timer isn't started, start it. */
|
||||||
if (!(tty->flags & TTY_ESCAPE)) {
|
if (!(tty->flags & TTY_ESCAPE)) {
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 500 * 1000L;
|
tv.tv_usec = ESCAPE_PERIOD * 1000L;
|
||||||
if (gettimeofday(&tty->key_timer, NULL) != 0)
|
if (gettimeofday(&tty->key_timer, NULL) != 0)
|
||||||
fatal("gettimeofday");
|
fatal("gettimeofday");
|
||||||
timeradd(&tty->key_timer, &tv, &tty->key_timer);
|
timeradd(&tty->key_timer, &tv, &tty->key_timer);
|
||||||
@ -282,41 +276,39 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Otherwise, if the timer hasn't expired, wait. */
|
/* Skip the escape. */
|
||||||
|
buf++;
|
||||||
|
len--;
|
||||||
|
|
||||||
|
/* Is there a normal key following? */
|
||||||
|
if (len != 0 && *buf != '\033') {
|
||||||
|
buffer_remove(tty->in, 1);
|
||||||
|
*key = KEYC_ADDESC(buffer_read8(tty->in));
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Or a key string? */
|
||||||
|
if (len > 1) {
|
||||||
|
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
||||||
|
if (tk != NULL) {
|
||||||
|
buffer_remove(tty->in, size + 1);
|
||||||
|
*key = KEYC_ADDESC(tk->key);
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the timer hasn't expired, keep waiting . */
|
||||||
if (gettimeofday(&tv, NULL) != 0)
|
if (gettimeofday(&tv, NULL) != 0)
|
||||||
fatal("gettimeofday");
|
fatal("gettimeofday");
|
||||||
if (!timercmp(&tty->key_timer, &tv, >))
|
if (timercmp(&tty->key_timer, &tv, >))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
/* Give up and return the escape. */
|
||||||
|
buffer_remove(tty->in, 1);
|
||||||
|
*key = '\033';
|
||||||
|
|
||||||
|
found:
|
||||||
tty->flags &= ~TTY_ESCAPE;
|
tty->flags &= ~TTY_ESCAPE;
|
||||||
|
|
||||||
/* Remove the leading escape. */
|
|
||||||
buffer_remove(tty->in, 1);
|
|
||||||
buf = BUFFER_OUT(tty->in);
|
|
||||||
len = BUFFER_USED(tty->in);
|
|
||||||
|
|
||||||
/* If we have no following data, return escape. */
|
|
||||||
if (len == 0) {
|
|
||||||
*key = '\033';
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If a normal key follows, return it. */
|
|
||||||
if (*buf != '\033') {
|
|
||||||
*key = KEYC_ADDESC(buffer_read8(tty->in));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to look up the key. */
|
|
||||||
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
|
||||||
if (tk != NULL) {
|
|
||||||
*key = KEYC_ADDESC(tk->key);
|
|
||||||
buffer_remove(tty->in, size + 1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If not found, return escape-escape. */
|
|
||||||
*key = KEYC_ADDESC('\033');
|
|
||||||
buffer_remove(tty->in, 1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user