Hello. Sorry for the accidental submit.
Both isatty() and GetConsoleScreenBufferInfo() fail with mintty 2.1.5 in MSYS2.
GetConsoleScreenBufferInfo() is used to get the number of rows/cols.
ioctl() is not available in MSYS2/mingw-w64.
isatty() seems to be an alias to _isatty().
Running this test:
https://gist.github.com/MoSal/af351add0efee1a8ccf7
ConEmu:
isatty(fileno(stdout)) returned 64
_isatty(fileno(stdout)) returned 64
cols=170
mintty:
isatty(fileno(stdout)) returned 0
_isatty(fileno(stdout)) returned 0
GetConsoleScreenBufferInfo() failed.
wine:
isatty(fileno(stdout)) returned 64
_isatty(fileno(stdout)) returned 64
cols=80
With mintty 2.1.5 in cygwin everything is OK:
isatty(fileno(stdout)) returned 1
_isatty(fileno(stdout)) returned 1
GetConsoleScreenBufferInfo() failed.
Note that mintty does not provide a Windows console environment. These are two different worlds, you cannot expect GetConsole... to work. To find out the terminal size, ioctl should work in an MSYS program but not necessarily in a MinGW program, note there is a distinction. Alternatively, you may query the terminal with the respective control sequences and check the response. The program stty should also work.
As for isatty, I'll check with MSYS.
CC: @Alexpux
A little update.
MSYS2's gcc uses a POSIX isatty() that correctly returns 1. And yes, ioctl() is available and seems to work.
So, the issue is with mingw-w64/Windows' isatty().
Quoting from mingw.org: “MinGW … is a minimalist development environment for native Microsoft Windows applications.”
Native Windows means no tty.
Closing.
For the benefit of others who stumble upon this page, it is possible to detect if the TTY is a MinTTY: https://fossies.org/linux/vim/src/iscygpty.c On Windows, it is useful to combine this with the standard Windows API check (e.g. via GetConsoleMode).
Cygwin 3.1.0 has been released with ConPTY support. Please recheck.
Most helpful comment
For the benefit of others who stumble upon this page, it is possible to detect if the TTY is a MinTTY: https://fossies.org/linux/vim/src/iscygpty.c On Windows, it is useful to combine this with the standard Windows API check (e.g. via
GetConsoleMode).