#include <errno.h>
#include <fcntl.h>
#include <termios.h>
+#include <sys/ioctl.h>
#endif
#include <msp/core/except.h>
#include "console.h"
if(handle==0)
tcgetattr(handle, &orig_attr);
#endif
+
+ if(n==0)
+ set_events(P_INPUT);
}
Console::~Console()
#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;
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
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)