-document.addEventListener('keydown', (event) => {
- if (tui.mode.has_input_prompt && event.key.length === 1) {
- tui.add_to_input(event.key);
- } else if (tui.mode.has_input_prompt && event.key == 'Backspace') {
- tui.shorten_input();
- } else if (tui.mode == mode_login && event.key == 'Enter') {
- server.send(['LOGIN', tui.input]);
+tui.inputEl.addEventListener('input', (event) => {
+ if (tui.mode.has_input_prompt) {
+ let max_length = tui.window_width * terminal.rows - tui.input_prompt.length;
+ if (tui.inputEl.value.length > max_length) {
+ tui.inputEl.value = tui.inputEl.value.slice(0, max_length);
+ };
+ tui.recalc_input_lines();
+ tui.full_refresh();
+ } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
+ server.send(["TASK:WRITE", tui.inputEl.value[0]]);
+ tui.switch_mode(mode_play);
+ }
+}, false);
+tui.inputEl.addEventListener('keydown', (event) => {
+ if (event.key == 'Enter') {
+ event.preventDefault();
+ }
+ if (tui.mode == mode_login && event.key == 'Enter') {
+ server.send(['LOGIN', tui.inputEl.value]);