<link rel="stylesheet" href="../src/xterm.css" />
<link rel="stylesheet" href="../addons/fullscreen/fullscreen.css" />
<link rel="stylesheet" href="style.css" />
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script src="../src/xterm.js" ></script>
<script src="../addons/attach/attach.js" ></script>
<script src="../addons/fit/fit.js" ></script>
<div>
<h2>Options</h2>
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
+ <div>
+ <h3>Size</h3>
+ <div>
+ <div style="display: inline-block; margin-right: 16px;">
+ <label for="cols">Columns</label>
+ <input type="number" id="cols" />
+ </div>
+ <div style="display: inline-block; margin-right: 16px;">
+ <label for="rows">Rows</label>
+ <input type="number" id="rows" />
+ </div>
+ </div>
+ </div>
</div>
<script src="main.js" defer ></script>
</body>
protocol,
socketURL,
socket,
- pid;
+ pid,
+ charWidth,
+ charHeight;
+
+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);
+}
-var terminalContainer = document.getElementById('terminal-container');
-var optionElements = {
- cursorBlink: document.querySelector('#option-cursor-blink')
-};
+colsElement.addEventListener('change', setTerminalSize);
+rowsElement.addEventListener('change', setTerminalSize);
optionElements.cursorBlink.addEventListener('change', 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;
socket.onerror = runFakeTerminal;
});
});
-
- term.fit();
}
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');
}