Simplify getting buffer info

This commit is contained in:
Jason Hood 2019-04-29 20:11:00 +10:00
parent d7a2d5e962
commit 0dd40f6d74

32
ANSI.c
View File

@ -539,26 +539,14 @@ void get_state( void )
csbix.cbSize = sizeof(csbix); csbix.cbSize = sizeof(csbix);
if (GetConsoleScreenBufferInfoX( hConOut, &csbix )) if (GetConsoleScreenBufferInfoX( hConOut, &csbix ))
{ {
Info.dwSize = csbix.dwSize;
ATTR = csbix.wAttributes;
WIN = csbix.srWindow;
arrcpy( pState->o_palette, csbix.ColorTable ); arrcpy( pState->o_palette, csbix.ColorTable );
ATTR = csbix.wAttributes;
} }
else else
{ {
arrcpy( pState->o_palette, legacy_palette ); arrcpy( pState->o_palette, legacy_palette );
if (!GetConsoleScreenBufferInfo( hConOut, &Info )) if (!GetConsoleScreenBufferInfo( hConOut, &Info ))
{
DEBUGSTR( 1, "Failed to get screen buffer info (%u) - assuming defaults",
GetLastError() );
ATTR = 7; ATTR = 7;
WIDTH = 80;
HEIGHT = 300;
WIN.Left = 0;
WIN.Right = 79;
TOP = 0;
BOTTOM = 24;
}
} }
arrcpy( pState->x_palette, xterm_palette ); arrcpy( pState->x_palette, xterm_palette );
@ -578,7 +566,10 @@ void get_state( void )
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL ); NULL, OPEN_EXISTING, 0, NULL );
if (!GetConsoleScreenBufferInfo( hConOut, &Info )) if (!GetConsoleScreenBufferInfo( hConOut, &Info ))
{
RtlZeroMemory( &Info, sizeof(Info) );
ATTR = 7; ATTR = 7;
}
if (pState->sgr.reverse) if (pState->sgr.reverse)
{ {
*a++ = '-'; *a++ = '-';
@ -3877,20 +3868,9 @@ void set_ansicon( PCONSOLE_SCREEN_BUFFER_INFO pcsbi )
hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL ); NULL, OPEN_EXISTING, 0, NULL );
if (hConOut == INVALID_HANDLE_VALUE) if (!GetConsoleScreenBufferInfo( hConOut, &csbi ))
{ RtlZeroMemory( &csbi, sizeof(csbi) );
csbi.dwSize.X =
csbi.dwSize.Y =
csbi.srWindow.Left =
csbi.srWindow.Top =
csbi.srWindow.Right =
csbi.srWindow.Bottom = 0;
}
else
{
GetConsoleScreenBufferInfo( hConOut, &csbi );
CloseHandle( hConOut ); CloseHandle( hConOut );
}
pcsbi = &csbi; pcsbi = &csbi;
} }