1

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...
        }
    }
Albert
  • 65,406
  • 61
  • 242
  • 386

1 Answers1

0

Does system( "stty -raw" ); work?

chacham15
  • 13,719
  • 26
  • 104
  • 207
  • If you have a new question, please ask it by clicking the [Ask Question](http://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. – Extra Savoir-Faire Apr 19 '14 at 21:35
  • @trudyscousin its not a new question, its a proposal for a solution to his question. – chacham15 Apr 20 '14 at 19:48