#include <errno.h>
#include <fcntl.h>
#include <termios.h>
+#include <sys/ioctl.h>
#endif
#include <msp/core/except.h>
#include "console.h"
#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)
*/
void set_line_buffer(bool);
+ /**
+ Retrieves the size of the Console. Can only be used on an output Console.
+ */
+ void get_size(unsigned &rows, unsigned &cols);
+
virtual Handle get_event_handle();
protected:
virtual unsigned do_write(const char *, unsigned);