public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: pty: Use redraw screen instead of clear screen.
Date: Wed, 13 Nov 2019 09:17:00 -0000	[thread overview]
Message-ID: <20191113091734.36684.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7ef4290a98edca60cfbab44327384f8ad6b471da

commit 7ef4290a98edca60cfbab44327384f8ad6b471da
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Tue Nov 12 22:00:23 2019 +0900

    Cygwin: pty: Use redraw screen instead of clear screen.
    
    - Previously, pty cleared screen at startup for synchronization
      between the real screen and console screen buffer for pseudo
      console. With this patch, instead of clearing screen, the screen
      is redrawn when the first native program is executed after pty
      is created. In other words, synchronization is deferred until
      the native app is executed. Moreover, this realizes excluding
      $TERM dependent code.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 30 ++++++++++++++++--------------
 winsup/cygwin/tty.cc          |  2 +-
 winsup/cygwin/tty.h           |  2 +-
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c716030..e02a8f4 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2669,7 +2669,7 @@ fhandler_pty_slave::fixup_after_attach (bool native_maybe, int fd_set)
 	  if (get_ttyp ()->num_pcon_attached_slaves == 0
 	      && !ALWAYS_USE_PCON)
 	    /* Assume this is the first process using this pty slave. */
-	    get_ttyp ()->need_clear_screen = true;
+	    get_ttyp ()->need_redraw_screen = true;
 
 	  get_ttyp ()->num_pcon_attached_slaves ++;
 	}
@@ -2700,6 +2700,21 @@ fhandler_pty_slave::fixup_after_attach (bool native_maybe, int fd_set)
 		  kill (get_ttyp ()->pcon_pid, 0) != 0)
 		get_ttyp ()->pcon_pid = myself->pid;
 	      get_ttyp ()->switch_to_pcon_out = true;
+
+	      if (get_ttyp ()->need_redraw_screen)
+		{
+		  /* Forcibly redraw screen based on console screen buffer. */
+		  /* The following code triggers redrawing the screen. */
+		  CONSOLE_SCREEN_BUFFER_INFO sbi;
+		  GetConsoleScreenBufferInfo (get_output_handle (), &sbi);
+		  SMALL_RECT rect = {0, 0,
+		    (SHORT) (sbi.dwSize.X -1), (SHORT) (sbi.dwSize.Y - 1)};
+		  COORD dest = {0, 0};
+		  CHAR_INFO fill = {' ', 0};
+		  ScrollConsoleScreenBuffer (get_output_handle (),
+					     &rect, NULL, dest, &fill);
+		  get_ttyp ()->need_redraw_screen = false;
+		}
 	    }
 	  init_console_handler (false);
 	}
@@ -2717,19 +2732,6 @@ fhandler_pty_slave::fixup_after_fork (HANDLE parent)
   // fork_fixup (parent, inuse, "inuse");
   // fhandler_pty_common::fixup_after_fork (parent);
   report_tty_counts (this, "inherited", "");
-
-  if (get_ttyp ()->need_clear_screen)
-    {
-      const char *term = getenv ("TERM");
-      if (term && strcmp (term, "dumb") && !strstr (term, "emacs"))
-	{
-	  /* FIXME: Clearing sequence may not be "^[[H^[[J"
-	     depending on the terminal type. */
-	  DWORD n;
-	  WriteFile (get_output_handle_cyg (), "\033[H\033[J", 6, &n, NULL);
-	}
-      get_ttyp ()->need_clear_screen = false;
-    }
 }
 
 void
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 460153c..9c66b89 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -244,7 +244,7 @@ tty::init ()
   pcon_pid = 0;
   num_pcon_attached_slaves = 0;
   term_code_page = 0;
-  need_clear_screen = false;
+  need_redraw_screen = false;
 }
 
 HANDLE
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index 927d7af..a6732ae 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -105,7 +105,7 @@ private:
   pid_t pcon_pid;
   int num_pcon_attached_slaves;
   UINT term_code_page;
-  bool need_clear_screen;
+  bool need_redraw_screen;
 
 public:
   HANDLE from_master () const { return _from_master; }


                 reply	other threads:[~2019-11-13  9:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191113091734.36684.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).