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: Disable ResizePseudoConsole() if stdout is redirected.
Date: Tue, 27 Oct 2020 09:27:23 +0000 (GMT)	[thread overview]
Message-ID: <20201027092723.B55E43858D37@sourceware.org> (raw)

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

commit 490d4862df73ffba39ba7d82c4b65c539d5e33f6
Author: Takashi Yano via Cygwin-patches <cygwin-patches@cygwin.com>
Date:   Tue Oct 27 17:26:34 2020 +0900

    Cygwin: pty: Disable ResizePseudoConsole() if stdout is redirected.
    
    - Calling ResizePseudoConsole() generates some escape sequences.
      Due to this behaviour, if the output of non-cygwin app is piped
      to less, screen is sometimes distorted when the screen is resized.
      With this patch, ResizePseudoConsole() is not called if stdout is
      redirected.

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

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c5a081ebd..600de085c 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1511,7 +1511,7 @@ fhandler_pty_common::resize_pseudo_console (struct winsize *ws)
   size.X = ws->ws_col;
   size.Y = ws->ws_row;
   pinfo p (get_ttyp ()->pcon_pid);
-  if (p)
+  if (p && !get_ttyp ()->do_not_resize_pcon)
     {
       HPCON_INTERNAL hpcon_local;
       HANDLE pcon_owner =
@@ -2489,7 +2489,10 @@ fhandler_pty_slave::setup_pseudoconsole (STARTUPINFOEXW *si, bool nopcon)
       si->StartupInfo.hStdInput = fh0->get_handle ();
     fhandler_base *fh1 = ::cygheap->fdtab[1];
     if (fh1 && fh1->get_device () != get_device ())
-      si->StartupInfo.hStdOutput = fh1->get_output_handle ();
+      {
+	get_ttyp ()->do_not_resize_pcon = true;
+	si->StartupInfo.hStdOutput = fh1->get_output_handle ();
+      }
     fhandler_base *fh2 = ::cygheap->fdtab[2];
     if (fh2 && fh2->get_device () != get_device ())
       si->StartupInfo.hStdError = fh2->get_output_handle ();
@@ -2535,6 +2538,7 @@ fhandler_pty_slave::close_pseudoconsole (void)
       get_ttyp ()->switch_to_pcon_in = false;
       get_ttyp ()->pcon_pid = 0;
       get_ttyp ()->pcon_start = false;
+      get_ttyp ()->do_not_resize_pcon = false;
     }
 }
 
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 7e3b88b0b..d4b8d7651 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -245,6 +245,7 @@ tty::init ()
   pcon_cap_checked = false;
   has_csi6n = false;
   has_set_title = false;
+  do_not_resize_pcon = false;
 }
 
 HANDLE
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index 4e9199dba..2c1ac7f5d 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -104,6 +104,7 @@ private:
   bool pcon_cap_checked;
   bool has_csi6n;
   bool has_set_title;
+  bool do_not_resize_pcon;
 
 public:
   HANDLE from_master () const { return _from_master; }


                 reply	other threads:[~2020-10-27  9:27 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=20201027092723.B55E43858D37@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).