Blob Blame History Raw
From eee15b862dd5b051f16c719bf3c974591783a8f8 Mon Sep 17 00:00:00 2001
From: Jim Warner <james.warner@comcast.net>
Date: Mon, 1 Jul 2013 00:00:00 -0500
Subject: [PATCH 2/2] top: cursor repositioning includes line oriented input

A recent patch introduced the ability to recognize the
need to reposition the cursor at suspension or program
end. There remained unmet 1 additional potential need.

This commit extends that ability to embrace line input
so that if a user issues ^Z or ^C while being prompted
the resulting shell output will no longer be embedded.

Reference(s):
http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,7
commit 5c974ff44da4fbbb9170dd15bdd81555c62c31a9

Signed-off-by: Jim Warner <james.warner@comcast.net>
---
 top/top.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/top/top.c b/top/top.c
index c1c61dd..138f3ee 100644
--- a/top/top.c
+++ b/top/top.c
@@ -1081,12 +1081,14 @@ static char *ioline (const char *prompt) {
    static char buf[MEDBUFSIZ];
    char *p;
 
+   Cursor_repos = 1;
    show_pmt(prompt);
    memset(buf, '\0', sizeof(buf));
    ioch(1, buf, sizeof(buf)-1);
 
    if ((p = strpbrk(buf, ws))) *p = '\0';
    // note: we DO produce a vaid 'string'
+   Cursor_repos = 0;
    return buf;
 } // end: ioline
 
@@ -1117,6 +1119,7 @@ static char *ioline (const char *prompt) {
    };
    static struct lin_s *anchor, *plin;
 
+   Cursor_repos = 1;
    if (!anchor) {
       anchor = alloc_c(sizeof(struct lin_s));
       anchor->str = alloc_s("");       // top-of-stack == empty str
@@ -1182,6 +1185,7 @@ static char *ioline (const char *prompt) {
       putp(tg2(beg+pos, Msg_row));
    } while (key && key != kbd_ENTER && key != kbd_ESC);
 
+   Cursor_repos = 0;
    // weed out duplicates, including empty strings (top-of-stack)...
    for (i = 0, plin = anchor; ; i++) {
 #ifdef RECALL_FIXED
-- 
1.8.1.2