From 0d7bbc0bc3da7d7c9e0a76243cbeaf458724d32d Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Thu, 27 Feb 2020 00:33:01 +0900 Subject: [PATCH] Cygwin: console: Add support for REP escape sequence to xterm mode. - In Win10 upto 1809, xterm compatible mode does not have REP escape sequence which terminfo declares. This patch adds support for "CSI Ps b" (REP). With this patch, bvi (binary editor) works normally in Win10 1809. Also, xterm compatible mode does not have "CSI Pm `" (HPA), "CSI Pm a" (HPR) and "CSI Ps e" (VPR). However, they do not appear to be declared by terminfo. Therefore, these have been pending. --- winsup/cygwin/fhandler_console.cc | 33 +++++++++++++++++++++++++++++++ winsup/cygwin/wincap.cc | 10 ++++++++++ winsup/cygwin/wincap.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index fbeccffad..f87d93269 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -62,6 +62,7 @@ static struct fhandler_base::rabuf_t con_ra; #define WPBUF_LEN 256 static unsigned char wpbuf[WPBUF_LEN]; static int wpixput; +static unsigned char last_char; #define wpbuf_put(x) \ wpbuf[wpixput++] = x; \ if (wpixput > WPBUF_LEN) \ @@ -2009,6 +2010,37 @@ fhandler_console::char_command (char c) DWORD wn; switch (c) { +#if 0 /* These sequences, which are supported by real xterm, are + not supported by xterm compatible mode. Therefore they + were implemented once. However, these are not declared + in terminfo of xterm-256color, therefore, do not appear + to be necessary. */ + case '`': /* HPA */ + if (con.args[0] == 0) + con.args[0] = 1; + cursor_get (&x, &y); + cursor_set (false, con.args[0]-1, y); + break; + case 'a': /* HPR */ + if (con.args[0] == 0) + con.args[0] = 1; + cursor_rel (con.args[0], 0); + break; + case 'e': /* VPR */ + if (con.args[0] == 0) + con.args[0] = 1; + cursor_rel (0, con.args[0]); + break; +#endif + case 'b': /* REP */ + wpbuf_put (c); + if (wincap.has_con_esc_rep ()) + /* Just send the sequence */ + WriteConsoleA (get_output_handle (), wpbuf, wpixput, &wn, 0); + else if (last_char && last_char != '\n') + for (int i = 0; i < con.args[0]; i++) + WriteConsoleA (get_output_handle (), &last_char, 1, &wn, 0); + break; case 'r': /* DECSTBM */ con.scroll_region.Top = con.args[0] ? con.args[0] - 1 : 0; con.scroll_region.Bottom = con.args[1] ? con.args[1] - 1 : -1; @@ -2746,6 +2778,7 @@ fhandler_console::write_normal (const unsigned char *src, break; default: found += ret; + last_char = *(found - 1); break; } } diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 714a6d49f..922705e65 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -44,6 +44,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_24bit_colors:false, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -73,6 +74,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_24bit_colors:false, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -102,6 +104,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_24bit_colors:false, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -131,6 +134,7 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = { has_con_24bit_colors:false, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -160,6 +164,7 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared)) has_con_24bit_colors:false, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -189,6 +194,7 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_24bit_colors:true, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -218,6 +224,7 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_24bit_colors:true, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -247,6 +254,7 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_24bit_colors:true, has_con_broken_csi3j:false, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -276,6 +284,7 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_24bit_colors:true, has_con_broken_csi3j:true, has_con_broken_il_dl:false, + has_con_esc_rep:false, }, }; @@ -305,6 +314,7 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) = has_con_24bit_colors:true, has_con_broken_csi3j:false, has_con_broken_il_dl:true, + has_con_esc_rep:true, }, }; diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index f85a88877..6d7a1eae6 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -38,6 +38,7 @@ struct wincaps unsigned has_con_24bit_colors : 1; unsigned has_con_broken_csi3j : 1; unsigned has_con_broken_il_dl : 1; + unsigned has_con_esc_rep : 1; }; }; @@ -99,6 +100,7 @@ public: bool IMPLEMENT (has_con_24bit_colors) bool IMPLEMENT (has_con_broken_csi3j) bool IMPLEMENT (has_con_broken_il_dl) + bool IMPLEMENT (has_con_esc_rep) void disable_case_sensitive_dirs () { -- 2.43.5