mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.0.0905: MS-Windows: broken multi-byte characters in the console
Problem: MS-Windows: broken multi-byte characters in the console. Solution: Restore all regions of the console buffer. (Ken Takata)
This commit is contained in:
@@ -2192,6 +2192,8 @@ typedef struct ConsoleBufferStruct
|
|||||||
CONSOLE_SCREEN_BUFFER_INFO Info;
|
CONSOLE_SCREEN_BUFFER_INFO Info;
|
||||||
PCHAR_INFO Buffer;
|
PCHAR_INFO Buffer;
|
||||||
COORD BufferSize;
|
COORD BufferSize;
|
||||||
|
PSMALL_RECT Regions;
|
||||||
|
int NumRegions;
|
||||||
} ConsoleBuffer;
|
} ConsoleBuffer;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2212,6 +2214,7 @@ SaveConsoleBuffer(
|
|||||||
COORD BufferCoord;
|
COORD BufferCoord;
|
||||||
SMALL_RECT ReadRegion;
|
SMALL_RECT ReadRegion;
|
||||||
WORD Y, Y_incr;
|
WORD Y, Y_incr;
|
||||||
|
int i, numregions;
|
||||||
|
|
||||||
if (cb == NULL)
|
if (cb == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -2254,7 +2257,22 @@ SaveConsoleBuffer(
|
|||||||
ReadRegion.Left = 0;
|
ReadRegion.Left = 0;
|
||||||
ReadRegion.Right = cb->Info.dwSize.X - 1;
|
ReadRegion.Right = cb->Info.dwSize.X - 1;
|
||||||
Y_incr = 12000 / cb->Info.dwSize.X;
|
Y_incr = 12000 / cb->Info.dwSize.X;
|
||||||
for (Y = 0; Y < cb->BufferSize.Y; Y += Y_incr)
|
|
||||||
|
numregions = (cb->Info.dwSize.Y + Y_incr - 1) / Y_incr;
|
||||||
|
if (cb->Regions == NULL || numregions != cb->NumRegions)
|
||||||
|
{
|
||||||
|
cb->NumRegions = numregions;
|
||||||
|
vim_free(cb->Regions);
|
||||||
|
cb->Regions = (PSMALL_RECT)alloc(cb->NumRegions * sizeof(SMALL_RECT));
|
||||||
|
if (cb->Regions == NULL)
|
||||||
|
{
|
||||||
|
vim_free(cb->Buffer);
|
||||||
|
cb->Buffer = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0, Y = 0; i < cb->NumRegions; i++, Y += Y_incr)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Read into position (0, Y) in our buffer.
|
* Read into position (0, Y) in our buffer.
|
||||||
@@ -2268,7 +2286,7 @@ SaveConsoleBuffer(
|
|||||||
*/
|
*/
|
||||||
ReadRegion.Top = Y;
|
ReadRegion.Top = Y;
|
||||||
ReadRegion.Bottom = Y + Y_incr - 1;
|
ReadRegion.Bottom = Y + Y_incr - 1;
|
||||||
if (!ReadConsoleOutput(g_hConOut, /* output handle */
|
if (!ReadConsoleOutputW(g_hConOut, /* output handle */
|
||||||
cb->Buffer, /* our buffer */
|
cb->Buffer, /* our buffer */
|
||||||
cb->BufferSize, /* dimensions of our buffer */
|
cb->BufferSize, /* dimensions of our buffer */
|
||||||
BufferCoord, /* offset in our buffer */
|
BufferCoord, /* offset in our buffer */
|
||||||
@@ -2276,8 +2294,11 @@ SaveConsoleBuffer(
|
|||||||
{
|
{
|
||||||
vim_free(cb->Buffer);
|
vim_free(cb->Buffer);
|
||||||
cb->Buffer = NULL;
|
cb->Buffer = NULL;
|
||||||
|
vim_free(cb->Regions);
|
||||||
|
cb->Regions = NULL;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
cb->Regions[i] = ReadRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -2299,6 +2320,7 @@ RestoreConsoleBuffer(
|
|||||||
{
|
{
|
||||||
COORD BufferCoord;
|
COORD BufferCoord;
|
||||||
SMALL_RECT WriteRegion;
|
SMALL_RECT WriteRegion;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (cb == NULL || !cb->IsValid)
|
if (cb == NULL || !cb->IsValid)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -2335,19 +2357,19 @@ RestoreConsoleBuffer(
|
|||||||
*/
|
*/
|
||||||
if (cb->Buffer != NULL)
|
if (cb->Buffer != NULL)
|
||||||
{
|
{
|
||||||
BufferCoord.X = 0;
|
for (i = 0; i < cb->NumRegions; i++)
|
||||||
BufferCoord.Y = 0;
|
|
||||||
WriteRegion.Left = 0;
|
|
||||||
WriteRegion.Top = 0;
|
|
||||||
WriteRegion.Right = cb->Info.dwSize.X - 1;
|
|
||||||
WriteRegion.Bottom = cb->Info.dwSize.Y - 1;
|
|
||||||
if (!WriteConsoleOutput(g_hConOut, /* output handle */
|
|
||||||
cb->Buffer, /* our buffer */
|
|
||||||
cb->BufferSize, /* dimensions of our buffer */
|
|
||||||
BufferCoord, /* offset in our buffer */
|
|
||||||
&WriteRegion)) /* region to restore */
|
|
||||||
{
|
{
|
||||||
return FALSE;
|
BufferCoord.X = cb->Regions[i].Left;
|
||||||
|
BufferCoord.Y = cb->Regions[i].Top;
|
||||||
|
WriteRegion = cb->Regions[i];
|
||||||
|
if (!WriteConsoleOutputW(g_hConOut, /* output handle */
|
||||||
|
cb->Buffer, /* our buffer */
|
||||||
|
cb->BufferSize, /* dimensions of our buffer */
|
||||||
|
BufferCoord, /* offset in our buffer */
|
||||||
|
&WriteRegion)) /* region to restore */
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
905,
|
||||||
/**/
|
/**/
|
||||||
904,
|
904,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user