Hi vim_dev,
I always liked the feature in win32 console vim where the cursor
changed shape depending on what mode you're in. I recently switched to
using cygwin console vim on my Windows systems instead of win32
console for various reasons (primarily because it understands cygwin
paths), and was disappointed to find the cursor shape-change feature
was not working, even though my version of cygwin vim was compiled
with +cursorshape. I had some time on my hands, so I went into the
source and figured out how to get it to work. Here's the patch:
diff -r a96cb758a8d7 runtime/doc/options.txt
--- a/runtime/doc/options.txt Fri Dec 23 14:56:28 2011 +0100
+++ b/runtime/doc/options.txt Mon Dec 26 00:11:47 2011 -0500
@@ -3334,17 +3334,17 @@
r-cr:hor20-Cursor/lCursor,
sm:block-Cursor
-blinkwait175-blinkoff150-blinkon175",
- for MS-DOS and Win32 console:
+ for MS-DOS, Win32, and Cygwin console:
"n-v-c:block,o:hor50,i-ci:hor15,
r-cr:hor30,sm:block")
global
{not in Vi}
{only available when compiled with GUI enabled, and
- for MS-DOS and Win32 console}
+ for MS-DOS, Win32, and Cygwin console}
This option tells Vim what the cursor should look like in different
- modes. It fully works in the GUI. In an MSDOS or Win32 console,
only
- the height of the cursor can be changed. This can be done by
- specifying a block cursor, or a percentage for a vertical or
+ modes. It fully works in the GUI. In an MSDOS, Win32, and Cygwin
+ console, only the height of the cursor can be changed. This can be
+ done by specifying a block cursor, or a percentage for a vertical or
horizontal cursor.
For a console the 't_SI' and 't_EI' escape sequences are used.
diff -r a96cb758a8d7 src/feature.h
--- a/src/feature.h Fri Dec 23 14:56:28 2011 +0100
+++ b/src/feature.h Mon Dec 26 00:11:47 2011 -0500
@@ -1156,8 +1156,8 @@
* mouse shape Adjust the shape of the mouse pointer to the mode.
*/
#ifdef FEAT_NORMAL
-/* MS-DOS console and Win32 console can change cursor shape */
-# if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
+/* MS-DOS console, Win32 console, and Cygwin console can change
cursor shape */
+# if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
|| defined(__CYGWIN__)
# define MCH_CURSOR_SHAPE
# endif
# if defined(FEAT_GUI_W32) || defined(FEAT_GUI_W16) ||
defined(FEAT_GUI_MOTIF) \
diff -r a96cb758a8d7 src/os_unix.c
--- a/src/os_unix.c Fri Dec 23 14:56:28 2011 +0100
+++ b/src/os_unix.c Mon Dec 26 00:11:47 2011 -0500
@@ -31,6 +31,11 @@
#include "vim.h"
+#if defined(__CYGWIN__)
+#include <windows.h>
+static HANDLE g_hConOut = INVALID_HANDLE_VALUE;
+#endif
+
#ifdef FEAT_MZSCHEME
# include "if_mzsch.h"
#endif
@@ -1222,6 +1227,10 @@
#ifdef MACOS_CONVERT
mac_conv_init();
#endif
+
+#if defined(__CYGWIN__)
+ g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
+#endif
}
static void
@@ -7196,3 +7205,41 @@
#endif
+
+#if defined(__CYGWIN__)
+
+#if defined(MCH_CURSOR_SHAPE)
+/*
+ * Set the shape of the cursor.
+ * 'thickness' can be from 1 (thin) to 99 (block)
+ */
+ static void
+mch_set_cursor_shape(int thickness)
+{
+ CONSOLE_CURSOR_INFO ConsoleCursorInfo;
+ ConsoleCursorInfo.dwSize = thickness;
+ ConsoleCursorInfo.bVisible = TRUE;
+
+ SetConsoleCursorInfo(g_hConOut, &ConsoleCursorInfo);
+}
+
+ void
+mch_update_cursor(void)
+{
+ int idx;
+ int thickness;
+
+ /*
+ * How the cursor is drawn depends on the current mode.
+ */
+ idx = get_shape_idx(FALSE);
+
+ if (shape_table[idx].shape == SHAPE_BLOCK)
+ thickness = 99; /* 100 doesn't work on W95 */
+ else
+ thickness = shape_table[idx].percentage;
+ mch_set_cursor_shape(thickness);
+}
+#endif
+
+#endif
Some possible concerns:
1. I know that cygwin vim can run in different terminals, such as rxvt
and the new cygwin terminal. The patch obviously only works when run
in a DOS box because it calls the Windows API function
SetConsoleCursorInfo, which only applies to the DOS box. I'm not sure
how to test what type of console we're running in... should we include
such a test to avoid calling that code unnecessarily?
2. I believe cygwin vim can be compiled for GUI mode, so the code
wouldn't work in that case either; should we include a preprocessor
test to exclude the code if compiling for GUI mode?
3. I'm not sure about how much testing needs to be done for a new
patch (this is the first patch I've ever submitted); I've only tested
it on one Windows 7 machine.
Any feedback is appreciated.
Thanks,
Ben
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php