home · contact · privacy
Minor client improvements.
[plomrogue2-experiments] / new2 / rogue_chat_nocanvas_monochrome.html
1 <!DOCTYPE html>
2 <html><head>
3 <style>
4 </style>
5 </head><body>
6 <div>
7 movement: <select id="WASD_selector" name="WASD_selector" >
8 <option value="w, a, s, d" selected>w, a, s, d</option>
9 <option value="arrow keys">arrow keys</option>
10 </select>
11 rows: <input id="n_rows" type="number" step=2 min=10 value=24 />
12 cols: <input id="n_cols" type="number" step=4 min=20 value=80 />
13 command character: <select id="command_char"" >
14 <option value=":" selected>:</option>
15 <option value="/">/</option>
16 </select>
17 </div>
18 <pre id="terminal" style="display: inline-block;"></pre>
19 <textarea id="input" style="opacity: 0; width: 0px;"></textarea>
20 <script>
21 "use strict";
22 let websocket_location = "ws://localhost:8000";
23
24 let wasd_selector = document.getElementById("WASD_selector");
25 let rows_selector = document.getElementById("n_rows");
26 let cols_selector = document.getElementById("n_cols");
27 let command_char_selector = document.getElementById("command_char");
28
29 let terminal = {
30   foreground: 'white',
31   background: 'black',
32   initialize: function() {
33     this.rows = rows_selector.value;
34     this.cols = cols_selector.value;
35     this.pre_el = document.getElementById("terminal");
36     this.pre_el.style.color = this.foreground;
37     this.pre_el.style.backgroundColor = this.background;
38     this.content = [];
39       let line = []
40     for (let y = 0, x = 0; y <= this.rows; x++) {
41         if (x == this.cols) {
42             x = 0;
43             y += 1;
44             this.content.push(line);
45             line = [];
46             if (y == this.rows) {
47                 break;
48             }
49         }
50         line.push(' ');
51     }
52   },
53   blink_screen: function() {
54       this.pre_el.style.color = this.background;
55       this.pre_el.style.backgroundColor = this.foreground;
56       setTimeout(() => {
57           this.pre_el.style.color = this.foreground;
58           this.pre_el.style.backgroundColor = this.background;
59       }, 100);
60   },
61   refresh: function() {
62       let pre_string = '';
63       for (let y = 0; y < this.rows; y++) {
64           let line = this.content[y].join('');
65           pre_string += line + '\n';
66       }
67       this.pre_el.textContent = pre_string;
68   },
69   write: function(start_y, start_x, msg) {
70       for (let x = start_x, i = 0; x < this.cols && i < msg.length; x++, i++) {
71           this.content[start_y][x] = msg[i];
72       }
73   },
74   drawBox: function(start_y, start_x, height, width) {
75     let end_y = start_y + height;
76     let end_x = start_x + width;
77     for (let y = start_y, x = start_x; y < this.rows; x++) {
78       if (x == end_x) {
79         x = start_x;
80         y += 1;
81         if (y == end_y) {
82             break;
83         }
84       };
85       this.content[y][x] = ' ';
86     }
87   },
88 }
89 terminal.initialize();
90
91 let parser = {
92   tokenize: function(str) {
93     let token_ends = [];
94     let tokens = [];
95     let token = ''
96     let quoted = false;
97     let escaped = false;
98     for (let i = 0; i < str.length; i++) {
99       let c = str[i];
100       if (quoted) {
101         if (escaped) {
102           token += c;
103           escaped = false;
104         } else if (c == '\\') {
105           escaped = true;
106         } else if (c == '"') {
107           quoted = false
108         } else {
109           token += c;
110         }
111       } else if (c == '"') {
112         quoted = true
113       } else if (c === ' ') {
114         if (token.length > 0) {
115           token_ends.push(i);
116           tokens.push(token);
117           token = '';
118         }
119       } else {
120         token += c;
121       }
122     }
123     if (token.length > 0) {
124       tokens.push(token);
125     }
126     let token_starts = [];
127     for (let i = 0; i < token_ends.length; i++) {
128       token_starts.push(token_ends[i] - tokens[i].length);
129     };
130     return [tokens, token_starts];
131   },
132   parse_yx: function(position_string) {
133     let coordinate_strings = position_string.split(',')
134     let position = [0, 0];
135     position[0] = parseInt(coordinate_strings[0].slice(2));
136     position[1] = parseInt(coordinate_strings[1].slice(2));
137     return position;
138   },
139 }
140
141 class Thing {
142     constructor(yx) {
143         this.position = yx;
144     }
145 }
146
147 let server = {
148     init: function(url) {
149         this.url = url;
150         this.websocket = new WebSocket(this.url);
151         this.websocket.onopen = function(event) {
152             window.setInterval(function() { server.send(['PING']) }, 30000);
153             tui.log_msg("@ server connected! :)");
154             tui.init_login();
155         };
156         this.websocket.onclose = function(event) {
157             tui.log_msg("@ server disconnected :(");
158             tui.log_msg("@ hint: try the '" + command_char_selector.value + "reconnect' command");
159         };
160         this.websocket.onmessage = this.handle_event;
161     },
162     reconnect: function() {
163         this.reconnect_to(this.url);
164     },
165     reconnect_to: function(url) {
166         this.websocket.close();
167         this.init(url);
168     },
169     send: function(tokens) {
170         this.websocket.send(unparser.untokenize(tokens));
171     },
172     handle_event: function(event) {
173         let tokens = parser.tokenize(event.data)[0];
174         if (tokens[0] === 'TURN') {
175             game.things = {};
176             game.portals = {};
177             game.turn = parseInt(tokens[1]);
178         } else if (tokens[0] === 'THING_POS') {
179             game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
180         } else if (tokens[0] === 'THING_NAME') {
181             game.get_thing(tokens[1], true).name_ = tokens[2];
182         } else if (tokens[0] === 'MAP') {
183             game.map_size = parser.parse_yx(tokens[1]);
184             game.map = tokens[2]
185         } else if (tokens[0] === 'GAME_STATE_COMPLETE') {
186             explorer.empty_info_db();
187             if (tui.mode == mode_study) {
188                 explorer.query_info();
189             }
190             let t = game.get_thing(game.player_id);
191             if (t.position in game.portals) {
192                 tui.teleport_target = game.portals[t.position];
193                 tui.switch_mode(mode_teleport);
194                 return;
195             }
196             tui.full_refresh();
197         } else if (tokens[0] === 'CHAT') {
198              tui.log_msg('# ' + tokens[1], 1);
199         } else if (tokens[0] === 'PLAYER_ID') {
200             game.player_id = parseInt(tokens[1]);
201         } else if (tokens[0] === 'LOGIN_OK') {
202             this.send(['GET_GAMESTATE']);
203             tui.log_help();
204             // TODO wait for game state for this switch, use intermediary mode?
205             tui.switch_mode(mode_play);
206         } else if (tokens[0] === 'PORTAL') {
207             let position = parser.parse_yx(tokens[1]);
208             game.portals[position] = tokens[2];
209         } else if (tokens[0] === 'ANNOTATION') {
210             let position = parser.parse_yx(tokens[1]);
211             explorer.update_info_db(position, tokens[2]);
212         } else if (tokens[0] === 'UNHANDLED_INPUT') {
213             tui.log_msg('? unknown command');
214         } else if (tokens[0] === 'PLAY_ERROR') {
215             terminal.blink_screen();
216         } else if (tokens[0] === 'ARGUMENT_ERROR') {
217             tui.log_msg('? syntax error: ' + tokens[1]);
218         } else if (tokens[0] === 'GAME_ERROR') {
219             tui.log_msg('? game error: ' + tokens[1]);
220         } else if (tokens[0] === 'PONG') {
221             console.log('PONG');
222         } else {
223             tui.log_msg('? unhandled input: ' + event.data);
224         }
225     }
226 }
227
228 let unparser = {
229     quote: function(str) {
230         let quoted = ['"'];
231         for (let i = 0; i < str.length; i++) {
232             let c = str[i];
233             if (['"', '\\'].includes(c)) {
234                 quoted.push('\\');
235             };
236             quoted.push(c);
237         }
238         quoted.push('"');
239         return quoted.join('');
240     },
241     to_yx: function(yx_coordinate) {
242         return "Y:" + yx_coordinate[0] + ",X:" + yx_coordinate[1];
243     },
244     untokenize: function(tokens) {
245         let quoted_tokens = [];
246         for (let token of tokens) {
247             quoted_tokens.push(this.quote(token));
248         }
249         return quoted_tokens.join(" ");
250     }
251 }
252
253 class Mode {
254     constructor(name, has_input_prompt=false, shows_info=false, is_intro=false) {
255         this.name = name;
256         this.has_input_prompt = has_input_prompt;
257         this.shows_info= shows_info;
258         this.is_intro = is_intro;
259     }
260 }
261 let mode_waiting_for_server = new Mode('waiting_for_server', false, false, true);
262 let mode_login = new Mode('login', true, false, true);
263 let mode_chat = new Mode('chat / write messages to players', true, false);
264 let mode_annotate = new Mode('add message to map tile', true, true);
265 let mode_play = new Mode('play / move around', false, false);
266 let mode_study = new Mode('check map tiles for messages', false, true);
267 let mode_edit = new Mode('write ASCII char to map tile', false, false);
268 let mode_teleport = new Mode('teleport away?');
269 let mode_portal = new Mode('add portal to map tile', true, true);
270
271 let tui = {
272   mode: mode_waiting_for_server,
273   log: [],
274   input_prompt: '> ',
275   input_lines: [],
276   window_width: terminal.cols / 2,
277   height_turn_line: 1,
278   height_mode_line: 1,
279   height_input: 1,
280   init: function() {
281       this.inputEl = document.getElementById("input");
282       this.inputEl.focus();
283       this.recalc_input_lines();
284       this.height_header = this.height_turn_line + this.height_mode_line;
285       this.log_msg("@ waiting for server connection ...");
286       this.init_wasd();
287   },
288   init_wasd: function() {
289     if (wasd_selector.value == 'w, a, s, d') {
290         tui.key_up = 'w';
291         tui.key_down = 's';
292         tui.key_left = 'a';
293         tui.key_right = 'd';
294     } else if (wasd_selector.value == 'arrow keys') {
295         tui.key_up = 'ArrowUp';
296         tui.key_down = 'ArrowDown';
297         tui.key_left = 'ArrowLeft';
298         tui.key_right = 'ArrowRight';
299     };
300     tui.movement_keys_desc = wasd_selector.value;
301   },
302   init_login: function() {
303       this.log_msg("@ please enter your username:");
304       this.switch_mode(mode_login);
305   },
306   switch_mode: function(mode, keep_pos=false) {
307     if (mode == mode_study && !keep_pos) {
308       explorer.position = game.things[game.player_id].position;
309     }
310     this.mode = mode;
311     this.empty_input();
312     if (mode == mode_annotate && explorer.position in explorer.info_db) {
313         let info = explorer.info_db[explorer.position];
314         if (info != "(none)") {
315             this.inputEl.value = info;
316             this.recalc_input_lines();
317         }
318     }
319     if (mode == mode_portal && explorer.position in game.portals) {
320         let portal = game.portals[explorer.position]
321         this.inputEl.value = portal;
322         this.recalc_input_lines();
323     } else if (mode == mode_teleport) {
324         tui.log_msg("@ May teleport to: " + tui.teleport_target);
325         tui.log_msg("@ Type Y or y to affirm, other keys to abort.");
326     }
327     this.full_refresh();
328   },
329   empty_input: function(str) {
330       this.inputEl.value = "";
331       if (this.mode.has_input_prompt) {
332           this.recalc_input_lines();
333       } else {
334           this.height_input = 0;
335       }
336   },
337   recalc_input_lines: function() {
338       this.input_lines = this.msg_into_lines_of_width(this.input_prompt + this.inputEl.value, this.window_width);
339       this.height_input = this.input_lines.length;
340   },
341   msg_into_lines_of_width: function(msg, width) {
342     let chunk = "";
343     let lines = [];
344     for (let i = 0, x = 0; i < msg.length; i++, x++) {
345       if (x >= width || msg[i] == "\n") {
346         lines.push(chunk);
347         chunk = "";
348         x = 0;
349       };
350       if (msg[i] != "\n") {
351         chunk += msg[i];
352       }
353     }
354     lines.push(chunk);
355     return lines;
356   },
357   log_msg: function(msg) {
358       this.log.push(msg);
359       while (this.log.length > 100) {
360         this.log.shift();
361       };
362       this.full_refresh();
363   },
364   log_help: function() {
365     this.log_msg("HELP:");
366     this.log_msg("chat mode commands:");
367     this.log_msg("  " + command_char_selector.value + "nick NAME - re-name yourself to NAME");
368     this.log_msg("  " + command_char_selector.value + "msg USER TEXT - send TEXT to USER");
369     this.log_msg("  " + command_char_selector.value + "help - show this help");
370     this.log_msg("  " + command_char_selector.value + "p or " + command_char_selector.value + "play - switch to play mode");
371     this.log_msg("  " + command_char_selector.value + "? or " + command_char_selector.value + "study - switch to study mode");
372     this.log_msg("commands common to study and play mode:");
373     this.log_msg("  " + this.movement_keys_desc + " - move");
374     this.log_msg("  c - switch to chat mode");
375     this.log_msg("commands specific to play mode:");
376     this.log_msg("  e - write following ASCII character");
377     this.log_msg("  f - flatten surroundings");
378     this.log_msg("  ? - switch to study mode");
379     this.log_msg("commands specific to study mode:");
380     this.log_msg("  e - annotate terrain");
381     this.log_msg("  p - switch to play mode");
382   },
383   draw_map: function() {
384     let map_lines = [];
385     let line = [];
386     for (let i = 0, j = 0; i < game.map.length; i++, j++) {
387         if (j == game.map_size[1]) {
388             map_lines.push(line);
389             line = [];
390             j = 0;
391         };
392         line.push(game.map[i]);
393     };
394     map_lines.push(line);
395     let center_pos = [Math.floor(game.map_size[0] / 2),
396                       Math.floor(game.map_size[1] / 2)];
397     for (const thing_id in game.things) {
398         let t = game.things[thing_id];
399         map_lines[t.position[0]][t.position[1]] = '@';
400         if (game.player_id == thing_id) {
401             center_pos = t.position;
402         }
403     };
404     if (tui.mode.shows_info) {
405         map_lines[explorer.position[0]][explorer.position[1]] = '?';
406         center_pos = explorer.position;
407     }
408     let offset = [(terminal.rows / 2) - center_pos[0],
409                   this.window_width / 2 - center_pos[1]];
410       for (let term_y = offset[0], map_y = 0;
411            term_y < terminal.rows && map_y < game.map_size[0];
412            term_y++, map_y++) {
413         if (term_y >= 0) {
414             let to_draw = map_lines[map_y].join('').slice(0, this.window_width - offset[1]);
415             terminal.write(term_y, offset[1], to_draw);
416         }
417     }
418   },
419   draw_mode_line: function() {
420       terminal.write(0, this.window_width, 'MODE: ' + this.mode.name);
421   },
422   draw_turn_line: function(n) {
423     terminal.write(1, this.window_width, 'TURN: ' + game.turn);
424   },
425   draw_history: function() {
426       let log_display_lines = [];
427       for (let line of this.log) {
428           log_display_lines = log_display_lines.concat(this.msg_into_lines_of_width(line, this.window_width));
429       };
430       for (let y = terminal.rows - 1 - this.height_input,
431                i = log_display_lines.length - 1;
432            y >= this.height_header && i >= 0;
433            y--, i--) {
434           terminal.write(y, this.window_width, log_display_lines[i]);
435       }
436   },
437   draw_info: function() {
438     let lines = this.msg_into_lines_of_width(explorer.get_info(), this.window_width);
439     for (let y = this.height_header, i = 0; y < terminal.rows && i < lines.length; y++, i++) {
440       terminal.write(y, this.window_width, lines[i]);
441     }
442   },
443   draw_input: function() {
444     if (this.mode.has_input_prompt) {
445         for (let y = terminal.rows - this.height_input, i = 0; i < this.input_lines.length; y++, i++) {
446             terminal.write(y, this.window_width, this.input_lines[i]);
447         }
448     }
449   },
450   full_refresh: function() {
451     terminal.drawBox(0, 0, terminal.rows, terminal.cols);
452     if (this.mode.is_intro) {
453         this.draw_history();
454         this.draw_input();
455     } else {
456         this.draw_map();
457         this.draw_turn_line();
458         this.draw_mode_line();
459         if (this.mode.shows_info) {
460           this.draw_info();
461         } else {
462           this.draw_history();
463         }
464         this.draw_input();
465     }
466     terminal.refresh();
467   }
468 }
469
470 let game = {
471     init: function() {
472         this.things = {};
473         this.turn = -1;
474         this.map = "";
475         this.map_size = [0,0];
476         this.player_id = -1;
477         this.portals = {};
478     },
479     get_thing: function(id_, create_if_not_found=false) {
480         if (id_ in game.things) {
481             return game.things[id_];
482         } else if (create_if_not_found) {
483             let t = new Thing([0,0]);
484             game.things[id_] = t;
485             return t;
486         };
487     }
488 }
489
490 game.init();
491 tui.init();
492 tui.full_refresh();
493 server.init(websocket_location);
494
495 let explorer = {
496     position: [0,0],
497     info_db: {},
498     move: function(direction) {
499         let try_pos = [0,0];
500         try_pos[0] = this.position[0];
501         try_pos[1] = this.position[1];
502         if (direction == 'left') {
503             try_pos[1] -= 1;
504         } else if (direction == 'right') {
505             try_pos[1] += 1;
506         } else if (direction == 'up') {
507             try_pos[0] -= 1;
508         } else if (direction == 'down') {
509             try_pos[0] += 1;
510         };
511         if (!(try_pos[0] < 0) &&
512             !(try_pos[1] < 0) &&
513             !(try_pos[0] >= game.map_size[0])
514             && !(try_pos[1] >= game.map_size[1])) {
515             this.position = try_pos;
516             this.query_info();
517             tui.full_refresh();
518         }
519     },
520     update_info_db: function(yx, str) {
521         this.info_db[yx] = str;
522         if (tui.mode == mode_study) {
523             tui.full_refresh();
524         }
525     },
526     empty_info_db: function() {
527         this.info_db = {};
528         if (tui.mode == mode_study) {
529             tui.full_refresh();
530         }
531     },
532     query_info: function() {
533         server.send(["GET_ANNOTATION", unparser.to_yx(explorer.position)]);
534     },
535     get_info: function() {
536         let info = "";
537         let position_i = this.position[0] * game.map_size[1] + this.position[1];
538         info += "TERRAIN: " + game.map[position_i] + "\n";
539         for (let t_id in game.things) {
540              let t = game.things[t_id];
541              if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
542                  info += "PLAYER @";
543                  if (t.name_) {
544                      info += ": " + t.name_;
545                  }
546                  info += "\n";
547              }
548         }
549         if (this.position in game.portals) {
550             info += "PORTAL: " + game.portals[this.position] + "\n";
551         }
552         if (this.position in this.info_db) {
553             info += "ANNOTATIONS: " + this.info_db[this.position];
554         } else {
555             info += 'waiting …';
556         }
557         return info;
558     },
559     annotate: function(msg) {
560         if (msg.length == 0) {
561             msg = " ";  // triggers annotation deletion
562         }
563         server.send(["ANNOTATE", unparser.to_yx(explorer.position), msg]);
564     },
565     set_portal: function(msg) {
566         if (msg.length == 0) {
567             msg = " ";  // triggers portal deletion
568         }
569         server.send(["PORTAL", unparser.to_yx(explorer.position), msg]);
570     }
571 }
572
573 tui.inputEl.addEventListener('input', (event) => {
574     if (tui.mode.has_input_prompt) {
575         let max_length = tui.window_width * terminal.rows - tui.input_prompt.length;
576         if (tui.inputEl.value.length > max_length) {
577             tui.inputEl.value = tui.inputEl.value.slice(0, max_length);
578         };
579         tui.recalc_input_lines();
580         tui.full_refresh();
581     } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
582         server.send(["TASK:WRITE", tui.inputEl.value[0]]);
583         tui.switch_mode(mode_play);
584     } else if (tui.mode == mode_teleport) {
585         if (['Y', 'y'].includes(tui.inputEl.value[0])) {
586             server.reconnect_to(tui.teleport_target);
587         } else {
588             tui.log_msg("@ teleportation aborted");
589             tui.switch_mode(mode_play);
590         }
591     }
592 }, false);
593 tui.inputEl.addEventListener('keydown', (event) => {
594     if (event.key == 'Enter') {
595         event.preventDefault();
596     }
597     if (tui.mode == mode_login && event.key == 'Enter') {
598         server.send(['LOGIN', tui.inputEl.value]);
599         tui.switch_mode(mode_login);
600     } else if (tui.mode == mode_portal && event.key == 'Enter') {
601         explorer.set_portal(tui.inputEl.value);
602         tui.switch_mode(mode_study, true);
603     } else if (tui.mode == mode_annotate && event.key == 'Enter') {
604         explorer.annotate(tui.inputEl.value);
605         tui.switch_mode(mode_study, true);
606     } else if (tui.mode == mode_chat && event.key == 'Enter') {
607         let [tokens, token_starts] = parser.tokenize(tui.inputEl.value);
608         if (tokens.length > 0 && tokens[0].length > 0) {
609             if (tui.inputEl.value[0][0] == command_char_selector.value) {
610                 if (tokens[0].slice(1) == 'play' || tokens[0].slice(1) == 'p') {
611                     tui.switch_mode(mode_play);
612                 } else if (tokens[0].slice(1) == 'study' || tokens[0].slice(1) == '?') {
613                     tui.switch_mode(mode_study);
614                 } else if (tokens[0].slice(1) == 'help') {
615                     tui.log_help();
616                 } else if (tokens[0].slice(1) == 'nick') {
617                     if (tokens.length > 1) {
618                         server.send(['LOGIN', tokens[1]]);
619                     } else {
620                         tui.log_msg('? need login name');
621                     }
622                 } else if (tokens[0].slice(1) == 'msg') {
623                     if (tokens.length > 2) {
624                         let msg = tui.inputEl.value.slice(token_starts[2]);
625                         server.send(['QUERY', tokens[1], msg]);
626                     } else {
627                         tui.log_msg('? need message target and message');
628                     }
629                 } else if (tokens[0].slice(1) == 'reconnect') {
630                     if (tokens.length > 1) {
631                         server.reconnect_to(tokens[1]);
632                     } else {
633                         server.reconnect();
634                     }
635                 } else {
636                     tui.log_msg('? unknown command');
637                 }
638             } else {
639                 server.send(['ALL', tui.inputEl.value]);
640             }
641         } else if (tui.inputEl.valuelength > 0) {
642             server.send(['ALL', tui.inputEl.value]);
643         }
644         tui.empty_input();
645         tui.full_refresh();
646       } else if (tui.mode == mode_play) {
647           if (event.key === 'c') {
648               event.preventDefault();
649               tui.switch_mode(mode_chat);
650           } else if (event.key === 'e') {
651               event.preventDefault();
652               tui.switch_mode(mode_edit);
653           } else if (event.key === '?') {
654               tui.switch_mode(mode_study);
655           } else if (event.key === 'F1') {
656               tui.log_help();
657           } else if (event.key === 'f') {
658               server.send(["TASK:FLATTEN_SURROUNDINGS"]);
659           } else if (event.key === tui.key_left) {
660               server.send(['TASK:MOVE', 'LEFT']);
661           } else if (event.key === tui.key_right) {
662               server.send(['TASK:MOVE', 'RIGHT']);
663           } else if (event.key === tui.key_up) {
664               server.send(['TASK:MOVE', 'UP']);
665           } else if (event.key === tui.key_down) {
666               server.send(['TASK:MOVE', 'DOWN']);
667           };
668     } else if (tui.mode == mode_study) {
669         if (event.key === 'c') {
670             event.preventDefault();
671             tui.switch_mode(mode_chat);
672         } else if (event.key == 'p') {
673             tui.switch_mode(mode_play);
674         } else if (event.key === 'P') {
675             event.preventDefault();
676             tui.switch_mode(mode_portal);
677         } else if (event.key === tui.key_left) {
678               explorer.move('left');
679         } else if (event.key === tui.key_right) {
680               explorer.move('right');
681         } else if (event.key === tui.key_up) {
682               explorer.move('up');
683         } else if (event.key === tui.key_down) {
684               explorer.move('down');
685         } else if (event.key === 'e') {
686           event.preventDefault();
687           tui.switch_mode(mode_annotate);
688         };
689     }
690 }, false);
691
692 wasd_selector.addEventListener('input', function() {
693     tui.init_wasd();
694 }, false);
695 rows_selector.addEventListener('input', function() {
696     if (rows_selector.value % 2 != 0) {
697         return;
698     }
699     terminal.initialize();
700     tui.full_refresh();
701 }, false);
702 cols_selector.addEventListener('input', function() {
703     if (cols_selector.value % 4 != 0) {
704         return;
705     }
706     terminal.initialize();
707     tui.window_width = terminal.cols / 2,
708     tui.full_refresh();
709 }, false);
710 window.setInterval(function() {
711     if (!(['input', 'n_cols', 'n_rows', 'WASD_selector', 'command_char'].includes(document.activeElement.id))) {
712         tui.inputEl.focus();
713     }
714 }, 100);
715 </script>
716 </body></html>