Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/5aed3a57d3995e31a377 to your computer and use it in GitHub Desktop.
Save mattn/5aed3a57d3995e31a377 to your computer and use it in GitHub Desktop.
vim.exe で終了時にワイド文字を復帰するパッチ
diff -r 3790fb70e04c src/os_win32.c
--- a/src/os_win32.c Tue Apr 21 19:10:49 2015 +0200
+++ b/src/os_win32.c Mon May 25 13:07:59 2015 +0900
@@ -584,6 +584,11 @@
SECURITY_INFORMATION, PSID *, PSID *, PACL *, PACL *,
PSECURITY_DESCRIPTOR *);
# endif
+typedef BOOL (*PRCOUTPUT)(HANDLE, PCHAR_INFO, COORD, COORD, PSMALL_RECT);
+typedef BOOL (*PWCOUTPUT)(HANDLE, CONST CHAR_INFO*, COORD, COORD, PSMALL_RECT);
+
+static PRCOUTPUT pReadConsoleOutput = ReadConsoleOutputA;
+static PWCOUTPUT pWriteConsoleOutput = WriteConsoleOutputA;
static HANDLE advapi_lib = NULL; /* Handle for ADVAPI library */
static PSNSECINFO pSetNamedSecurityInfo;
@@ -708,7 +713,7 @@
*/
if (g_PlatformId == VER_PLATFORM_WIN32_NT)
{
- HANDLE kernel32 = GetModuleHandle("kernel32");
+ HMODULE kernel32 = GetModuleHandle("kernel32");
pSetHandleInformation = (PSETHANDLEINFORMATION)GetProcAddress(
kernel32, "SetHandleInformation");
@@ -2243,7 +2248,7 @@
*/
ReadRegion.Top = Y;
ReadRegion.Bottom = Y + Y_incr - 1;
- if (!ReadConsoleOutput(g_hConOut, /* output handle */
+ if (!pReadConsoleOutput(g_hConOut, /* output handle */
cb->Buffer, /* our buffer */
cb->BufferSize, /* dimensions of our buffer */
BufferCoord, /* offset in our buffer */
@@ -2316,7 +2321,7 @@
WriteRegion.Top = 0;
WriteRegion.Right = cb->Info.dwSize.X - 1;
WriteRegion.Bottom = cb->Info.dwSize.Y - 1;
- if (!WriteConsoleOutput(g_hConOut, /* output handle */
+ if (!pWriteConsoleOutput(g_hConOut, /* output handle */
cb->Buffer, /* our buffer */
cb->BufferSize, /* dimensions of our buffer */
BufferCoord, /* offset in our buffer */
@@ -2495,6 +2500,20 @@
create_conin();
g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (g_PlatformId == VER_PLATFORM_WIN32_NT)
+ {
+ HMODULE kernel32 = GetModuleHandle("kernel32");
+ if (!(pReadConsoleOutput = (PRCOUTPUT) GetProcAddress(kernel32,
+ "ReadConsoleOutputW")))
+ pReadConsoleOutput = ReadConsoleOutputA;
+ else if (!(pWriteConsoleOutput = (PWCOUTPUT) GetProcAddress(kernel32,
+ "WriteConsoleOutputW")))
+ {
+ pReadConsoleOutput = ReadConsoleOutputA;
+ pWriteConsoleOutput = WriteConsoleOutputA;
+ }
+ }
+
#ifdef FEAT_RESTORE_ORIG_SCREEN
/* Save the initial console buffer for later restoration */
SaveConsoleBuffer(&g_cbOrig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment