Implement ncurses extension has_key.

This commit is contained in:
roy 2017-01-01 03:06:06 +00:00
parent c0f2822a3c
commit 6de5f0d137
5 changed files with 40 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.2087 2016/12/31 22:47:01 roy Exp $
# $NetBSD: mi,v 1.2088 2017/01/01 03:06:06 roy Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@ -6740,6 +6740,7 @@
./usr/share/man/cat3/has_colors.0 comp-c-catman .cat
./usr/share/man/cat3/has_ic.0 comp-c-catman .cat
./usr/share/man/cat3/has_il.0 comp-c-catman .cat
./usr/share/man/cat3/has_key.0 comp-c-catman .cat
./usr/share/man/cat3/hash.0 comp-c-catman .cat
./usr/share/man/cat3/hcreate.0 comp-c-catman .cat
./usr/share/man/cat3/hcreate_r.0 comp-c-catman .cat
@ -14085,6 +14086,7 @@
./usr/share/man/html3/has_colors.html comp-c-htmlman html
./usr/share/man/html3/has_ic.html comp-c-htmlman html
./usr/share/man/html3/has_il.html comp-c-htmlman html
./usr/share/man/html3/has_key.html comp-c-htmlman html
./usr/share/man/html3/hash.html comp-c-htmlman html
./usr/share/man/html3/hcreate.html comp-c-htmlman html
./usr/share/man/html3/hcreate_r.html comp-c-htmlman html
@ -21347,6 +21349,7 @@
./usr/share/man/man3/has_colors.3 comp-c-man .man
./usr/share/man/man3/has_ic.3 comp-c-man .man
./usr/share/man/man3/has_il.3 comp-c-man .man
./usr/share/man/man3/has_key.3 comp-c-man .man
./usr/share/man/man3/hash.3 comp-c-man .man
./usr/share/man/man3/hcreate.3 comp-c-man .man
./usr/share/man/man3/hcreate_r.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.75 2016/12/31 22:47:01 roy Exp $
# $NetBSD: Makefile,v 1.76 2017/01/01 03:06:06 roy Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94
.include <bsd.own.mk>
@ -91,7 +91,8 @@ MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
curses_tty.3 gettmode.3 \
curses_cursor.3 getyx.3 curses_cursor.3 getsyx.3 \
curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \
curses_tty.3 halfdelay.3 curses_tty.3 has_il.3 \
curses_tty.3 halfdelay.3 curses_input.3 has_key.3 \
curses_tty.3 has_il.3 \
curses_line.3 hline.3 curses_tty.3 idcok.3 \
curses_tty.3 idlok.3 curses_inch.3 inch.3 \
curses_inch.3 inchnstr.3 curses_inch.3 inchstr.3 \

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.111 2016/12/31 22:47:01 roy Exp $ */
/* $NetBSD: curses.h,v 1.112 2017/01/01 03:06:06 roy Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -677,6 +677,7 @@ int halfdelay(int);
bool has_colors(void);
bool has_ic(void);
bool has_il(void);
int has_key(int);
int hline(chtype, int);
int idcok(WINDOW *, bool);
int idlok(WINDOW *, bool);

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses_input.3,v 1.22 2012/04/21 12:27:28 roy Exp $
.\" $NetBSD: curses_input.3,v 1.23 2017/01/01 03:06:06 roy Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\"
.Dd April 5, 2012
.Dd January 1, 2017
.Dt CURSES_INPUT 3
.Os
.Sh NAME
@ -41,6 +41,7 @@
.Nm mvwgetch ,
.Nm define_key ,
.Nm keyok ,
.Nm has_key ,
.Nm getnstr ,
.Nm wgetnstr ,
.Nm mvgetnstr ,
@ -71,6 +72,8 @@
.Ft int
.Fn keyok "int key_symbol" "bool flag"
.Ft int
.Fn has_key "int key_symbol"
.Ft int
.Fn define_key "char *sequence" "int key_symbol"
.Ft int
.Fn getnstr "char *str" "int limit"
@ -156,6 +159,13 @@ will behave as if the character sequence associated with that key symbol
was not recognised and will return the component characters one at a time to
the caller.
.Pp
The
.Fn has_key
function takes a key value and returns
.Dv TRUE
if the current terminal recognises a key with that value, otherwise
.Dv FALSE .
.Pp
Custom associations between sequences of characters and a key symbol can
be made by using the
.Fn define_key

View File

@ -1,4 +1,4 @@
/* $NetBSD: getch.c,v 1.59 2012/04/21 12:27:28 roy Exp $ */
/* $NetBSD: getch.c,v 1.60 2017/01/01 03:06:06 roy Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: getch.c,v 1.59 2012/04/21 12:27:28 roy Exp $");
__RCSID("$NetBSD: getch.c,v 1.60 2017/01/01 03:06:06 roy Exp $");
#endif
#endif /* not lint */
@ -216,7 +216,8 @@ static void add_key_sequence(SCREEN *screen, char *sequence, int key_type);
static key_entry_t *add_new_key(keymap_t *current, char ch, int key_type,
int symbol);
static void delete_key_sequence(keymap_t *current, int key_type);
static void do_keyok(keymap_t *current, int key_type, bool flag, int *retval);
static void do_keyok(keymap_t *current, int key_type, bool set, bool flag,
int *retval);
static keymap_t *new_keymap(void); /* create a new keymap */
static key_entry_t *new_key(void); /* create a new key entry */
static wchar_t inkey(int to, int delay);
@ -733,7 +734,7 @@ keyok(int key_type, bool flag)
{
int result = ERR;
do_keyok(_cursesi_screen->base_keymap, key_type, flag, &result);
do_keyok(_cursesi_screen->base_keymap, key_type, true, flag, &result);
return result;
}
@ -742,8 +743,8 @@ keyok(int key_type, bool flag)
* Does the actual work for keyok, we need to recurse through the
* keymaps finding the passed key symbol.
*/
void
do_keyok(keymap_t *current, int key_type, bool flag, int *retval)
static void
do_keyok(keymap_t *current, int key_type, bool set, bool flag, int *retval)
{
key_entry_t *key;
int i;
@ -759,9 +760,10 @@ do_keyok(keymap_t *current, int key_type, bool flag, int *retval)
key = current->key[current->mapping[i]];
if (key->type == KEYMAP_MULTI)
do_keyok(key->value.next, key_type, flag, retval);
do_keyok(key->value.next, key_type, set, flag, retval);
else if ((key->type == KEYMAP_LEAF)
&& (key->value.symbol == key_type)) {
if (set)
key->enable = flag;
*retval = OK; /* we found at least one instance, ok */
}
@ -966,3 +968,12 @@ __unget(wint_t c)
_cursesi_screen->unget_pos++;
return OK;
}
int
has_key(int key_type)
{
int result = ERR;
do_keyok(_cursesi_screen->base_keymap, key_type, false, false, &result);
return result;
}