X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fconsole.cpp;h=259f80fbdf5ca21802099d9108c779f1bb9c0f53;hp=447377b32ebe08d057c5e1f121601ffde893dd64;hb=5b541316a8c7bbf8b812c0f1e2dbebaa6563b0ee;hpb=33bfa130254370803efc6882a29a0f0c9f2b6d28 diff --git a/source/io/console.cpp b/source/io/console.cpp index 447377b..259f80f 100644 --- a/source/io/console.cpp +++ b/source/io/console.cpp @@ -1,5 +1,6 @@ #ifndef WIN32 #include +#include #include #include #include @@ -93,14 +94,18 @@ void Console::set_line_buffer(bool l) #ifdef WIN32 DWORD m; - GetConsoleMode(*handle, &m); - SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)); + 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 // XXX ICANON does more than just set line buffering, may need a bit more thought termios t; - tcgetattr(*handle, &t); + if(tcgetattr(*handle, &t)==-1) + throw system_error("tcgetattr"); t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0); - tcsetattr(*handle, TCSADRAIN, &t); + if(tcsetattr(*handle, TCSADRAIN, &t)==-1) + throw system_error("tcsetattr"); #endif } @@ -114,12 +119,23 @@ void Console::get_size(unsigned &rows, unsigned &cols) cols = 80; #else struct winsize wsz; - ioctl(*handle, TIOCGWINSZ, &wsz); + if(ioctl(*handle, TIOCGWINSZ, &wsz)==-1) + throw system_error("ioctl TIOCGWINSZ"); rows = wsz.ws_row; cols = wsz.ws_col; #endif } +void Console::redirect(Base &other) +{ + Handle other_handle = other.get_handle(mode&M_RDWR); +#ifdef WIN32 + SetStdHandle(stream_to_sys(stream), *other_handle); +#else + dup2(*other_handle, *handle); +#endif +} + unsigned Console::do_write(const char *buf, unsigned len) { check_access(M_WRITE);