Cygwin / Mintty中stdin上的原始输入模式

时间:2014-03-25 12:34:58

标签: cygwin stdin mintty

我想让我的stdin进入Cygwin / Mintty的原始输入模式。我怎么做?现在,它是行缓冲的。对于原始输入模式,我的意思是read会返回每个输入的字符。

我更愿意在没有任何进一步依赖的情况下这样做。即我想这可能是通过链接来自Cygwin的一些lib来完成的,但是,如果可能的话,我想避免这种情况。

部分搜索结果:libuv issuelibuv win/tty.cCygwin tty.ccCygwin fhandler_tty.ccCygwin post (non-blocking stdin)Mintty issueMsysgit issue

我尝试通过SetConsoleMode,但这只适用于Windows控制台,而不适用于Mintty。即这段代码:

    // 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...
        }
    }

1 个答案:

答案 0 :(得分:0)

system( "stty -raw" );是否有效?