delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/07/27/14:45:44

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=Vfjr5LRzQWmUc3pxt0qI+L3mHlmHmlvCxrBAsb21wEPaR7hKhJbZo
LyTuSEtF2rpF0TnINVvFx+Ov0eYQ8z6sFN6Z/ZDyZKSLlg4u4LcpU4EVvTx64vaV
x2MBfS7HfttmVYRushLwMOmjesolg8RpVeMH2t7Ir6eZnIBVRSv0H4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=iRGN/xltf6JAzj2W5sqQboxj4zs=; b=dCMx+kGCp9thh4m22WGVnIPpyEm4
eTG4I/yBLgwgSN3NUpCenjnANWZFkl7WLd8Hinbtcfge73K0HwvmZvgyaVNkCCkV
VI88DEBELzK6+ADFY8LSk+uyCKP+aflgtermSQlUUbutTgVJa31IVUrWHHGQqbYE
cmNSeABrNzCGqpw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-94.9 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_BRBL_LASTEXT,RCVD_IN_PBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=ham version=3.3.2 spammy=H*f:sk:50bb6b3, H*i:sk:50bb6b3, upward
X-HELO: calimero.vinschen.de
Date: Wed, 27 Jul 2016 20:45:11 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Cc: Kaz Kylheku <kaz AT kylheku DOT com>
Subject: Re: [PATCH] Strange behavior of cmd.exe when hammered with clear screen operations from Cygwin program.
Message-ID: <20160727184511.GA29214@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com, Kaz Kylheku <kaz AT kylheku DOT com>
References: <05e87c9326e8bc9a32a5a3cd2511fe98 AT mail DOT kylheku DOT com> <9b05b6502dc0bdba2654069cfa924a50 AT mail DOT kylheku DOT com> <6d026b0ea424481879a89d480730c1f4 AT mail DOT kylheku DOT com> <49c8dca543daed3fa35b29e41ebf449b AT mail DOT kylheku DOT com> <50bb6b3942d5fb67057465f8b09b7121 AT mail DOT kylheku DOT com>
MIME-Version: 1.0
In-Reply-To: <50bb6b3942d5fb67057465f8b09b7121@mail.kylheku.com>
User-Agent: Mutt/1.6.2 (2016-07-01)

--5p8PegU4iirBW1oA
Content-Type: multipart/mixed; boundary="ZmUaFz6apKcXQszQ"
Content-Disposition: inline


--ZmUaFz6apKcXQszQ
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Kaz,

On Jul 27 08:40, Kaz Kylheku wrote:
> On 27.07.2016 07:35, Kaz Kylheku wrote:
> > On 27.07.2016 07:31, Kaz Kylheku wrote:
> > > The patch below seems to solves it for me:
> >=20
> > Oops, no it doesn't. Stay tuned. :)
>=20
> This is a bit more like it:
>=20
> From: Kaz Kylheku <kaz AT kylheku DOT com>
> Date: Wed, 27 Jul 2016 07:49:54 -0700
> Subject: Replace bogus resize-window-to-clear-screen logic.
>=20
> This removes (ab)uses of SetConsoleScreenBufferSize
> which sometimes cause cmd.exe to badly misbehave.
> It probably doesn't like the closely spaced timing of
> shrinking the window down to one line followed by a restore
> of the size. Instead we just output newlines to clear
> the window.

The problem is obvious when observing your test application (thanks a
lot for that), but I'm not convinced that just calling WriteConsole with
a single LF in a loop is the way to go.  The Windows console API has
more nifty ways to fix this problem.

Here's another suggestion.  I attached a patch which utilizes
ScrollConsoleScreenBuffer to save the buffer content when the console
window is at the end of the console buffer.  So we either move the
console window down the buffer if there's enough buffer left, or we move
the buffer up under the window if we're operating at the end of the
buffer.

Please give it a try and report back.  Especially if I screwed up :}

Btw, since you're apparently building your own Cygwin DLL I thought just
sending the patch for testing is sufficient.  If you prefer to get a
developer snapshot with this patch, I can do that, too.  Just say the word.


Thanks,
Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--ZmUaFz6apKcXQszQ
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="0001-Fix-buffer-scrolling-when-performing-a-clear-screen.patch"
Content-Transfer-Encoding: quoted-printable

=46rom f9dd1288180b5d88b2915337aa58462811de3168 Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna AT vinschen DOT de>
Date: Wed, 27 Jul 2016 20:39:24 +0200
Subject: [PATCH] Fix buffer scrolling when performing a "clear screen"

Signed-off-by: Corinna Vinschen <corinna AT vinschen DOT de>
---
 winsup/cygwin/fhandler_console.cc | 54 +++++++++++++++++++++++++----------=
----
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_con=
sole.cc
index d4c077b..9c490c5 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -1216,30 +1216,46 @@ dev_console::scroll_window (HANDLE h, int x1, int y=
1, int x2, int y2)
     return false;
=20
   SMALL_RECT sr;
-  int toscroll =3D 2 + dwEnd.Y - b.srWindow.Top;
-  int shrink =3D 1 + toscroll + b.srWindow.Bottom - b.dwSize.Y;
+  int toscroll =3D dwEnd.Y - b.srWindow.Top + 1;
   sr.Left =3D sr.Right =3D dwEnd.X =3D 0;
-  /* Can't increment dwEnd yet since we may not have space in
-     the buffer.  */
-  SetConsoleCursorPosition (h, dwEnd);
-  if (shrink > 0)
+
+  if (b.srWindow.Bottom + toscroll >=3D b.dwSize.Y)
     {
-      COORD c =3D b.dwSize;
-      c.Y =3D dwEnd.Y - shrink;
-      SetConsoleScreenBufferSize (h, c);
-      SetConsoleScreenBufferSize (h, b.dwSize);
-      dwEnd.Y =3D 0;
-      fillin (h);
-      toscroll =3D 2 + dwEnd.Y - b.srWindow.Top;
+      /* So we're at the end of the buffer and scrolling the console window
+	 would move us beyond the buffer.  What we do here is to scroll the
+	 console buffer upward by just as much so that the current last line
+	 becomes the last line just prior to the first window line.  That
+	 keeps the end of the console buffer intact, as desired.
+
+	 Since we're moving the console buffer under the console window in
+	 this case, we must not move the console window. */
+      SMALL_RECT br;
+      COORD dest;
+      CHAR_INFO fill;
+
+      br.Left =3D 0;
+      br.Top =3D dwEnd.Y - b.srWindow.Top + 1;
+      br.Right =3D b.dwSize.X - 1;
+      br.Bottom =3D b.dwSize.Y - 1;
+      dest.X =3D dest.Y =3D 0;
+      fill.Char.AsciiChar =3D ' ';
+      fill.Attributes =3D current_win32_attr;
+      ScrollConsoleScreenBuffer (h, &br, NULL, dest, &fill);
+      /* Fix dwEnd to reflect the new cursor line (minus 1 to take the
+	 increment a few lines later into account) */
+      dwEnd.Y =3D b.dwCursorPosition.Y - 1;
     }
-
-  sr.Top =3D sr.Bottom =3D toscroll;
-
-  SetConsoleWindowInfo (h, FALSE, &sr);
-
+  else
+    {
+      /* The reminder of the console buffer is big enough to simply move
+         the console window. */
+      sr.Top =3D sr.Bottom =3D toscroll;
+      SetConsoleWindowInfo (h, FALSE, &sr);
+    }
+  /* Eventually set cursor to new end position at the top of the window. */
   dwEnd.Y++;
   SetConsoleCursorPosition (h, dwEnd);
-
+  /* Fix up console buffer info. */
   fillin (h);
   return true;
 }
--=20
2.5.5


--ZmUaFz6apKcXQszQ--

--5p8PegU4iirBW1oA
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJXmQE2AAoJEPU2Bp2uRE+gePAQAIWdIKcfGakmDYfkqJ9OtMnv
x/QLhOVkqZe8eCQD9TBBw3mEKW5RF6gE5GBPkSHY9pf2Va5fmdtuaOtP5iMuAFY6
dhmDcV8xp2CAp+A3MKX4i2SwuVqYyGJ7Gg2bk4uDLoTy4KiqGunfXlg/at9La+b6
ORCreO5+5c5xREnnqJ0wvZhxpguE2m1R/cB20X5cVSypLtFwFf5fXoyPoJdzGo03
sAUqQv4YrHD4WMEV5PDOWLfp4JpS9EkeIxjZnfcQG9c8L39c1S83mr79Rdtk6m4E
6GXDQfb4eGLzos4vwEnKUDk8ZpxBsvI1gMqEUPwoiSGnMbOfCbSin1Ts5CbOUdKT
jixevlaocDoAkARtvIS15xTRmTVNlQwBYeGBh5dQ9bjlyB9rJoCny+R0L7UGxhOa
w+IB8GPB3YNQG8ZoeRdaedS0mdshtQSAIbwsD5l6kcgNhtHA3eeGTQuRv445PC/0
YEJEidnms9x42v2IjlK/SY8vPdmNljqBop5R67lavDtIR+Y3jRrNHKRLq8rHs4h8
cswY9UmYHhbpdz+YiaNZT5r2lc8mV9WgJ3OV1gCIL/nC5o3CUtPjxbaZ7EmYmLbx
I9L/aAUF39dBZa+Hb9MVVjCgdenUDKSk44PtT6BrYFj1iD7nThjKYYq9sFGeJXFa
DAsppkdx4TvqOkA7+/w2
=PP/J
-----END PGP SIGNATURE-----

--5p8PegU4iirBW1oA--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019