[PATCH 0/1] Workaround for horizontal tab on console (again)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/1] Workaround for horizontal tab on console (again)

Takashi Yano
The workaround commit 33a21904a702191cebf0e81b4deba2dfa10a406c does not
work as expected if the window size is changed while screen is alternated.
This patch fixes the issue.

Takashi Yano (1):
  Cygwin: console: Fix workaround for horizontal tab position

 winsup/cygwin/fhandler_console.cc | 47 +++++++++++++++++++------------
 1 file changed, 29 insertions(+), 18 deletions(-)

--
2.21.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 1/1] Cygwin: console: Fix workaround for horizontal tab position

Takashi Yano
- The workaround commit 33a21904a702191cebf0e81b4deba2dfa10a406c
  does not work as expected if window size is changed while screen
  is alternated. Fixed.
---
 winsup/cygwin/fhandler_console.cc | 47 +++++++++++++++++++------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 4afb7efb7..67638055e 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -319,6 +319,25 @@ fhandler_console::set_cursor_maybe ()
     }
 }
 
+/* Workaround for a bug of windows xterm compatible mode. */
+/* The horizontal tab positions are broken after resize. */
+static void
+fix_tab_position (HANDLE h, SHORT width)
+{
+  char buf[2048] = {0,};
+  /* Save cursor position */
+  __small_sprintf (buf+strlen (buf), "\0337");
+  /* Clear all horizontal tabs */
+  __small_sprintf (buf+strlen (buf), "\033[3g");
+  /* Set horizontal tabs */
+  for (int col=8; col<width; col+=8)
+    __small_sprintf (buf+strlen (buf), "\033[%d;%dH\033H", 1, col+1);
+  /* Restore cursor position */
+  __small_sprintf (buf+strlen (buf), "\0338");
+  DWORD dwLen;
+  WriteConsole (h, buf, strlen (buf), &dwLen, 0);
+}
+
 bool
 fhandler_console::send_winch_maybe ()
 {
@@ -331,24 +350,7 @@ fhandler_console::send_winch_maybe ()
       con.scroll_region.Top = 0;
       con.scroll_region.Bottom = -1;
       if (wincap.has_con_24bit_colors ())
- {
-  /* Workaround for a bug of windows xterm compatible mode. */
-  /* The horizontal tab positions are broken after resize. */
-  DWORD dwLen;
-  CONSOLE_SCREEN_BUFFER_INFO sbi;
-  GetConsoleScreenBufferInfo (get_output_handle (), &sbi);
-  /* Clear all horizontal tabs */
-  WriteConsole (get_output_handle (), "\033[3g", 4, &dwLen, 0);
-  /* Set horizontal tabs */
-  for (int col=8; col<con.dwWinSize.X; col+=8)
-    {
-      char buf[32];
-      __small_sprintf (buf, "\033[%d;%dH\033H", 1, col+1);
-      WriteConsole (get_output_handle (), buf, strlen (buf), &dwLen, 0);
-    }
-  /* Restore cursor position */
-  SetConsoleCursorPosition (get_output_handle (), sbi.dwCursorPosition);
- }
+ fix_tab_position (get_output_handle (), con.dwWinSize.X);
       get_ttyp ()->kill_pgrp (SIGWINCH);
       return true;
     }
@@ -1615,6 +1617,12 @@ static const wchar_t __vt100_conv[31] = {
 inline
 bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
 {
+  bool need_fix_tab_position = false;
+  /* Check if screen will be alternated. */
+  if (wincap.has_con_24bit_colors ()
+      && memmem (buf, len*sizeof (WCHAR), L"\033[?1049", 7*sizeof (WCHAR)))
+    need_fix_tab_position = true;
+
   if (con.iso_2022_G1
  ? con.vt100_graphics_mode_G1
  : con.vt100_graphics_mode_G0)
@@ -1633,6 +1641,9 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
       len -= done;
       buf += done;
     }
+  /* Call fix_tab_position() if screen has been alternated. */
+  if (need_fix_tab_position)
+    fix_tab_position (get_output_handle (), con.dwWinSize.X);
   return true;
 }
 
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/1] Cygwin: console: Fix workaround for horizontal tab position

Corinna Vinschen-2
On Aug 15 14:02, Takashi Yano wrote:
> - The workaround commit 33a21904a702191cebf0e81b4deba2dfa10a406c
>   does not work as expected if window size is changed while screen
>   is alternated. Fixed.
> ---
>  winsup/cygwin/fhandler_console.cc | 47 +++++++++++++++++++------------
>  1 file changed, 29 insertions(+), 18 deletions(-)

Pushed.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment