} else {
return NULL;
}
- }
+ } else if (es.reason == NEWT_EXIT_ERROR)
+ return NULL;
return es.u.co;
}
}
}
+ if (key == NEWT_KEY_ERROR) {
+ es->u.watch = -1;
+ es->reason = NEWT_EXIT_ERROR;
+ done = 1;
+ }
+
if (!done) {
ev.event = EV_KEYPRESS;
ev.u.key = key;
}
int newtGetKey(void) {
- int key;
+ int key, lastcode, errors = 0;
unsigned char *chptr = keyreader_buf, *lastmatch;
- int lastcode;
struct kmap_trie_entry *curr = kmap_trie_root;
do {
key = getkey();
if (key == SLANG_GETKEY_ERROR) {
- /* Either garbage was read, or stdin disappeared
- * (the parent terminal was proably closed)
- */
if (needResize) {
needResize = 0;
return NEWT_KEY_RESIZE;
}
- /* ignore other signals */
+ /* Ignore other signals, but assume that stdin disappeared (the
+ * parent terminal was proably closed) if the error persists.
+ */
+ if (errors++ > 10)
+ return NEWT_KEY_ERROR;
+
continue;
}
if (key == NEWT_KEY_SUSPEND && suspendCallback)
suspendCallback(suspendCallbackData);
- } while (key == NEWT_KEY_SUSPEND);
+ } while (key == NEWT_KEY_SUSPEND || key == SLANG_GETKEY_ERROR);
/* Read more characters, matching against the trie as we go */
lastcode = *chptr = key;
struct newtExitStruct {
enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,
- NEWT_EXIT_TIMER } reason;
+ NEWT_EXIT_TIMER, NEWT_EXIT_ERROR } reason;
union {
int watch;
int key;
/* not really a key, but newtGetKey returns it */
#define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
+#define NEWT_KEY_ERROR NEWT_KEY_EXTRA_BASE + 114
#define NEWT_ANCHOR_LEFT (1 << 0)
#define NEWT_ANCHOR_RIGHT (1 << 1)