If stdout is redirected on Windows, the dimensions of the terminal won't be correctly retrieved. Open the console instead, using the special filename CONOUT$, and ask the dimensions of this handle. Keep a fallback to stdout if the console can't be opened, because you can never be too cautious with this OS.
If stdout is redirected on Windows, the dimensions of the terminal won't be correctly retrieved. Open the console instead, using the special filename
CONOUT$
, and ask the dimensions of this handle. Keep a fallback to stdout if the console can't be opened, because you can never be too cautious with this OS.(this is akin to opening
/dev/tty
on Unix).https://learn.microsoft.com/en-us/windows/console/console-handles