【发布时间】:2014-03-25 12:34:57
【问题描述】:
我想让我的标准输入在 Cygwin/Mintty 中进入原始输入模式。我怎么做?现在,它是行缓冲的。对于原始输入模式,我的意思是 read 在每个输入的字符上都返回。
我宁愿在没有任何进一步依赖的情况下这样做。 IE。我想这可能可以通过链接 Cygwin 的一些库来完成,但是,如果可能的话,我想避免这种情况。
部分搜索结果:libuv issue、libuv win/tty.c、Cygwin tty.cc、Cygwin fhandler_tty.cc、Cygwin post (non-blocking stdin)、Mintty issue、Msysgit issue
我通过SetConsoleMode 尝试过,但这仅适用于 Windows 控制台,不适用于 Mintty。 IE。这段代码:
// 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...
}
}
【问题讨论】: