#include "procVisLog.h"

#define PROC_COLOR 0x7
procVisLog::procVisLog(RTKMailbox *mb, Log *log) {
	this->mb = mb;
	this->log = log;
}

void procVisLog::run() {
	WWindow *win = WNewWindow(42, 2, 74, 19, 500, PROC_COLOR, " LOG: ");
	WPutC( win, 0x0C );
	while (true) {		
		RTKGet( *mb , &data );
		switch (data) {
			case 'v':
				{
					WPutC( win, 0x0C );
					int antal = this->log->ldAntal();
					if (antal <= 0) break;
					LogData *ld = new LogData[antal];
					this->log->laes(ld);
					for (int i=0; i < antal; i++) {
						char *t = new char[ ld[i].hStrLaengde() ];
						ld[i].haendelse(t);						
						Wprintf(win,t);
						Wprintf(win,"\n");
					}
					delete [] ld;
				}
				break;

			case 'n':
				{
					WPutC( win, 0x0C );
					Wprintf( win, "Nulstillet\n");					
					this->log->nulstil();
				}
				break;
			default:
				{
					Wprintf( win, "Forkert kommando\n");
				}
		}
	}
}