]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Add basic options selection to demo
authorDaniel Imms <daimms@microsoft.com>
Sat, 11 Jun 2016 02:15:52 +0000 (19:15 -0700)
committerDaniel Imms <daimms@microsoft.com>
Sat, 11 Jun 2016 02:15:58 +0000 (19:15 -0700)
This will make it easier to test options without needing to modify the demo.

demo/index.html
demo/main.js

index 92ccc94ca3636cabf75cd2cfcd9929ea9dff55b7..ff10a5cbd7ba6294c7b4afec8b5ddf7f2266e1a7 100644 (file)
@@ -9,12 +9,16 @@
         <script src="../addons/attach/attach.js" ></script>
         <script src="../addons/fit/fit.js" ></script>
         <script src="../addons/fullscreen/fullscreen.js" ></script>
-        <script src="main.js" defer ></script>
     </head>
     <body>
         <h1>
             xterm.js: xterm, in the browser
         </h1>
         <div id="terminal-container"></div>
+        <div>
+          <h2>Options</h2>
+          <label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
+        </div>
+        <script src="main.js" defer ></script>
     </body>
 </html>
index 70d64c5900c83767a493530c74a1f2e12a892025..59bdacdd226a1e257ddf97e30628f8823f1727e8 100644 (file)
@@ -1,11 +1,36 @@
-var terminalContainer = document.getElementById('terminal-container'),
-    term = new Terminal(),
-    protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://',
-    socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/bash',
-    socket = new WebSocket(socketURL);
+var term,
+    protocol,
+    socketURL,
+    socket;
+
+var terminalContainer = document.getElementById('terminal-container');
+var optionElements = {
+  cursorBlink: document.querySelector('#option-cursor-blink')
+};
+
+optionElements.cursorBlink.addEventListener('change', createTerminal);
+
+createTerminal();
+
+function createTerminal() {
+  while (terminalContainer.children.length) {
+    terminalContainer.removeChild(terminalContainer.children[0]);
+  }
+  term = new Terminal({
+    cursorBlink: optionElements.cursorBlink.checked
+  });
+  protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
+  socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/bash';
+  socket = new WebSocket(socketURL);
+
+  term.open(terminalContainer);
+  term.fit();
+
+  socket.onopen = runRealTerminal;
+  socket.onclose = runFakeTerminal;
+  socket.onerror = runFakeTerminal;
+}
 
-term.open(terminalContainer);
-term.fit();
 
 function runRealTerminal() {
   term.attach(socket);
@@ -54,7 +79,3 @@ function runFakeTerminal() {
     term.write(data);
   });
 }
-
-socket.onopen = runRealTerminal;
-socket.onclose = runFakeTerminal;
-socket.onerror = runFakeTerminal;