X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fconsole.cpp;h=f606a09fcceb64406500dac6c00d9b532b108244;hp=eb7ac4b588bf4b6724ad8b28f02142ab010531ca;hb=41ea778b16825c3c701c6600a76eaf628831f028;hpb=33a5613489bbb9d4eab5c8761af88f4c1352aad4 diff --git a/source/console.cpp b/source/console.cpp index eb7ac4b..f606a09 100644 --- a/source/console.cpp +++ b/source/console.cpp @@ -9,6 +9,7 @@ Distributed under the LGPL #include #include #include +#include #endif #include #include "console.h" @@ -44,6 +45,9 @@ Console::Console(unsigned n) if(handle==0) tcgetattr(handle, &orig_attr); #endif + + if(n==0) + set_events(P_INPUT); } Console::~Console() @@ -101,6 +105,23 @@ void Console::set_line_buffer(bool l) #endif } +void Console::get_size(unsigned &rows, unsigned &cols) +{ + if(!(mode&M_WRITE)) + throw InvalidState("Size can only be queried from an output console"); + +#ifdef WIN32 + // XXX Figure out how to do this + rows=24; + cols=80; +#else + struct winsize wsz; + ioctl(handle, TIOCGWINSZ, &wsz); + rows=wsz.ws_row; + cols=wsz.ws_col; +#endif +} + Handle Console::get_event_handle() { return 0; @@ -116,7 +137,7 @@ unsigned Console::do_write(const char *buf, unsigned len) if(!WriteFile(handle, buf, len, &ret, 0)) throw SystemError("Writing to console failed", GetLastError()); #else - int ret=::write(1, buf, len); + int ret=::write(handle, buf, len); if(ret==-1) throw SystemError("Writing to console failed", errno); #endif @@ -134,7 +155,7 @@ unsigned Console::do_read(char *buf, unsigned len) if(!ReadFile(handle, buf, len, &ret, 0)) throw SystemError("Reading from console failed", GetLastError()); #else - int ret=::read(0, buf, len); + int ret=::read(handle, buf, len); if(ret==-1) { if(errno==EAGAIN)