-#ifdef WIN32
- // XXX Dunno how to do this in win32
- (void)b;
-#else
- int flags = fcntl(*handle, F_GETFL);
- flags = (flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
- fcntl(*handle, F_SETFL, flags);
-#endif
-}
-
-void Console::set_local_echo(bool e)
-{
- check_access(M_READ);
-
-#ifdef WIN32
- DWORD m;
- GetConsoleMode(*handle, &m);
- SetConsoleMode(*handle, (m&~ENABLE_ECHO_INPUT) | (e?ENABLE_ECHO_INPUT:0));
-#else
- termios t;
- tcgetattr(*handle, &t);
- t.c_lflag = (t.c_lflag&~ECHO) | (e?ECHO:0);
- tcsetattr(*handle, TCSADRAIN, &t);
-#endif
-}
-
-void Console::set_line_buffer(bool l)
-{
- check_access(M_READ);
-
-#ifdef WIN32
- DWORD m;
- if(!GetConsoleMode(*handle, &m))
- throw system_error("GetConsoleMode");
- if(!SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)))
- throw system_error("SetConsoleMode");
-#else
- 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
-}
-
-void Console::get_size(unsigned &rows, unsigned &cols)
-{
- check_access(M_WRITE);
-
-#ifdef WIN32
- CONSOLE_SCREEN_BUFFER_INFO sbi;
- if(!GetConsoleScreenBufferInfo(*handle, &sbi))
- throw system_error("GetConsoleScreenBufferInfo");
- // Right/bottom coords are inclusive
- rows = sbi.srWindow.Bottom+1-sbi.srWindow.Top;
- cols = sbi.srWindow.Right+1-sbi.srWindow.Left;
-#else
- struct winsize wsz;
- if(ioctl(*handle, TIOCGWINSZ, &wsz)==-1)
- throw system_error("ioctl TIOCGWINSZ");
- rows = wsz.ws_row;
- cols = wsz.ws_col;
-#endif