#ifndef TERMINALH #define TERMINALH #include #include "fatal.h" extern "C" { #include "term.h" } using namespace std; class terminal { const char _background; const unsigned _xmax; const unsigned _ymax; public: class unprintable: public fatal { const unsigned x, y; const char c; void print(ostream& ost) const throw() { ost << "unprintable character " << static_cast(static_cast(c)) << " at location (" << x << ", " << y << ")\n"; } public: unprintable(unsigned initial_x, unsigned initial_y, char initial_c) throw(): c(initial_c), x(initial_x), y(initial_y) {} }; class out_of_range: public fatal { unsigned x, y; unsigned xmax, ymax; void print(ostream& ost) const throw() { ost << "coordinates (" << x << ", " << y << ") are off screen (" << xmax << ", " << ymax << ")\n"; } public: out_of_range(unsigned initial_x, unsigned initial_y, unsigned initial_xmax, unsigned initial_ymax) throw(): x(initial_x), y(initial_y), xmax(initial_xmax), ymax(initial_ymax) {} }; terminal(char initial_background = ' ') throw (unprintable, out_of_range); ~terminal() throw (unprintable, out_of_range); char background() const {return _background;} unsigned xmax() const {return _xmax;} unsigned ymax() const {return _ymax;} char get(unsigned x, unsigned y) const throw (out_of_range) {return term_get(x, y);} void put(unsigned x, unsigned y, char c) const throw (unprintable, out_of_range); void put(unsigned x, unsigned y) const throw (unprintable, out_of_range) {put(x, y, background());} void put(unsigned x, unsigned y, const char *s) const throw (unprintable, out_of_range); static char key() {return term_key();} static void wait(int milliseconds) {term_wait(milliseconds);} static void beep() {term_beep();} bool in_range(unsigned x, unsigned y) const {return x < _xmax && y < _ymax;} void next(unsigned& x, unsigned& y) const throw (out_of_range); }; #endif