static int vtp_working = 0;
static void vtp_init();
static void vtp_exit();
-static int vtp_printf(char *format, ...);
static void vtp_sgr_bulk(int arg);
static void vtp_sgr_bulks(int argc, int *argv);
+static int wt_working = 0;
+static void wt_init();
+
static guicolor_T save_console_bg_rgb;
static guicolor_T save_console_fg_rgb;
static guicolor_T store_console_bg_rgb;
# ifdef FEAT_TERMGUICOLORS
# define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256)))
+# define USE_WT (wt_working)
# else
# define USE_VTP 0
+# define USE_WT 0
# endif
static void set_console_color_rgb(void);
static BOOL win8_or_later = FALSE;
+# if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__)
+# define UChar UnicodeChar
+# else
+# define UChar uChar.UnicodeChar
+# endif
+
#if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
// Dynamic loading for portability
typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX
}
#if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
+ static BOOL
+is_ambiwidth_event(
+ INPUT_RECORD *ir)
+{
+ return ir->EventType == KEY_EVENT
+ && ir->Event.KeyEvent.bKeyDown
+ && ir->Event.KeyEvent.wRepeatCount == 1
+ && ir->Event.KeyEvent.wVirtualKeyCode == 0x12
+ && ir->Event.KeyEvent.wVirtualScanCode == 0x38
+ && ir->Event.KeyEvent.UChar == 0
+ && ir->Event.KeyEvent.dwControlKeyState == 2;
+}
+
+ static void
+make_ambiwidth_event(
+ INPUT_RECORD *down,
+ INPUT_RECORD *up)
+{
+ down->Event.KeyEvent.wVirtualKeyCode = 0;
+ down->Event.KeyEvent.wVirtualScanCode = 0;
+ down->Event.KeyEvent.UChar = up->Event.KeyEvent.UChar;
+ down->Event.KeyEvent.dwControlKeyState = 0;
+}
+
/*
* Version of ReadConsoleInput() that works with IME.
* Works around problems on Windows 8.
if (s_dwMax == 0)
{
- if (nLength == -1)
+ if (!USE_WT && nLength == -1)
return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
- if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents))
- return FALSE;
+ GetNumberOfConsoleInputEvents(hInput, &dwEvents);
+ if (dwEvents == 0 && nLength == -1)
+ return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
+ ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents);
s_dwIndex = 0;
s_dwMax = dwEvents;
if (dwEvents == 0)
return TRUE;
}
+ for (i = s_dwIndex; i < (int)s_dwMax - 1; ++i)
+ if (is_ambiwidth_event(&s_irCache[i]))
+ make_ambiwidth_event(&s_irCache[i], &s_irCache[i + 1]);
+
if (s_dwMax > 1)
{
head = 0;
};
-# if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__)
-# define UChar UnicodeChar
-# else
-# define UChar uChar.UnicodeChar
-# endif
-
/*
* The return code indicates key code size.
*/
vtp_flag_init();
vtp_init();
+ wt_init();
}
/*
clear_chars(coord, source.Right - source.Left + 1);
}
}
+
+ if (USE_WT)
+ {
+ COORD coord;
+ int i;
+
+ coord.X = source.Left;
+ for (i = source.Top; i < dest.Y; ++i)
+ {
+ coord.Y = i;
+ clear_chars(coord, source.Right - source.Left + 1);
+ }
+ }
}
clear_chars(coord, source.Right - source.Left + 1);
}
}
+
+ if (USE_WT)
+ {
+ COORD coord;
+ int i;
+
+ coord.X = source.Left;
+ for (i = nb; i <= source.Bottom; ++i)
+ {
+ coord.Y = i;
+ clear_chars(coord, source.Right - source.Left + 1);
+ }
+ }
}
restore_console_color_rgb();
}
- static int
+ int
vtp_printf(
char *format,
...)
}
}
+ static void
+wt_init(void)
+{
+ wt_working = (mch_getenv("WT_SESSION") != NULL);
+}
+
+ int
+use_wt(void)
+{
+ return USE_WT;
+}
+
# ifdef FEAT_TERMGUICOLORS
static int
ctermtoxterm(
get_default_console_color(&ctermfg, &ctermbg, &fg, &bg);
+ if (USE_WT)
+ {
+ term_fg_rgb_color(fg);
+ term_bg_rgb_color(bg);
+ return;
+ }
+
fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
# ifdef FEAT_TERMGUICOLORS
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
+ if (USE_WT)
+ return;
+
csbi.cbSize = sizeof(csbi);
if (has_csbiex)
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);