#include //for isprint #include "terminal.h" using namespace std; terminal::terminal(char initial_background) throw (unprintable, out_of_range) : _background(initial_background), _xmax((term_construct(), term_xmax())), _ymax(term_ymax()) { if (_background != ' ') { for (unsigned y = 0; y < _ymax; ++y) { for (unsigned x = 0; x < _xmax; ++x) { put(x, y); } } } } terminal::~terminal() throw (unprintable, out_of_range) { for (unsigned y = 0; y < _ymax; ++y) { for (unsigned x = 0; x < _xmax; ++x) { put(x, y, ' '); } } term_destruct(); } void terminal::put(unsigned x, unsigned y, char c) const throw (unprintable, out_of_range) { if (isprint(c) == 0) { throw unprintable(x, y, c); } if (!in_range(x, y)) { throw out_of_range(x, y, _xmax, _ymax); } term_put(x, y, c); } void terminal::put(unsigned x, unsigned y, const char *s) const throw (unprintable, out_of_range) { for (; *s != '\0'; ++s) { put(x, y, *s); next(x, y); } } //Move to the next (x, y) position: left to right, top to bottom. //Warning: will change the values of the arguments. void terminal::next(unsigned& x, unsigned& y) const throw (out_of_range) { if (!in_range(x, y)) { throw out_of_range(x, y, _xmax, _ymax); } if (++x >= _xmax) { x = 0; ++y; } }