From e0c0fb6917cae9bf0d6dca45167170166f1afa1a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 10 Jun 2016 19:15:52 -0700 Subject: [PATCH] Add basic options selection to demo This will make it easier to test options without needing to modify the demo. --- demo/index.html | 6 +++++- demo/main.js | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/demo/index.html b/demo/index.html index 92ccc94..ff10a5c 100644 --- a/demo/index.html +++ b/demo/index.html @@ -9,12 +9,16 @@ -

xterm.js: xterm, in the browser

+
+

Options

+ +
+ diff --git a/demo/main.js b/demo/main.js index 70d64c5..59bdacd 100644 --- a/demo/main.js +++ b/demo/main.js @@ -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; -- 2.39.5