Add ESCDELAY variable to control the inter-key delay in escape sequences.

Fixes PR 20031 by Thomas Klausner.
This commit is contained in:
jdc 2003-04-08 18:55:43 +00:00
parent 3068339e18
commit 7a37df1b93
3 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.73 2003/03/30 07:38:42 jdc Exp $ */
/* $NetBSD: curses.h,v 1.74 2003/04/08 18:55:43 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -312,6 +312,8 @@ extern int LINES; /* Lines on the screen. */
extern int COLORS; /* Max colours on the screen. */
extern int COLOR_PAIRS; /* Max colour pairs on the screen. */
extern int ESCDELAY; /* Delay between keys in esc seq's. */
#define ERR (0) /* Error return. */
#define OK (1) /* Success return. */

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses_input.3,v 1.7 2003/02/14 16:29:11 grant Exp $
.\" $NetBSD: curses_input.3,v 1.8 2003/04/08 18:55:43 jdc Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\"
.Dd August 12, 2002
.Dd April 8, 2003
.Dt CURSES_INPUT 3
.Os
.Sh NAME
@ -94,6 +94,8 @@
.Fn nodelay "WINDOW *win" "boolf flag"
.Ft int
.Fn ungetch "int c"
.Ft extern int
.Dv ESCDELAY
.Sh DESCRIPTION
These functions read characters and strings from the window input file
descriptor.
@ -275,7 +277,8 @@ If
is
.Dv FALSE ,
then the component characters of a multi-character sequence must not
have an inter-character gap of more than 200ms.
have an inter-character gap of more than
.Dv ESCDELAY .
If this timing is exceeded, then the multi-character key assembly is
deemed to have failed and the characters read thus far are returned
one at a time when
@ -283,6 +286,12 @@ one at a time when
is called.
The default setting for the flag is
.Dv FALSE .
The default value of
.Dv ESCDELAY
is 300ms. If
.Dv ESCDELAY
is negative, no timeout applied between characters comprising a
multi-character key sequence.
.Pp
The
.Fn timeout

View File

@ -1,4 +1,4 @@
/* $NetBSD: getch.c,v 1.40 2003/04/05 10:06:59 jdc Exp $ */
/* $NetBSD: getch.c,v 1.41 2003/04/08 18:55:43 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: getch.c,v 1.40 2003/04/05 10:06:59 jdc Exp $");
__RCSID("$NetBSD: getch.c,v 1.41 2003/04/08 18:55:43 jdc Exp $");
#endif
#endif /* not lint */
@ -49,7 +49,7 @@ __RCSID("$NetBSD: getch.c,v 1.40 2003/04/05 10:06:59 jdc Exp $");
#include "curses.h"
#include "curses_private.h"
#define DEFAULT_DELAY 3 /* default delay for timeout() */
int ESCDELAY=300; /* Delay in ms between keys for esc seq's */
/*
* Keyboard input handler. Do this by snarfing
@ -629,17 +629,17 @@ reread:
* out of keys in the
* backlog */
/* if we have then switch to
assembling */
/* if we have then switch to assembling */
state = INKEY_ASSEMBLING;
}
} else if (state == INKEY_ASSEMBLING) {
/* assembling a key sequence */
if (delay) {
if (__timeout(to ? DEFAULT_DELAY : delay) == ERR)
return ERR;
if (__timeout(to ? (ESCDELAY / 100) : delay)
== ERR)
return ERR;
} else {
if (to && (__timeout(DEFAULT_DELAY) == ERR))
if (to && (__timeout(ESCDELAY / 100) == ERR))
return ERR;
}