export default class Input {
    constructor(commandHandler, outputHandler) {
        this.handler = commandHandler;
        this.output = outputHandler;
        this.echoInput = true;
        this.inputField = document.getElementById("input-area");
        this.init();
    }

    setEcho(value) {
        this.echoInput = value;
    }

    init() {
        this.inputField.addEventListener("keydown", (e) => {
            if (e.which == 13) {
                const val = this.inputField.value;
                this.inputField.value = "";
                if (this.echoInput) this.output.say(`> ${val}`);
                this.handler.doCommand(val);
            }
        })
    }
}