From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83211 invoked by alias); 28 Feb 2020 14:47:01 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 83170 invoked by uid 9078); 28 Feb 2020 14:47:01 -0000 Date: Fri, 28 Feb 2020 14:47:00 -0000 Message-ID: <20200228144701.83168.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Adjust the detailed behaviour of ESC sequences. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 729cb70bcf232a1da956ec3725c1f76e28b3caa5 X-Git-Newrev: 002206dc7cac5f3cc4d1282439c7a0c619a37b7f X-SW-Source: 2020-q1/txt/msg00095.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=002206dc7cac5f3cc4d1282439c7a0c619a37b7f commit 002206dc7cac5f3cc4d1282439c7a0c619a37b7f Author: Takashi Yano 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++;