diff --git a/demo/index.html b/demo/index.html index ff10a5cb..74c954d6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -5,6 +5,7 @@ + @@ -18,6 +19,19 @@

Options

+
+

Size

+
+
+ + +
+
+ + +
+
+
diff --git a/demo/main.js b/demo/main.js index b46716bf..86fbd314 100644 --- a/demo/main.js +++ b/demo/main.js @@ -2,12 +2,30 @@ var term, protocol, socketURL, socket, - pid; + pid, + charWidth, + charHeight; -var terminalContainer = document.getElementById('terminal-container'); -var optionElements = { - cursorBlink: document.querySelector('#option-cursor-blink') -}; +var terminalContainer = document.getElementById('terminal-container'), + optionElements = { + cursorBlink: document.querySelector('#option-cursor-blink') + }, + colsElement = document.getElementById('cols'), + rowsElement = document.getElementById('rows'); + +function setTerminalSize () { + var cols = parseInt(colsElement.value), + rows = parseInt(rowsElement.value), + width = (cols * charWidth).toString() + 'px', + height = (rows * charHeight).toString() + 'px'; + + terminalContainer.style.width = width; + terminalContainer.style.height = height; + term.resize(cols, rows); +} + +colsElement.addEventListener('change', setTerminalSize); +rowsElement.addEventListener('change', setTerminalSize); optionElements.cursorBlink.addEventListener('change', createTerminal); @@ -25,17 +43,30 @@ function createTerminal() { if (!pid) { return; } + var cols = size.cols, + rows = size.rows, + url = '/terminals/' + pid + '/size?cols=' + cols + '&rows=' + rows; + + fetch(url, {method: 'POST'}); }); protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://'; socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/'; term.open(terminalContainer); + term.fit(); var initialGeometry = term.proposeGeometry(), cols = initialGeometry.cols, rows = initialGeometry.rows; + colsElement.value = cols; + rowsElement.value = rows; + fetch('/terminals?cols=' + cols + '&rows=' + rows, {method: 'POST'}).then(function (res) { + + charWidth = Math.ceil(term.element.offsetWidth / cols); + charHeight = Math.ceil(term.element.offsetHeight / rows); + res.text().then(function (pid) { window.pid = pid; socketURL += pid; @@ -45,8 +76,6 @@ function createTerminal() { socket.onerror = runFakeTerminal; }); }); - - term.fit(); } @@ -82,9 +111,7 @@ function runFakeTerminal() { if (ev.keyCode == 13) { term.prompt(); } else if (ev.keyCode == 8) { - /* - * Do not delete the prompt - */ + // Do not delete the prompt if (term.x > 2) { term.write('\b \b'); } diff --git a/demo/style.css b/demo/style.css index c93ca74f..2f05e309 100644 --- a/demo/style.css +++ b/demo/style.css @@ -9,8 +9,8 @@ h1 { } #terminal-container { - width: 960px; - height: 600px; + width: 800px; + height: 450px; margin: 0 auto; padding: 2px; }