#include "terminal_tile.h"

#include "piscreendrawer.h"


TileTerminal::TileTerminal(const PIString & n): PIScreenTile(n) {
	focus_flags = PIScreenTypes::CanHasFocus;
	size_policy = PIScreenTypes::Expanding;
	lastp[0] = lastp[1] = lastp[2] = 0;
}


void TileTerminal::drawEvent(PIScreenDrawer * d) {
	// piCout << "draw" << visible;
	d->fillRect(x_, y_, x_ + width_, y_ + height_, cells);
}


bool TileTerminal::keyEvent(PIKbdListener::KeyEvent key) {
	lastp[0] = lastp[1];
	lastp[1] = lastp[2];
	lastp[2] = char(key.key);
	if (lastp[0] == '\e' && lastp[1] == '~' && lastp[2] == '.') {
		closeRequest();
		return true;
	}
	// piCout << "key";
	keyPressed(key);
	return true;
}


void TileTerminal::resizeEvent(int w, int h) {
	resizeRequest();
}
