@Override
	public void run() {
		dungeon.startup();
		char read = '\0';
		try {
			while (dungeon.isActive()) {
				if (read == '\n' || read == '\r') {
					command = inputBuffer.toString();
					dungeon.takeAction(command);
					inputBuffer = new StringBuffer();
				} else if (read == '\u007f') {
					printOutputStream.print("\b ");
					if (inputBuffer.length() >= 1) {
						inputBuffer.deleteCharAt(inputBuffer.length() - 1);
					}
				} else if (read == '\u0003') {
					dungeon.exitRequest();
				} else {
					inputBuffer.append(read);
				}
				printOutputStream.print("\r" + inputBuffer.toString());
				if (dungeon.hasUpdate()) {
					printOutputStream.print(dungeon.output());
				}
				printOutputStream.flush();
				if (!dungeon.isActive()) {
					return;
				}
				read = (char) inputStream.read();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			exitCallback.onExit(0);
		}

	}