X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fconsole.cpp;h=a03ad20747bf251c40c57f682e027f760756cb7e;hp=c846604806aa66e36ea8ce76d37199b7420b4372;hb=3f7aa81d9212811b323d89949adcccda212cbed3;hpb=651cfe05e867ffdef9028a831add3eca54d19d0d diff --git a/source/io/console.cpp b/source/io/console.cpp index c846604..a03ad20 100644 --- a/source/io/console.cpp +++ b/source/io/console.cpp @@ -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 - // 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); + // 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 @@ -114,9 +124,12 @@ void Console::get_size(unsigned &rows, unsigned &cols) check_access(M_WRITE); #ifdef WIN32 - // XXX Figure out how to do this - rows = 24; - cols = 80; + 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)