Improve isatty() Windows implementation with Cygwin/Mingw pseudo terminals
hboutemy opened this issue · 2 comments
hboutemy commented
as seen in Jansi issue fusesource/jansi#94, Cygwin and Mingw use pseudo terminals, not real terminals
Then isatty() does not detect the pseudo-terminal
Git has a workaround: git/git@8692483
/* get pipe name */
if (!NT_SUCCESS(NtQueryObject(h, ObjectNameInformation,
buffer, sizeof(buffer) - 2, &result)))
return;
name = nameinfo->Name.Buffer;
name[nameinfo->Name.Length] = 0;
/*
* Check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX')
* or a cygwin pty pipe ('cygwin-XXXX-ptyN-XX')
*/
if ((!wcsstr(name, L"msys-") && !wcsstr(name, L"cygwin-")) ||
!wcsstr(name, L"-pty"))
return;
This code should be added to Jansi native isatty() implementation for Windows to properly detect (pseudo)terminal with Cygwin and Mingw
gnodet commented
The code builds, but it does not seem to give the expected results.
When I execute the CLibrary.isatty(0)
or CLibrary.isatty(1)
under cygwin, both returns 0.
hboutemy commented
did you try to get the value of the terminal name?
this is really the current code in git: https://github.com/git/git/blob/master/compat/winansi.c#L537