Improved yosys.js example
authorClifford Wolf <clifford@clifford.at>
Sun, 15 Feb 2015 15:16:08 +0000 (16:16 +0100)
committerClifford Wolf <clifford@clifford.at>
Sun, 15 Feb 2015 15:16:08 +0000 (16:16 +0100)
misc/yosys.html

index c82bc187105360ecb4f77689049c7a0d5bb9e099..929d0dd3b25894b1062bac553a47a4a61036113f 100644 (file)
@@ -1,60 +1,72 @@
-<html>
-  <head>
-    <title>yosys.js example application</title>
-  </head>
-  <body onload="document.getElementById('command').focus()">
-    <h1>yosys.js example application</h1>
-    <div><textarea id="output" style="width: 100%" rows="30" cols="100">Loading...</textarea></div>
-    <div><form onsubmit="return run_command()"><tt><span id="prompt"><br/>yosys&gt; </span></tt><input id="command" type="text" size="100"></form></div>
-    <script type='text/javascript'>
-      var got_log_messages = false;
-      var Module = {
-        print: (function() {
-          var element = document.getElementById('output');
-          if (element) element.value = ''; // clear browser cache
-          return function(text) {
-           got_log_messages = true;
-            if (element && typeof(text) != "number") {
-              element.value += text + "\n";
-              element.scrollTop = element.scrollHeight; // focus on bottom
-            }
-          };
-       })(),
-        printErr: (function() {
-          var element = document.getElementById('output');
-          if (element) element.value = ''; // clear browser cache
-          return function(text) {
-            if (element && typeof(text) != "number") {
-             console.log(text);
-             if (got_log_messages) {
-                element.value += text + "\n";
-                element.scrollTop = element.scrollHeight; // focus on bottom
-             }
-            }
-          };
-       })(),
-       command: (function(cmd) {
-         Module.ccall('run', '', ['string'], [cmd])
-       }),
-       prompt: (function(cmd) {
-         return Module.ccall('prompt', 'string', [], [])
-       })
-      };
-      function run_command() {
-        var cmd = document.getElementById('command').value;
-       document.getElementById('command').value = '';
-        Module.print(Module.prompt() + cmd);
-       try {
-               Module.command(cmd);
-       } catch (e) {
-               Module.print('Caught JavaScript exception. (see JavaScript console for details.)');
-               console.log(e);
-       }
-       document.getElementById('command').focus();
-       document.getElementById('prompt').innerText = Module.prompt();
-       return false;
-      }
-    </script>
-    <script async type="text/javascript" src="yosys.js"></script>
-  </body>
-</html>
+<html><head>
+       <title>yosys.js example application</title>
+</head><body onload="document.getElementById('command').focus()">
+       <h1>yosys.js example application</h1>
+       <div><textarea id="output" style="width: 100%" rows="30" cols="100"></textarea></div>
+       <div id="wait" style="display: block"><br/><b><span id="waitmsg">Loading...</span></b></div>
+       <div id="input" style="display: none"><form onsubmit="return run_command()"><tt><span id="prompt"><br/>yosys&gt; </span></tt><input id="command" type="text" size="100"></form></div>
+       <script type='text/javascript'>
+               var got_log_messages = false;
+               var Module = {
+                       print: (function() {
+                               var element = document.getElementById('output');
+                               if (element) element.value = ''; // clear browser cache
+                               return function(text) {
+                                       if (!got_log_messages) {
+                                               document.getElementById('wait').style.display = 'none';
+                                               document.getElementById('input').style.display = 'block';
+                                               document.getElementById('waitmsg').innerText = 'Waiting for yosys.js...';
+                                               got_log_messages = true;
+                                       }
+                                       if (element && typeof(text) != "number") {
+                                               element.value += text + "\n";
+                                               element.scrollTop = element.scrollHeight; // focus on bottom
+                                       }
+                               };
+                       })(),
+                       printErr: (function() {
+                               var element = document.getElementById('output');
+                               if (element) element.value = ''; // clear browser cache
+                               return function(text) {
+                                       if (element && typeof(text) != "number") {
+                                               console.log(text);
+                                               if (got_log_messages) {
+                                                       element.value += text + "\n";
+                                                       element.scrollTop = element.scrollHeight; // focus on bottom
+                                               }
+                                       }
+                               };
+                       })(),
+                       command: (function(cmd) {
+                               Module.ccall('run', '', ['string'], [cmd])
+                       }),
+                       prompt: (function(cmd) {
+                               return Module.ccall('prompt', 'string', [], [])
+                       })
+               };
+               function run_command() {
+                       var cmd = document.getElementById('command').value;
+                       document.getElementById('command').value = '';
+                       Module.print(Module.prompt() + cmd);
+                       document.getElementById('wait').style.display = 'block';
+                       document.getElementById('input').style.display = 'none';
+
+                       function run_command_bh() {
+                               try {
+                                       Module.command(cmd);
+                               } catch (e) {
+                                       Module.print('Caught JavaScript exception. (see JavaScript console for details.)');
+                                       console.log(e);
+                               }
+                               document.getElementById('wait').style.display = 'none';
+                               document.getElementById('input').style.display = 'block';
+                               document.getElementById('prompt').innerText = Module.prompt();
+                               document.getElementById('command').focus();
+                       }
+
+                       window.setTimeout(run_command_bh, 50);
+                       return false;
+               }
+       </script>
+       <script async type="text/javascript" src="yosys.js"></script>
+</body></html>