Console modes: cursor style

Thomas Wolff towo@towo.net
Fri Jan 11 08:33:00 GMT 2013


The attached patch adds two escape control sequences to the Cygwin Console:

  * Show/Hide Cursor (DECTCEM)
  * Set cursor style (DECSCUSR): block vs. underline cursor, or
    arbitrary size (as an extension, using values > 4)

Thomas

-------------- next part --------------
2013-01-13  Thomas Wolff  <towo@towo.net>

	* fhandler.h (class dev_console): Flag for expanded control sequence.
	* fhandler_console.cc (char_command): Supporting cursor style modes.

-------------- next part --------------
diff -rup sav/fhandler.h ./fhandler.h
--- sav/fhandler.h	2012-10-13 14:34:17.000000000 +0200
+++ ./fhandler.h	2013-01-08 16:02:54.601269200 +0100
@@ -1246,6 +1246,7 @@ class dev_console
   unsigned rarg;
   bool saw_question_mark;
   bool saw_greater_than_sign;
+  bool saw_space;
   bool vt100_graphics_mode_G0;
   bool vt100_graphics_mode_G1;
   bool iso_2022_G1;
diff -rup sav/fhandler_console.cc ./fhandler_console.cc
--- sav/fhandler_console.cc	2012-08-17 17:57:30.000000000 +0200
+++ ./fhandler_console.cc	2013-01-08 16:50:05.467534000 +0100
@@ -1510,6 +1510,31 @@ fhandler_console::char_command (char c)
 	   }
        dev_state.set_color (get_output_handle ());
       break;
+    case 'q': /* Set cursor style (DECSCUSR) */
+      if (dev_state.saw_space)
+	{
+	    CONSOLE_CURSOR_INFO console_cursor_info;
+	    GetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+	    switch (dev_state.args_[0])
+	      {
+		case 0: /* blinking block */
+		case 1: /* blinking block (default) */
+		case 2: /* steady block */
+		  console_cursor_info.dwSize = 100;
+		  SetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+		  break;
+		case 3: /* blinking underline */
+		case 4: /* steady underline */
+		  console_cursor_info.dwSize = 10;	/* or Windows default 25? */
+		  SetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+		  break;
+		default: /* use value as percentage */
+		  console_cursor_info.dwSize = dev_state.args_[0];
+		  SetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+		  break;
+	      }
+	}
+      break;
     case 'h':
     case 'l':
       if (!dev_state.saw_question_mark)
@@ -1525,6 +1550,17 @@ fhandler_console::char_command (char c)
 	}
       switch (dev_state.args_[0])
 	{
+	case 25: /* Show/Hide Cursor (DECTCEM) */
+	  {
+	    CONSOLE_CURSOR_INFO console_cursor_info;
+	    GetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+	    if (c == 'h')
+	      console_cursor_info.bVisible = TRUE;
+	    else
+	      console_cursor_info.bVisible = FALSE;
+	    SetConsoleCursorInfo (get_output_handle (), & console_cursor_info);
+	    break;
+	  }
 	case 47:   /* Save/Restore screen */
 	  if (c == 'h') /* save */
 	    {
@@ -1752,7 +1788,7 @@ fhandler_console::char_command (char c)
 	  __small_sprintf (buf, "\033[%d;%dR", y + 1, x + 1);
 	  puts_readahead (buf);
 	  break;
-    default:
+      default:
 	  goto bad_escape;
 	}
       break;
@@ -2026,6 +2062,7 @@ fhandler_console::write (const void *vsr
 	      dev_state.state_ = gotsquare;
 	      dev_state.saw_question_mark = false;
 	      dev_state.saw_greater_than_sign = false;
+	      dev_state.saw_space = false;
 	      for (dev_state.nargs_ = 0; dev_state.nargs_ < MAXARGS; dev_state.nargs_++)
 		dev_state.args_[dev_state.nargs_] = 0;
 	      dev_state.nargs_ = 0;
@@ -2092,6 +2129,12 @@ fhandler_console::write (const void *vsr
 	      if (dev_state.nargs_ >= MAXARGS)
 		dev_state.nargs_--;
 	    }
+	  else if (*src == ' ')
+	    {
+	      src++;
+	      dev_state.saw_space = true;
+	      dev_state.state_ = gotcommand;
+	    }
 	  else
 	    {
 	      dev_state.state_ = gotcommand;


More information about the Cygwin-patches mailing list