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
|
||||
|
||||
* 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
|
||||
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: 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>
|
||||
@ -126,6 +126,9 @@ extern const char *__progname;
|
||||
/* Automatic name refresh interval, in milliseconds. */
|
||||
#define NAME_INTERVAL 500
|
||||
|
||||
/* Escape timer period, in milliseconds. */
|
||||
#define ESCAPE_PERIOD 250
|
||||
|
||||
/* Fatal errors. */
|
||||
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
|
||||
#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
|
||||
|
66
tty-keys.c
66
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>
|
||||
@ -239,41 +239,35 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse)
|
||||
/* If a normal key, return it. */
|
||||
if (*buf != '\033') {
|
||||
*key = buffer_read8(tty->in);
|
||||
return (0);
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Look for matching key string and return if found. */
|
||||
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
||||
if (tk != NULL) {
|
||||
*key = tk->key;
|
||||
buffer_remove(tty->in, size + 1);
|
||||
|
||||
tty->flags &= ~TTY_ESCAPE;
|
||||
return (0);
|
||||
*key = tk->key;
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Not found. Is this a mouse key press? */
|
||||
*key = tty_keys_parse_mouse(tty, buf, len, &size, mouse);
|
||||
if (*key != KEYC_NONE) {
|
||||
buffer_remove(tty->in, size);
|
||||
|
||||
tty->flags &= ~TTY_ESCAPE;
|
||||
return (0);
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Not found. Try to parse xterm-type arguments. */
|
||||
*key = tty_keys_parse_xterm(tty, buf, len, &size);
|
||||
if (*key != KEYC_NONE) {
|
||||
buffer_remove(tty->in, size);
|
||||
|
||||
tty->flags &= ~TTY_ESCAPE;
|
||||
return (0);
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Escape but no key string. If the timer isn't started, start it. */
|
||||
if (!(tty->flags & TTY_ESCAPE)) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500 * 1000L;
|
||||
tv.tv_usec = ESCAPE_PERIOD * 1000L;
|
||||
if (gettimeofday(&tty->key_timer, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
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);
|
||||
}
|
||||
|
||||
/* Otherwise, if the timer hasn't expired, wait. */
|
||||
if (gettimeofday(&tv, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
if (!timercmp(&tty->key_timer, &tv, >))
|
||||
return (1);
|
||||
tty->flags &= ~TTY_ESCAPE;
|
||||
/* Skip the escape. */
|
||||
buf++;
|
||||
len--;
|
||||
|
||||
/* Remove the leading escape. */
|
||||
/* Is there a normal key following? */
|
||||
if (len != 0 && *buf != '\033') {
|
||||
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);
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Try to look up the key. */
|
||||
/* Or a key string? */
|
||||
if (len > 1) {
|
||||
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);
|
||||
*key = KEYC_ADDESC(tk->key);
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
||||
/* If not found, return escape-escape. */
|
||||
*key = KEYC_ADDESC('\033');
|
||||
/* If the timer hasn't expired, keep waiting . */
|
||||
if (gettimeofday(&tv, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
if (timercmp(&tty->key_timer, &tv, >))
|
||||
return (1);
|
||||
|
||||
/* Give up and return the escape. */
|
||||
buffer_remove(tty->in, 1);
|
||||
*key = '\033';
|
||||
|
||||
found:
|
||||
tty->flags &= ~TTY_ESCAPE;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user