From ca8317e82058c30b2d18f28b00d099a6dee04098 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 4 Oct 2017 21:46:33 +0200 Subject: [PATCH] tweaks: reduce a bit of code duplication This also removes a call of ungetch(), as it does not seem to be needed any more: nano does not lose a character when waking from suspension. --- src/winio.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/winio.c b/src/winio.c index f143f348..f90d23dc 100644 --- a/src/winio.c +++ b/src/winio.c @@ -111,7 +111,7 @@ static bool reveal_cursor = FALSE; * buffer is empty. */ void get_key_buffer(WINDOW *win) { - int input; + int input = ERR; size_t errcount = 0; /* If the keystroke buffer isn't empty, get out. */ @@ -125,38 +125,27 @@ void get_key_buffer(WINDOW *win) if (reveal_cursor) curs_set(1); - /* Read in the first character using whatever mode we're in. */ - input = wgetch(win); - -#ifndef NANO_TINY - if (the_window_resized) { - ungetch(input); - regenerate_screen(); - input = KEY_WINCH; - } -#endif - - if (input == ERR && !waiting_mode) { - curs_set(0); - return; - } - + /* Read in the first keystroke using whatever mode we're in. */ while (input == ERR) { - /* If we've failed to get a character MAX_BUF_SIZE times in a row, - * assume our input source is gone and die gracefully. We could - * check if errno is set to EIO ("Input/output error") and die in - * that case, but it's not always set properly. Argh. */ - if (++errcount == MAX_BUF_SIZE) - die(_("Too many errors from stdin")); + input = wgetch(win); #ifndef NANO_TINY if (the_window_resized) { regenerate_screen(); input = KEY_WINCH; - break; } #endif - input = wgetch(win); + if (input == ERR && !waiting_mode) { + curs_set(0); + return; + } + + /* If we've failed to get a character MAX_BUF_SIZE times in a row, + * assume our input source is gone and die gracefully. We could + * check if errno is set to EIO ("Input/output error") and die in + * that case, but it's not always set properly. Argh. */ + if (input == ERR && ++errcount == MAX_BUF_SIZE) + die(_("Too many errors from stdin")); } curs_set(0);