aboutsummaryrefslogtreecommitdiff
path: root/ui_getc.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui_getc.c')
-rw-r--r--ui_getc.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/ui_getc.c b/ui_getc.c
index 9d3c76df530d..5be01b88626b 100644
--- a/ui_getc.c
+++ b/ui_getc.c
@@ -1,9 +1,9 @@
/*
- * $Id: ui_getc.c,v 1.70 2018/06/14 00:05:05 tom Exp $
+ * $Id: ui_getc.c,v 1.80 2020/11/25 01:08:30 tom Exp $
*
* ui_getc.c - user interface glue for getc()
*
- * Copyright 2001-2013,2018 Thomas E. Dickey
+ * Copyright 2001-2019,2020 Thomas E. Dickey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License, version 2.1
@@ -23,6 +23,7 @@
#include <dialog.h>
#include <dlg_keys.h>
+#include <dlg_internals.h>
#ifdef NEED_WCHAR_H
#include <wchar.h>
@@ -68,7 +69,7 @@ dlg_add_callback(DIALOG_CALLBACK * p)
{
p->next = dialog_state.getc_callbacks;
dialog_state.getc_callbacks = p;
- wtimeout(p->win, WTIMEOUT_VAL);
+ dlg_set_timeout(p->win, TRUE);
}
/*
@@ -150,9 +151,11 @@ handle_inputs(WINDOW *win)
}
}
}
- if (result) {
+ if (result && _dlg_find_window(win)) {
(void) wmove(win, cur_y, cur_x); /* Restore cursor position */
wrefresh(win);
+ } else {
+ result = FALSE;
}
if (state != ERR)
curs_set(state);
@@ -187,15 +190,17 @@ check_inputs(void)
DIALOG_CALLBACK *p;
fd_set read_fds;
struct timeval test;
- int last_fd = -1;
- int fd;
- int found;
int result = -1;
if ((p = dialog_state.getc_callbacks) != 0) {
+ int last_fd = -1;
+ int found;
+ int fd;
+
FD_ZERO(&read_fds);
while (p != 0) {
+
p->input_ready = FALSE;
if (p->input != 0 && (fd = fileno(p->input)) >= 0) {
FD_SET(fd, &read_fds);
@@ -252,10 +257,12 @@ dlg_getc_callbacks(int ch, int fkey, int *result)
static void
dlg_raise_window(WINDOW *win)
{
- touchwin(win);
- wmove(win, getcury(win), getcurx(win));
- wnoutrefresh(win);
- doupdate();
+ if (_dlg_find_window(win)) {
+ touchwin(win);
+ wmove(win, getcury(win), getcurx(win));
+ wnoutrefresh(win);
+ doupdate();
+ }
}
/*
@@ -313,6 +320,7 @@ dlg_add_last_key(int mode)
} else {
char temp[80];
sprintf(temp, "%d", last_getc);
+ DLG_TRACE(("# dlg_add_last_key(%s)\n", temp));
dlg_add_string(temp);
if (mode == -1)
dlg_add_separator();
@@ -343,9 +351,7 @@ really_getch(WINDOW *win, int *fkey)
{
int ch;
#ifdef USE_WIDE_CURSES
- int code;
mbstate_t state;
- wchar_t my_wchar;
wint_t my_wint;
/*
@@ -353,6 +359,9 @@ really_getch(WINDOW *win, int *fkey)
* having to change the rest of the code to use wide-characters.
*/
if (used_last_getc >= have_last_getc) {
+ int code;
+ wchar_t my_wchar;
+
used_last_getc = 0;
have_last_getc = 0;
ch = ERR;
@@ -441,18 +450,16 @@ dlg_getc(WINDOW *win, int *fkey)
bool done = FALSE;
bool literal = FALSE;
DIALOG_CALLBACK *p = 0;
- int interval = (dialog_vars.timeout_secs * 1000);
+ int interval = dlg_set_timeout(win, may_handle_inputs());
time_t expired = time((time_t *) 0) + dialog_vars.timeout_secs;
time_t current;
- if (may_handle_inputs())
- wtimeout(win, WTIMEOUT_VAL);
- else if (interval > 0)
- wtimeout(win, interval);
-
while (!done) {
bool handle_others = FALSE;
+ if (_dlg_find_window(win) == NULL)
+ break;
+
/*
* If there was no pending file-input, check the keyboard.
*/
@@ -481,13 +488,19 @@ dlg_getc(WINDOW *win, int *fkey)
keypad(win, FALSE);
continue;
case CHR_REPAINT:
- (void) touchwin(win);
- (void) wrefresh(curscr);
+ if (_dlg_find_window(win)) {
+ (void) touchwin(win);
+ (void) wrefresh(curscr);
+ }
break;
case ERR: /* wtimeout() in effect; check for file I/O */
if (interval > 0
&& current >= expired) {
+ int status;
DLG_TRACE(("# dlg_getc: timeout expired\n"));
+ if (dlg_getenv_num("DIALOG_TIMEOUT", &status)) {
+ dlg_exiterr("timeout");
+ }
ch = ESC;
done = TRUE;
} else if (!valid_file(stdin)
@@ -496,7 +509,7 @@ dlg_getc(WINDOW *win, int *fkey)
ch = ESC;
done = TRUE;
} else if (check_inputs()) {
- if (handle_inputs(win))
+ if (_dlg_find_window(win) && handle_inputs(win))
dlg_raise_window(win);
else
done = TRUE;
@@ -505,7 +518,7 @@ dlg_getc(WINDOW *win, int *fkey)
}
break;
case DLGK_HELPFILE:
- if (dialog_vars.help_file) {
+ if (dialog_vars.help_file && _dlg_find_window(win)) {
int yold, xold;
getyx(win, yold, xold);
dialog_helpfile("HELP", dialog_vars.help_file, 0, 0);
@@ -575,7 +588,7 @@ dlg_getc(WINDOW *win, int *fkey)
}
}
}
- if (literal)
+ if (literal && _dlg_find_window(win))
keypad(win, TRUE);
return ch;
}
@@ -596,7 +609,6 @@ void
dlg_killall_bg(int *retval)
{
DIALOG_CALLBACK *cb;
- int pid;
#ifdef HAVE_TYPE_UNIONWAIT
union wait wstatus;
#else
@@ -613,6 +625,7 @@ dlg_killall_bg(int *retval)
}
}
if (dialog_state.getc_callbacks != 0) {
+ int pid;
refresh();
fflush(stdout);
@@ -620,7 +633,7 @@ dlg_killall_bg(int *retval)
reset_shell_mode();
if ((pid = fork()) != 0) {
_exit(pid > 0 ? DLG_EXIT_OK : DLG_EXIT_ERROR);
- } else if (pid == 0) { /* child */
+ } else { /* child, pid==0 */
if ((pid = fork()) != 0) {
/*
* Echo the process-id of the grandchild so a shell script
@@ -650,7 +663,7 @@ dlg_killall_bg(int *retval)
;
#endif
_exit(WEXITSTATUS(wstatus));
- } else if (pid == 0) {
+ } else { /* child, pid==0 */
if (!dialog_vars.cant_kill)
(void) signal(SIGHUP, finish_bg);
(void) signal(SIGINT, finish_bg);