Blame SOURCES/0001-top-enable-screen-contents-preservation-at-end-of-jo.patch

2006ba
From b765e587bf737efffbfe4fff087452de7a090708 Mon Sep 17 00:00:00 2001
2006ba
From: Jim Warner <james.warner@comcast.net>
2006ba
Date: Fri, 28 Jun 2013 00:00:00 -0500
2006ba
Subject: [PATCH] top: enable screen contents preservation at end-of-job
2006ba

2006ba
The title of this commit is actually quite misleading.
2006ba

2006ba
Were it more accurate, it would at least mention a tty
2006ba
emulator's scrollback buffer, which was the cumulation
2006ba
of a long pursuit to reduce the SIGWINCH overhead when
2006ba
a window manager carelessly floods an application with
2006ba
that signal *while* a user is still resizing a window!
2006ba

2006ba
Disabling and enabling that scrollback buffer resulted
2006ba
in the final top display replaced with original screen
2006ba
contents, a phenomenon acknowledged at the time but it
2006ba
also represented a user interface change which has now
2006ba
produced the first request for return to old behavior.
2006ba

2006ba
After the SIGWINCH dust settled, another problem arose
2006ba
regarding behaviors under the 'screen' window manager.
2006ba
In response, top was refactored a bit to avoid display
2006ba
corruption. That was before discovering 'screen' could
2006ba
duplicate the scrollback buffer behavior top expected.
2006ba

2006ba
As it turns out, the 'screen' refactoring had probably
2006ba
made scrollback buffer manipulation unnecessary. Still
2006ba
one could argue that a window should not be allowed to
2006ba
scroll while a constantly updating program was active.
2006ba

2006ba
The solution represented in this commit returns former
2006ba
behavior at program end (retaining top's last screen).
2006ba
And if we ever wish to disable scrollback buffers, the
2006ba
associated logic was retained but made conditional. It
2006ba
is not reflected in configure.ac but might be someday.
2006ba

2006ba
Lastly, this commit corrects cursor positioning when a
2006ba
^C is issued under 'Fields Management' at any terminal
2006ba
that didn't have a scrollback buffer (i.e. a console).
2006ba

2006ba
Reference(s):
2006ba
https://bugzilla.redhat.com/show_bug.cgi?id=977561
2006ba
http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,1
2006ba
. screen program refactor
2006ba
commit 0fe393ff270922cd4f6edbcaabba006314e73a37
2006ba
. scrollback buffer disabled
2006ba
commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d
2006ba
. sigwinch management defines
2006ba
commit adca737758e5afc7be344a736953931894cbc19f
2006ba
commit 4f33b6b8c56464b4044deb29a3bb0e32622e108f
2006ba

2006ba
Signed-off-by: Jim Warner <james.warner@comcast.net>
2006ba
---
2006ba
 top/top.c | 18 +++++++++++-------
2006ba
 top/top.h |  1 +
2006ba
 2 files changed, 12 insertions(+), 7 deletions(-)
2006ba

2006ba
diff --git a/top/top.c b/top/top.c
2006ba
index 1d38c0f..cdcf3c0 100644
2006ba
--- a/top/top.c
2006ba
+++ b/top/top.c
2006ba
@@ -72,8 +72,9 @@ static struct termios Tty_original,    // our inherited terminal definition
2006ba
                       Tty_raw;         // for unsolicited input
2006ba
 static int Ttychanged = 0;
2006ba
 
2006ba
-        /* Last established cursor state/shape */
2006ba
+        /* Last established cursor state/shape, and is re-position needed */
2006ba
 static const char *Cursor_state = "";
2006ba
+static int         Cursor_repos;
2006ba
 
2006ba
         /* Program name used in error messages and local 'rc' file name */
2006ba
 static char *Myname;
2006ba
@@ -350,12 +351,15 @@ static void at_eoj (void) {
2006ba
    if (Ttychanged) {
2006ba
       tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original);
2006ba
       if (keypad_local) putp(keypad_local);
2006ba
+      if (Cursor_repos) putp(tg2(0, Screen_rows));
2006ba
       putp("\n");
2006ba
+#ifdef OFF_SCROLLBK
2006ba
       if (exit_ca_mode) {
2006ba
          // this next will also replace top's most recent screen with the
2006ba
          // original display contents that were visible at our invocation
2006ba
          putp(exit_ca_mode);
2006ba
       }
2006ba
+#endif
2006ba
       putp(Cap_curs_norm);
2006ba
       putp(Cap_clr_eol);
2006ba
 #ifndef RMAN_IGNORED
2006ba
@@ -591,17 +595,13 @@ static void sig_endpgm (int dont_care_sig) {
2006ba
 
2006ba
         /*
2006ba
          * Catches:
2006ba
-         *    SIGTSTP, SIGTTIN and SIGTTOU
2006ba
-         * note:
2006ba
-         *    we don't fiddle with with those enter/exit_ca_mode strings
2006ba
-         *    because we want to retain most of the last screen contents
2006ba
-         *    as a visual reminder this program is suspended, not ended! */
2006ba
+         *    SIGTSTP, SIGTTIN and SIGTTOU */
2006ba
 static void sig_paused (int dont_care_sig) {
2006ba
 // POSIX.1-2004 async-signal-safe: tcsetattr, tcdrain, raise
2006ba
    if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original))
2006ba
       error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
2006ba
    if (keypad_local) putp(keypad_local);
2006ba
-   putp(tg2(0, Screen_rows));
2006ba
+   if (Cursor_repos) putp(tg2(0, Screen_rows));
2006ba
    putp(Cap_curs_norm);
2006ba
 #ifndef RMAN_IGNORED
2006ba
    putp(Cap_smam);
2006ba
@@ -2120,6 +2120,7 @@ static void fields_utility (void) {
2006ba
    int i, key;
2006ba
    FLG_t f;
2006ba
 
2006ba
+   Cursor_repos = 1;
2006ba
    spewFI
2006ba
 signify_that:
2006ba
    putp(Cap_clr_scr);
2006ba
@@ -2180,6 +2181,7 @@ signify_that:
2006ba
             break;
2006ba
       }
2006ba
    } while (key != 'q' && key != kbd_ESC);
2006ba
+   Cursor_repos = 0;
2006ba
  #undef unSCRL
2006ba
  #undef swapEM
2006ba
  #undef spewFI
2006ba
@@ -3768,8 +3770,10 @@ static void whack_terminal (void) {
2006ba
    // thanks anyway stdio, but we'll manage buffering at the frame level...
2006ba
    setbuffer(stdout, Stdout_buf, sizeof(Stdout_buf));
2006ba
 #endif
2006ba
+#ifdef OFF_SCROLLBK
2006ba
    // this has the effect of disabling any troublesome scrollback buffer...
2006ba
    if (enter_ca_mode) putp(enter_ca_mode);
2006ba
+#endif
2006ba
    // and don't forget to ask iokey to initialize his tinfo_tab
2006ba
    iokey(0);
2006ba
 } // end: whack_terminal
2006ba
diff --git a/top/top.h b/top/top.h
2006ba
index f356798..a8a7357 100644
2006ba
--- a/top/top.h
2006ba
+++ b/top/top.h
2006ba
@@ -41,6 +41,7 @@
2006ba
 //#define INSP_SAVEBUF            /* preserve 'Insp_buf' contents in a file  */
2006ba
 //#define INSP_SLIDE_1            /* when scrolling left/right don't move 8  */
2006ba
 //#define OFF_HST_HASH            /* use BOTH qsort+bsrch vs. hashing scheme */
2006ba
+//#define OFF_SCROLLBK            /* disable tty emulators scrollback buffer */
2006ba
 //#define OFF_STDIOLBF            /* disable our own stdout _IOFBF override  */
2006ba
 //#define PRETEND2_5_X            /* pretend we're linux 2.5.x (for IO-wait) */
2006ba
 //#define PRETEND8CPUS            /* pretend we're smp with 8 ticsers (sic)  */
2006ba
-- 
2006ba
1.8.1.2
2006ba