]> git.tdb.fi Git - libs/core.git/commitdiff
Handle c_cc when toggling canonical mode
authorMikko Rasa <tdb@tdb.fi>
Tue, 10 Jul 2012 09:08:00 +0000 (12:08 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 26 Jul 2012 19:30:18 +0000 (22:30 +0300)
source/io/console.cpp

index c846604806aa66e36ea8ce76d37199b7420b4372..6ae969914b732319ed78609a30d294e3b670c609 100644 (file)
@@ -99,11 +99,21 @@ void Console::set_line_buffer(bool l)
        if(!SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)))
                throw system_error("SetConsoleMode");
 #else
        if(!SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)))
                throw system_error("SetConsoleMode");
 #else
-       // XXX ICANON does more than just set line buffering, may need a bit more thought
        termios t;
        if(tcgetattr(*handle, &t)==-1)
                throw system_error("tcgetattr");
        t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0);
        termios t;
        if(tcgetattr(*handle, &t)==-1)
                throw system_error("tcgetattr");
        t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0);
+       // man termios warns that VMIN and VTIME may share indices with VEOF and VEOL
+       if(l)
+       {
+               t.c_cc[VEOF] = orig_attr.c_cc[VEOF];
+               t.c_cc[VEOL] = orig_attr.c_cc[VEOL];
+       }
+       else
+       {
+               t.c_cc[VMIN] = 1;
+               t.c_cc[VTIME] = 0;
+       }
        if(tcsetattr(*handle, TCSADRAIN, &t)==-1)
                throw system_error("tcsetattr");
 #endif
        if(tcsetattr(*handle, TCSADRAIN, &t)==-1)
                throw system_error("tcsetattr");
 #endif