home · contact · privacy
Add blink screen on trivial errors instead of log messages.
[plomrogue2-experiments] / new2 / rogue_chat_nocanvas_monochrome.html
index e8f7873eb3794407c53747938bfe6ec2e1ecd459..096b6d55fa3f8eee0726999b57b1faa44bae5da6 100644 (file)
@@ -11,8 +11,12 @@ let websocket_location = "ws://localhost:8000";
 let terminal = {
   rows: 24,
   cols: 80,
+  foreground: 'white',
+  background: 'black',
   initialize: function() {
     this.pre_el = document.getElementById("terminal");
+    this.pre_el.style.color = this.foreground;
+    this.pre_el.style.backgroundColor = this.background;
     this.content = [];
       let line = []
     for (let y = 0, x = 0; y <= this.rows; x++) {
@@ -28,6 +32,14 @@ let terminal = {
         line.push(' ');
     }
   },
+  blink_screen: function() {
+      this.pre_el.style.color = this.background;
+      this.pre_el.style.backgroundColor = this.foreground;
+      setTimeout(() => {
+          this.pre_el.style.color = this.foreground;
+          this.pre_el.style.backgroundColor = this.background;
+      }, 100);
+  },
   refresh: function() {
       let pre_string = '';
       for (let y = 0; y < this.rows; y++) {
@@ -257,8 +269,12 @@ let tui = {
       this.height_input = this.input_lines.length;
   },
   shorten_input: function() {
-      this.input = tui.input.slice(0, -1);
-      this.recalc_input_lines();
+      if (this.input.length == 0) {
+          terminal.blink_screen();
+      } else {
+          this.input = tui.input.slice(0, -1);
+          this.recalc_input_lines();
+      }
   },
   draw_input: function() {
     terminal.drawBox(terminal.rows - this.height_input, this.window_width, this.height_input, this.window_width);
@@ -385,6 +401,8 @@ server.websocket.onmessage = function (event) {
   } else if (tokens[0] === 'UNHANDLED_INPUT') {
      tui.log_msg('? unknown command');
      tui.refresh();
+  } else if (tokens[0] === 'PLAY_ERROR') {
+     terminal.blink_screen();
   } else if (tokens[0] === 'ARGUMENT_ERROR') {
      tui.log_msg('? syntax error: ' + tokens[1]);
      tui.refresh();