131 lines
4.5 KiB
Diff
131 lines
4.5 KiB
Diff
From 46a1356219cfab67240704af9cd73b58a20d4232 Mon Sep 17 00:00:00 2001
|
|
From: Jim Warner <james.warner@comcast.net>
|
|
Date: Sat, 6 Jul 2013 00:00:00 -0500
|
|
Subject: [PATCH] top: correct cursor positioning for all ^Z or ^C cases
|
|
|
|
Some more (very obscure) conditions where a suspension
|
|
or program end might embed the shell prompt within top
|
|
output have been uncovered beyond the 2 already known.
|
|
|
|
We had already covered some suspend/end contingencies:
|
|
1. the users were using the 'fields management' screen
|
|
2. the users were prompted for any line oriented input
|
|
|
|
However, there remained some situations where ^Z or ^C
|
|
could still produce a misplaced cursor + shell prompt:
|
|
3. the 'g' command while waiting for the window choice
|
|
4. the 'W' command if about to overwrite an old rcfile
|
|
5. the '=' command when exploiting the Inspect feature
|
|
6. the period during which any error message was shown
|
|
|
|
But, even when all those bases are covered there still
|
|
remains a remote possibility that such interrupts will
|
|
occur during a top repaint cycle. So rather than throw
|
|
yet more code at these self-inflicted problems perhaps
|
|
it is better if we just throw in the proverbial towel.
|
|
|
|
Thus, I'll take the only sane approach and restore the
|
|
results expected ever since top's inception and before
|
|
scrollback buffers entered the picture. Namely, with a
|
|
^Z or ^C the cursor will be placed on the final screen
|
|
row. That usually means it will immediately follow the
|
|
last output line but it may follow many blank lines if
|
|
the user interrupts top when *not* on the main screen.
|
|
|
|
Reference(s):
|
|
. expanded repositioning (for line oriented input)
|
|
commit 33104a2bcc321495107d72e4cfee4090b1d90f76
|
|
. introduced repositioning (for fields management)
|
|
commit 5c974ff44da4fbbb9170dd15bdd81555c62c31a9
|
|
. scrollback buffers (the cursor handling changes)
|
|
commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d
|
|
|
|
Signed-off-by: Jim Warner <james.warner@comcast.net>
|
|
---
|
|
top/top.c | 13 +++----------
|
|
1 file changed, 3 insertions(+), 10 deletions(-)
|
|
|
|
diff --git top/top.c top/top.c
|
|
index 8978cd1..e2451f5 100644
|
|
--- top/top.c
|
|
+++ top/top.c
|
|
@@ -72,9 +72,8 @@ static struct termios Tty_original, // our inherited terminal definition
|
|
Tty_raw; // for unsolicited input
|
|
static int Ttychanged = 0;
|
|
|
|
- /* Last established cursor state/shape, and is re-position needed */
|
|
+ /* Last established cursor state/shape */
|
|
static const char *Cursor_state = "";
|
|
-static int Cursor_repos;
|
|
|
|
/* Program name used in error messages and local 'rc' file name */
|
|
static char *Myname;
|
|
@@ -351,7 +350,7 @@ static void at_eoj (void) {
|
|
if (Ttychanged) {
|
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original);
|
|
if (keypad_local) putp(keypad_local);
|
|
- if (Cursor_repos) putp(tg2(0, Screen_rows));
|
|
+ putp(tg2(0, Screen_rows));
|
|
putp("\n");
|
|
#ifdef OFF_SCROLLBK
|
|
if (exit_ca_mode) {
|
|
@@ -602,7 +601,7 @@ static void sig_paused (int dont_care_sig) {
|
|
if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original))
|
|
error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
|
|
if (keypad_local) putp(keypad_local);
|
|
- if (Cursor_repos) putp(tg2(0, Screen_rows));
|
|
+ putp(tg2(0, Screen_rows));
|
|
putp(Cap_curs_norm);
|
|
#ifndef RMAN_IGNORED
|
|
putp(Cap_smam);
|
|
@@ -1081,14 +1080,12 @@ 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
|
|
|
|
@@ -1119,7 +1116,6 @@ 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
|
|
@@ -1185,7 +1181,6 @@ 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
|
|
@@ -2126,7 +2121,6 @@ static void fields_utility (void) {
|
|
int i, key;
|
|
FLG_t f;
|
|
|
|
- Cursor_repos = 1;
|
|
spewFI
|
|
signify_that:
|
|
putp(Cap_clr_scr);
|
|
@@ -2187,7 +2181,6 @@ signify_that:
|
|
break;
|
|
}
|
|
} while (key != 'q' && key != kbd_ESC);
|
|
- Cursor_repos = 0;
|
|
#undef unSCRL
|
|
#undef swapEM
|
|
#undef spewFI
|
|
--
|
|
1.7.9.2
|
|
|