public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: console: Discard some unsupported escape sequences.
@ 2020-05-31  8:39 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-05-31  8:39 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 4527541ec66af8d82bb9dba5d25afdf489d71271
Author: Takashi Yano via Cygwin-patches <cygwin-patches@cygwin.com>
Date:   Sun May 31 14:53:18 2020 +0900

    Cygwin: console: Discard some unsupported escape sequences.
    
    - If the cygwin vim is started from a non-cygwin process which is
      executed in pseudo console, shift key and ctrl key do not work.
      In this case, vim is executed under /dev/cons*. If vim outputs
      escape sequence which is not supported by pseudo console, the
      escape sequence is leaked into the parent pty. This causes
      unexpected results. This patch fixes the issue by discarding
      "CSI > Pm m". "OSC 10;? BEL/ST" and "OSC 11;? BEL/ST" are
      discarded as well.

Diff:
---
 winsup/cygwin/fhandler_console.cc | 54 +++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 5cb4343ea..dd979fb8e 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -2186,6 +2186,14 @@ fhandler_console::char_command (char c)
 	  /* Just send the sequence */
 	  wpbuf.send (get_output_handle ());
 	  break;
+	case 'm':
+	  if (con.saw_greater_than_sign)
+	    break; /* Ignore unsupported CSI > Pm m */
+	  /* Text attribute settings */
+	  wpbuf.put (c);
+	  /* Just send the sequence */
+	  wpbuf.send (get_output_handle ());
+	  break;
 	default:
 	  /* Other escape sequences */
 	  wpbuf.put (c);
@@ -3077,6 +3085,13 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
+	  else if (*src == ']')		/* OSC Operating System Command */
+	    {
+	      wpbuf.put (*src);
+	      con.rarg = 0;
+	      con.my_title_buf[0] = '\0';
+	      con.state = gotrsquare;
+	    }
 	  else if (wincap.has_con_24bit_colors () && !con_is_legacy)
 	    {
 	      if (*src == 'c') /* RIS Full reset */
@@ -3095,13 +3110,6 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
-	  else if (*src == ']')		/* OSC Operating System Command */
-	    {
-	      wpbuf.put (*src);
-	      con.rarg = 0;
-	      con.my_title_buf[0] = '\0';
-	      con.state = gotrsquare;
-	    }
 	  else if (*src == '(')		/* Designate G0 character set */
 	    {
 	      wpbuf.put (*src);
@@ -3179,7 +3187,8 @@ fhandler_console::write (const void *vsrc, size_t len)
 	    con.rarg = con.rarg * 10 + (*src - '0');
 	  else if (*src == ';' && (con.rarg == 2 || con.rarg == 0))
 	    con.state = gettitle;
-	  else if (*src == ';' && (con.rarg == 4 || con.rarg == 104))
+	  else if (*src == ';' && (con.rarg == 4 || con.rarg == 104
+				   || (con.rarg >= 10 && con.rarg <= 19)))
 	    con.state = eatpalette;
 	  else
 	    con.state = eattitle;
@@ -3189,10 +3198,13 @@ fhandler_console::write (const void *vsrc, size_t len)
 	case eattitle:
 	case gettitle:
 	  {
+	    wpbuf.put (*src);
 	    int n = strlen (con.my_title_buf);
 	    if (*src < ' ')
 	      {
-		if (*src == '\007' && con.state == gettitle)
+		if (wincap.has_con_24bit_colors () && !con_is_legacy)
+		  wpbuf.send (get_output_handle ());
+		else if (*src == '\007' && con.state == gettitle)
 		  set_console_title (con.my_title_buf);
 		con.state = normal;
 		wpbuf.empty();
@@ -3201,27 +3213,37 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      {
 		con.my_title_buf[n++] = *src;
 		con.my_title_buf[n] = '\0';
-		wpbuf.put (*src);
 	      }
 	    src++;
 	    break;
 	  }
 	case eatpalette:
-	  if (*src == '\033')
-	    {
-	      wpbuf.put (*src);
-	      con.state = endpalette;
-	    }
+	  wpbuf.put (*src);
+	  if (*src == '?')
+	    con.saw_question_mark = true;
+	  else if (*src == '\033')
+	    con.state = endpalette;
 	  else if (*src == '\a')
 	    {
+	      /* Send OSC Ps; Pt BEL other than OSC Ps; ? BEL */
+	      if (wincap.has_con_24bit_colors () && !con_is_legacy
+		  && !con.saw_question_mark)
+		wpbuf.send (get_output_handle ());
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
 	  src++;
 	  break;
 	case endpalette:
+	  wpbuf.put (*src);
 	  if (*src == '\\')
-	    con.state = normal;
+	    {
+	      /* Send OSC Ps; Pt ST other than OSC Ps; ? ST */
+	      if (wincap.has_con_24bit_colors () && !con_is_legacy
+		  && !con.saw_question_mark)
+		wpbuf.send (get_output_handle ());
+	      con.state = normal;
+	    }
 	  else
 	    /* Sequence error (abort) */
 	    con.state = normal;


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

only message in thread, other threads:[~2020-05-31  8:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-31  8:39 [newlib-cygwin] Cygwin: console: Discard some unsupported escape 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).