mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 04:04:17 +01:00
TerminalSize (Windows): make it work when stdin or stdout is redirected
This commit is contained in:
@@ -5,9 +5,19 @@
|
||||
|
||||
bool ffDetectTerminalSize(FFTerminalSizeResult* result)
|
||||
{
|
||||
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
FF_AUTO_CLOSE_FD HANDLE hConout = INVALID_HANDLE_VALUE;
|
||||
{
|
||||
DWORD outputMode;
|
||||
if (!GetConsoleMode(hOutput, &outputMode))
|
||||
{
|
||||
hConout = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, NULL);
|
||||
hOutput = hConout;
|
||||
}
|
||||
}
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
||||
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||
{
|
||||
result->columns = (uint16_t) (csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
||||
result->rows = (uint16_t) (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
||||
@@ -23,7 +33,7 @@ bool ffDetectTerminalSize(FFTerminalSizeResult* result)
|
||||
|
||||
{
|
||||
CONSOLE_FONT_INFO cfi;
|
||||
if(GetCurrentConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi)) // Only works for ConHost
|
||||
if(GetCurrentConsoleFont(hOutput, FALSE, &cfi)) // Only works for ConHost
|
||||
{
|
||||
result->width = result->columns * (uint16_t) cfi.dwFontSize.X;
|
||||
result->height = result->rows * (uint16_t) cfi.dwFontSize.Y;
|
||||
|
||||
Reference in New Issue
Block a user