public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: console: Adjust the detailed behaviour of ESC sequences.
@ 2020-02-28 14:47 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-02-28 14:47 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 002206dc7cac5f3cc4d1282439c7a0c619a37b7f
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Feb 27 11:33:50 2020 +0900

    Cygwin: console: Adjust the detailed behaviour of ESC sequences.
    
    - This patch makes some detailed behaviour of ESC sequences such as
      "CSI Ps L" (IL), "CSI Ps M" (DL) and "ESC M" (RI) in xterm mode
      match with real xterm.

Diff:
---
 winsup/cygwin/fhandler.h          |  1 +
 winsup/cygwin/fhandler_console.cc | 51 +++++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 90805ab..adaf192 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1862,6 +1862,7 @@ class dev_console
   bool saw_question_mark;
   bool saw_greater_than_sign;
   bool saw_space;
+  bool saw_exclamation_mark;
   bool vt100_graphics_mode_G0;
   bool vt100_graphics_mode_G1;
   bool iso_2022_G1;
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 4ab9bca..64e12b8 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -2053,6 +2053,19 @@ fhandler_console::char_command (char c)
 	    {
 	      /* Use "CSI Ps T" instead */
 	      cursor_get (&x, &y);
+	      if (y < srTop || y > srBottom)
+		break;
+	      if (y == con.b.srWindow.Top
+		  && srBottom == con.b.srWindow.Bottom)
+		{
+		  /* Erase scroll down area */
+		  n = con.args[0] ? : 1;
+		  __small_sprintf (buf, "\033[%d;1H\033[J\033[%d;%dH",
+				   srBottom - (n-1) - con.b.srWindow.Top + 1,
+				   y + 1 - con.b.srWindow.Top, x + 1);
+		  WriteConsoleA (get_output_handle (),
+				 buf, strlen (buf), &wn, 0);
+		}
 	      __small_sprintf (buf, "\033[%d;%dr",
 			       y + 1 - con.b.srWindow.Top,
 			       srBottom + 1 - con.b.srWindow.Top);
@@ -2079,6 +2092,8 @@ fhandler_console::char_command (char c)
 	    {
 	      /* Use "CSI Ps S" instead */
 	      cursor_get (&x, &y);
+	      if (y < srTop || y > srBottom)
+		break;
 	      __small_sprintf (buf, "\033[%d;%dr",
 			       y + 1 - con.b.srWindow.Top,
 			       srBottom + 1 - con.b.srWindow.Top);
@@ -2137,6 +2152,16 @@ fhandler_console::char_command (char c)
 		fix_tab_position ();
 	    }
 	  break;
+	case 'p':
+	  if (con.saw_exclamation_mark) /* DECSTR Soft reset */
+	    {
+	      con.scroll_region.Top = 0;
+	      con.scroll_region.Bottom = -1;
+	    }
+	  wpbuf_put (c);
+	  /* Just send the sequence */
+	  WriteConsoleA (get_output_handle (), wpbuf, wpixput, &wn, 0);
+	  break;
 	default:
 	  /* Other escape sequences */
 	  wpbuf_put (c);
@@ -2970,6 +2995,7 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      con.saw_question_mark = false;
 	      con.saw_greater_than_sign = false;
 	      con.saw_space = false;
+	      con.saw_exclamation_mark = false;
 	    }
 	  else if (wincap.has_con_24bit_colors () && !con_is_legacy
 		   && wincap.has_con_broken_il_dl () && *src == 'M')
@@ -2979,13 +3005,17 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      cursor_get (&x, &y);
 	      if (y == srTop)
 		{
-		  /* Erase scroll down area */
-		  char buf[] = "\033[32768;1H\033[J\033[32768;32768";
-		  __small_sprintf (buf, "\033[%d;1H\033[J\033[%d;%dH",
-			     srBottom - con.b.srWindow.Top + 1,
-			     y + 1 - con.b.srWindow.Top, x + 1);
-		  WriteConsoleA (get_output_handle (),
-				 buf, strlen (buf), &n, 0);
+		  if (y == con.b.srWindow.Top
+		      && srBottom == con.b.srWindow.Bottom)
+		    {
+		      /* Erase scroll down area */
+		      char buf[] = "\033[32768;1H\033[J\033[32768;32768";
+		      __small_sprintf (buf, "\033[%d;1H\033[J\033[%d;%dH",
+				       srBottom - con.b.srWindow.Top + 1,
+				       y + 1 - con.b.srWindow.Top, x + 1);
+		      WriteConsoleA (get_output_handle (),
+				     buf, strlen (buf), &n, 0);
+		    }
 		  /* Substitute "CSI Ps T" */
 		  wpbuf_put ('[');
 		  wpbuf_put ('T');
@@ -2998,6 +3028,11 @@ fhandler_console::write (const void *vsrc, size_t len)
 	    }
 	  else if (wincap.has_con_24bit_colors () && !con_is_legacy)
 	    { /* Only CSI is handled in xterm compatible mode. */
+	      if (*src == 'c') /* RIS Full reset */
+		{
+		  con.scroll_region.Top = 0;
+		  con.scroll_region.Bottom = -1;
+		}
 	      wpbuf_put (*src);
 	      /* Just send the sequence */
 	      DWORD n;
@@ -3169,6 +3204,8 @@ fhandler_console::write (const void *vsrc, size_t len)
 		con.saw_question_mark = true;
 	      else if (*src == '>')
 		con.saw_greater_than_sign = true;
+	      else if (*src == '!')
+		con.saw_exclamation_mark = true;
 	      wpbuf_put (*src);
 	      /* ignore any extra chars between [ and first arg or command */
 	      src++;


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

only message in thread, other threads:[~2020-02-28 14:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-28 14:47 [newlib-cygwin] Cygwin: console: Adjust the detailed behaviour of ESC sequences Corinna Vinschen

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