From b9976f7056456b89a76d88dfc004b96925cd35dc Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 1 Mar 2013 00:00:00 -0600 Subject: [PATCH] top: finish the job of correcting the response to a ^Z if top is suspended while on the 2nd level help screen the key is no longer honored. Thus, users must use to exit help and return to the main display. Also, line input that was only partially complete when suspended would still require one additional keystroke before the read was aborted and the display refreshed. Lastly, some user interactions might require two input lines before an operation can be considered completed. Thus the 2nd line offers another opportunity for users to suspend top. Resumption would require an extra key. These issues stem from 2 recent enhancements: preserve the user context when signaled; complete input editing with cursor movement keys, insert/overtype modes, etc. With this patch, the key is once again honored on help screen #2 and partial reads are now completed. (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): bug reported http://www.freelists.org/post/procps/top-over-the-top,25 response to ^Z (partial solution) commit 5c3fffcf289c89f6a1171f18e33365f909d096d5 line input editing commit 477b10c0bd00ed8750c02a9580e606baadb0e6f4 preserve context with SIGWINCH commit ba9092ad83d37d9eb91ded49380a9bedeba4bac6 Signed-off-by: Jim Warner --- top/top.c | 12 ++++++++---- top/top.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/top/top.c b/top/top.c index 7372e809..bad453e0 100644 --- a/top/top.c +++ b/top/top.c @@ -966,7 +966,7 @@ static int iokey (int action) { const char *str; int key; } tinfo_tab[] = { - { "\n", kbd_ENTER }, { NULL, kbd_UP }, { NULL, kbd_DOWN }, + { "\033\n",kbd_ENTER }, { NULL, kbd_UP }, { NULL, kbd_DOWN }, { NULL, kbd_LEFT }, { NULL, kbd_RIGHT }, { NULL, kbd_PGUP }, { NULL, kbd_PGDN }, { NULL, kbd_HOME }, { NULL, kbd_END }, { NULL, kbd_BKSP }, { NULL, kbd_INS }, { NULL, kbd_DEL }, @@ -1115,7 +1115,7 @@ static char *ioline (const char *prompt) { case kbd_ESC: buf[0] = '\0'; // fall through ! case kbd_ENTER: - break; + continue; case kbd_INS: ovt = !ovt; putp(ovt ? Cap_curs_huge : Cap_curs_norm); @@ -1245,7 +1245,8 @@ static float get_float (const char *prompt) { char *line; float f; - if (!(*(line = ioline(prompt)))) return -1.0; + line = ioline(prompt); + if (!line[0] || Frames_resize) return -1.0; // note: we're not allowing negative floats if (strcspn(line, "+,.0123456789")) { show_msg(N_txt(BAD_numfloat_txt)); @@ -1265,7 +1266,9 @@ static int get_int (const char *prompt) { char *line; int n; - if (!(*(line = ioline(prompt)))) return GET_INTNONE; + line = ioline(prompt); + if (Frames_resize) return GET_INT_BAD; + if (!line[0]) return GET_INTNONE; // note: we've got to allow negative ints (renice) if (strcspn(line, "-+0123456789")) { show_msg(N_txt(BAD_integers_txt)); @@ -4097,6 +4100,7 @@ static void keys_global (int ch) { if (0 > pid) pid = def; str = ioline(fmtmk(N_fmt(GET_sigs_num_fmt), pid, SIGTERM)); if (*str) sig = signal_name_to_number(str); + if (Frames_resize) break; if (0 < sig && kill(pid, sig)) show_msg(fmtmk(N_fmt(FAIL_signals_fmt) , pid, sig, strerror(errno))); diff --git a/top/top.h b/top/top.h index b5af5264..b2bf67f8 100644 --- a/top/top.h +++ b/top/top.h @@ -141,7 +141,7 @@ char *strcasestr(const char *haystack, const char *needle); // support for keyboard stuff (cursor motion keystrokes, mostly) #define kbd_ESC '\033' #define kbd_SPACE ' ' -#define kbd_ENTER 128 +#define kbd_ENTER '\n' #define kbd_UP 129 #define kbd_DOWN 130 #define kbd_LEFT 131 -- 2.40.0