public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: pty: Fix screen alternation while pseudo console switching.
@ 2019-09-14 15:25 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-09-14 15:25 UTC (permalink / raw)
  To: cygwin-cvs

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

commit bd31b7c5d54e26d3fb02946f1a88e97fa7379e3e
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Sun Sep 8 22:23:23 2019 +0900

    Cygwin: pty: Fix screen alternation while pseudo console switching.
    
    - If screen alternated while pseudo console switching, it sometimes
      failed. This might happen when the output of the non-cygwin program
      is piped to less. This patch fixes this issue.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index a8821c7..b4591c1 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -73,6 +73,7 @@ struct pipe_reply {
 
 static int pcon_attached_to = -1;
 static bool isHybrid;
+static bool do_not_reset_switch_to_pcon;
 
 #if USE_API_HOOK
 static void
@@ -1046,6 +1047,8 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
       init_console_handler (true);
       return;
     }
+  if (do_not_reset_switch_to_pcon)
+    return;
   if (get_ttyp ()->switch_to_pcon)
     {
       DWORD mode;
@@ -1108,6 +1111,8 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len)
 	    {
 	      //p0 += 8;
 	      get_ttyp ()->screen_alternated = true;
+	      if (get_ttyp ()->switch_to_pcon)
+		do_not_reset_switch_to_pcon = true;
 	    }
 	}
       if (get_ttyp ()->screen_alternated)
@@ -1118,6 +1123,7 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len)
 	    {
 	      p1 += 8;
 	      get_ttyp ()->screen_alternated = false;
+	      do_not_reset_switch_to_pcon = false;
 	      memmove (p0, p1, buf+nlen - p1);
 	      nlen -= p1 - p0;
 	    }
@@ -1177,7 +1183,8 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len)
       p += wLen;
     }
   /* Detach from pseudo console and resume. */
-  SetConsoleMode (get_output_handle (), dwMode);
+  flags = ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+  SetConsoleMode (get_output_handle (), dwMode | flags);
 cleanup:
   SetConsoleOutputCP (origCP);
   HeapFree (GetProcessHeap (), 0, buf);
@@ -1267,7 +1274,7 @@ fhandler_pty_slave::write (const void *ptr, size_t len)
   HeapFree (GetProcessHeap (), 0, buf);
   flags = ENABLE_VIRTUAL_TERMINAL_PROCESSING;
   if (get_ttyp ()->switch_to_pcon && !fallback)
-    SetConsoleMode (get_output_handle (), dwMode);
+    SetConsoleMode (get_output_handle (), dwMode | flags);
 
   restore_reattach_pcon ();
 
@@ -2899,12 +2906,11 @@ fhandler_pty_slave::fixup_after_attach (bool native_maybe)
     {
       FlushConsoleInputBuffer (get_handle ());
       DWORD mode;
-      GetConsoleMode (get_handle (), &mode);
-      SetConsoleMode (get_handle (),
-		      (mode & ~ENABLE_VIRTUAL_TERMINAL_INPUT) |
-		      ENABLE_ECHO_INPUT |
-		      ENABLE_LINE_INPUT |
-		      ENABLE_PROCESSED_INPUT);
+      mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
+      SetConsoleMode (get_output_handle (), mode);
+      FlushConsoleInputBuffer (get_handle ());
+      mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
+      SetConsoleMode (get_handle (), mode);
       Sleep (20);
       if (get_ttyp ()->pcon_pid == 0 ||
 	  kill (get_ttyp ()->pcon_pid, 0) != 0)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-14 15:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-14 15:25 [newlib-cygwin] Cygwin: pty: Fix screen alternation while pseudo console switching Ken Brown

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).