I want to get my stdin into raw input mode in Cygwin/Mintty. How do I do that? Right now, it is line-buffered. With raw input mode, I mean that read
returns on every single entered character.
I would prefer to do that without any further dependencies. I.e. I guess this probably can be done by linking against some libs from Cygwin, however, if it is possible, I'd like to avoid that.
Some search results: libuv issue, libuv win/tty.c, Cygwin tty.cc, Cygwin fhandler_tty.cc, Cygwin post (non-blocking stdin), Mintty issue, Msysgit issue
I tried via SetConsoleMode
, but that only works for the Windows console, not for Mintty. I.e. this code:
// Setting terminal to raw mode...
HANDLE hStdin;
DWORD mode;
//hStdin = GetStdHandle(STD_INPUT_HANDLE);
hStdin = (HANDLE) _get_osfhandle(STDIN_FILENO);
if (GetFileType(hStdin) == FILE_TYPE_CHAR) {
cout << "stdin is file type char" << endl;
GetConsoleMode(hStdin, &mode);
if (
!SetConsoleMode(
hStdin,
mode & ~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT))
) {
cerr << "Cannot set stdin to raw mode" << endl;
// ignore...
}
}