Added experimental feature NEW_KEYBOARD_HIT.

This commit is contained in:
Bart House
2019-07-09 22:30:34 -07:00
parent 0e8163e341
commit bc65112ce0
14 changed files with 199 additions and 3 deletions

View File

@@ -101,6 +101,9 @@ struct window_procs safe_procs = {
safe_status_update,
#endif
safe_can_suspend,
#ifdef NEW_KEYBOARD_HIT
safe_keyboard_hit
#endif
};
struct window_procs *
@@ -386,6 +389,14 @@ safe_can_suspend()
return FALSE;
}
#ifdef NEW_KEYBOARD_HIT
boolean
safe_keyboard_hit()
{
return FALSE;
}
#endif
void
safe_nhbell()
{

View File

@@ -36,6 +36,12 @@ extern void msmsg(const char *, ...);
#endif
#endif
#ifdef NEW_KEYBOARD_HIT
#if defined(UNIX)
#include <fcntl.h>
#endif
#endif
#ifdef TTY_TILES_ESCCODES
extern short glyph2tile[];
#define TILE_ANSI_COMMAND 'z'
@@ -133,6 +139,9 @@ struct window_procs tty_procs = {
genl_status_update,
#endif
genl_can_suspend_yes,
#ifdef NEW_KEYBOARD_HIT
tty_keyboard_hit
#endif
};
static int maxwin = 0; /* number of windows in use */
@@ -3479,6 +3488,7 @@ const char *str;
#endif
}
#ifndef NEW_KEYBOARD_HIT
int
tty_nhgetch()
{
@@ -3533,6 +3543,93 @@ tty_nhgetch()
#endif /* TTY_TILES_ESCCODES */
return i;
}
#else /* NEW_KEYBOARD_HIT */
#ifdef UNIX
static boolean stdin_non_blocking = FALSE;
int
tgetch()
{
static volatile int nesting = 0;
int i;
char nestbuf;
if (stdin_non_blocking) {
fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
stdin_non_blocking = FALSE;
}
/* kludge alert: Some Unix variants return funny values if getc()
* is called, interrupted, and then called again. There
* is non-reentrant code in the internal _filbuf() routine, called by
* getc().
*/
i = (++nesting == 1)
? getchar()
: (read(fileno(stdin), (genericptr_t) &nestbuf, 1) == 1)
? (int) nestbuf : EOF;
--nesting;
return i;
}
boolean
tkbhit()
{
int i;
if (!stdin_non_blocking) {
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
stdin_non_blocking = TRUE;
}
i = getchar();
if (i != EOF) ungetc(i, stdin);
return (i != EOF);
}
#endif
int
tty_nhgetch()
{
int i;
HUPSKIP_RESULT('\033');
print_vt_code1(AVTC_INLINE_SYNC);
(void) fflush(stdout);
/* Note: if raw_print() and wait_synch() get called to report terminal
* initialization problems, then wins[] and ttyDisplay might not be
* available yet. Such problems will probably be fatal before we get
* here, but validate those pointers just in case...
*/
if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE])
wins[WIN_MESSAGE]->flags &= ~WIN_STOP;
if (iflags.debug_fuzzer) {
i = randomkey();
} else {
i = tgetch();
}
if (!i)
i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
else if (i == EOF)
i = '\033'; /* same for EOF */
if (ttyDisplay && ttyDisplay->toplin == 1)
ttyDisplay->toplin = 2;
#ifdef TTY_TILES_ESCCODES
{
/* hack to force output of the window select code */
int tmp = vt_tile_current_window;
vt_tile_current_window++;
print_vt_code2(AVTC_SELECT_WINDOW, tmp);
}
#endif /* TTY_TILES_ESCCODES */
return i;
}
boolean tty_keyboard_hit()
{
/* tgetch provider needs to also provide tkbhit() */
return tkbhit();
}
#endif /* NEW_KEYBOARD_HIT */
/*
* return a key, or 0, in which case a mouse button was pressed

View File

@@ -116,6 +116,9 @@ struct window_procs mswin_procs = {
mswin_status_init, mswin_status_finish, mswin_status_enablefield,
mswin_status_update,
genl_can_suspend_yes,
#ifdef NEW_KEYBOARD_HIT
mswin_keyboard_hit
#endif
};
/*
@@ -1402,6 +1405,15 @@ mswin_nhgetch()
return (key);
}
#ifdef NEW_KEYBOARD_HIT
/* boolean keyboard_hit() -- returns TRUE if input is available */
boolean
mswin_keyboard_hit()
{
return mswin_have_input() != 0;
}
#endif
/*
int nh_poskey(int *x, int *y, int *mod)
-- Returns a single character input from the user or a

View File

@@ -167,6 +167,9 @@ void mswin_raw_print(const char *str);
void mswin_raw_print_bold(const char *str);
void mswin_raw_print_flush();
int mswin_nhgetch(void);
#ifdef NEW_KEYBOARD_HIT
boolean mswin_keyboard_hit(void);
#endif
int mswin_nh_poskey(int *x, int *y, int *mod);
void mswin_nhbell(void);
int mswin_doprev_message(void);