Some polish

This commit is contained in:
Daniel Imms
2018-06-03 11:18:34 +01:00
parent 2d786910c8
commit 908b06cfa7
2 changed files with 39 additions and 161 deletions
+33 -92
View File
@@ -1,95 +1,36 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title>xterm.js demo</title> <title>xterm.js demo</title>
<link rel="stylesheet" href="/build/xterm.css" /> <link rel="stylesheet" href="/build/xterm.css" />
<link rel="stylesheet" href="/build/addons/fullscreen/fullscreen.css" /> <link rel="stylesheet" href="/build/addons/fullscreen/fullscreen.css" />
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
</head> </head>
<body> <body>
<h1 style="color: #2D2E2C">xterm.js: A terminal for the <em style="color: #5DA5D5">web</em></h1> <h1 style="color: #2D2E2C">xterm.js: A terminal for the <em style="color: #5DA5D5">web</em></h1>
<div id="terminal-container"></div> <div id="terminal-container"></div>
<div> <div>
<h2>Actions</h2> <h3>Actions</h3>
<p> <p>
<label>Find next <input id="find-next"/></label> <label>Find next <input id="find-next"/></label>
<label>Find previous <input id="find-previous"/></label> <label>Find previous <input id="find-previous"/></label>
</p> </p>
</div> </div>
<div> <div>
<h2>Options</h2> <h3>Options</h3>
<p> <p>These options can be set in the <code>Terminal</code> constructor or using the <code>Terminal.setOption</code> function.</p>
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label> <div id="options-container"></div>
</p> </div>
<p> <div>
<label><input type="checkbox" id="option-mac-option-is-meta"> macOptionIsMeta</label> <h3>Style</h3>
</p> <div style="display: inline-block; margin-right: 16px;">
<p> <label for="padding">Padding</label>
<label><input type="checkbox" id="option-transparency"> transparency</label> <input type="number" id="padding" />
</p> </div>
<p> </div>
<label> <p><strong>Attention:</strong> The demo is a barebones implementation and is designed for the development and evaluation of xterm.js only. Exposing the demo to the public as is would introduce security risks for the host.</p>
cursorStyle <script src="dist/bundle.js" defer ></script>
<select id="option-cursor-style"> </body>
<option value="block">block</option>
<option value="underline">underline</option>
<option value="bar">bar</option>
</select>
</label>
</p>
<p>
<label>
bellStyle
<select id="option-bell-style">
<option value="">none</option>
<option value="sound">sound</option>
<option value="visual">visual</option>
<option value="both">both</option>
</select>
</label>
</p>
<p>
<label>scrollback <input type="number" id="option-scrollback" value="1000" /></label>
</p>
<p>
<label>tabStopWidth <input type="number" id="option-tabstopwidth" value="8" /></label>
</p>
<p>
<label>
experimentalCharAtlas
<select id="option-experimental-char-atlas">
<option value="static" selected>static</option>
<option value="dynamic">dynamic</option>
<option value="none">none</option>
</select>
</label>
</p>
<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 style="display: inline-block; margin-right: 16px;">
<label for="padding">Padding</label>
<input type="number" id="padding" />
</div>
</div>
</div>
<div>
<h3>Accessibility</h3>
<p>
<label><input type="checkbox" id="option-screen-reader-mode"> screenReaderMode</label>
</p>
</div>
<p><strong>Attention:</strong> The demo is a barebones implementation and is designed for the development and evaluation of xterm.js only. Exposing the demo to the public as is would introduce security risks for the host.</p>
<script src="dist/bundle.js" defer ></script>
</body>
</html> </html>
+6 -69
View File
@@ -26,38 +26,13 @@ var terminalContainer = document.getElementById('terminal-container'),
findNext: document.querySelector('#find-next'), findNext: document.querySelector('#find-next'),
findPrevious: document.querySelector('#find-previous') findPrevious: document.querySelector('#find-previous')
}, },
optionElements = {
cursorBlink: document.querySelector('#option-cursor-blink'),
cursorStyle: document.querySelector('#option-cursor-style'),
macOptionIsMeta: document.querySelector('#option-mac-option-is-meta'),
scrollback: document.querySelector('#option-scrollback'),
transparency: document.querySelector('#option-transparency'),
tabstopwidth: document.querySelector('#option-tabstopwidth'),
experimentalCharAtlas: document.querySelector('#option-experimental-char-atlas'),
bellStyle: document.querySelector('#option-bell-style'),
screenReaderMode: document.querySelector('#option-screen-reader-mode')
},
colsElement = document.getElementById('cols'),
rowsElement = document.getElementById('rows'),
paddingElement = document.getElementById('padding'); paddingElement = document.getElementById('padding');
function setTerminalSize() {
var cols = parseInt(colsElement.value, 10);
var rows = parseInt(rowsElement.value, 10);
var width = (cols * term.renderer.dimensions.actualCellWidth + term.viewport.scrollBarWidth).toString() + 'px';
var height = (rows * term.renderer.dimensions.actualCellHeight).toString() + 'px';
terminalContainer.style.width = width;
terminalContainer.style.height = height;
term.fit();
}
function setPadding() { function setPadding() {
term.element.style.padding = parseInt(paddingElement.value, 10).toString() + 'px'; term.element.style.padding = parseInt(paddingElement.value, 10).toString() + 'px';
term.fit(); term.fit();
} }
colsElement.addEventListener('change', setTerminalSize);
rowsElement.addEventListener('change', setTerminalSize);
paddingElement.addEventListener('change', setPadding); paddingElement.addEventListener('change', setPadding);
actionElements.findNext.addEventListener('keypress', function (e) { actionElements.findNext.addEventListener('keypress', function (e) {
@@ -73,36 +48,6 @@ actionElements.findPrevious.addEventListener('keypress', function (e) {
} }
}); });
optionElements.cursorBlink.addEventListener('change', function () {
term.setOption('cursorBlink', optionElements.cursorBlink.checked);
});
optionElements.macOptionIsMeta.addEventListener('change', function () {
term.setOption('macOptionIsMeta', optionElements.macOptionIsMeta.checked);
});
optionElements.transparency.addEventListener('change', function () {
var checked = optionElements.transparency.checked;
term.setOption('allowTransparency', checked);
term.setOption('theme', checked ? {background: 'rgba(0, 0, 0, .5)'} : {});
});
optionElements.cursorStyle.addEventListener('change', function () {
term.setOption('cursorStyle', optionElements.cursorStyle.value);
});
optionElements.bellStyle.addEventListener('change', function () {
term.setOption('bellStyle', optionElements.bellStyle.value);
});
optionElements.scrollback.addEventListener('change', function () {
term.setOption('scrollback', parseInt(optionElements.scrollback.value, 10));
});
optionElements.tabstopwidth.addEventListener('change', function () {
term.setOption('tabStopWidth', parseInt(optionElements.tabstopwidth.value, 10));
});
optionElements.experimentalCharAtlas.addEventListener('change', function () {
term.setOption('experimentalCharAtlas', optionElements.experimentalCharAtlas.value);
});
optionElements.screenReaderMode.addEventListener('change', function () {
term.setOption('screenReaderMode', optionElements.screenReaderMode.checked);
});
createTerminal(); createTerminal();
function createTerminal() { function createTerminal() {
@@ -110,13 +55,7 @@ function createTerminal() {
while (terminalContainer.children.length) { while (terminalContainer.children.length) {
terminalContainer.removeChild(terminalContainer.children[0]); terminalContainer.removeChild(terminalContainer.children[0]);
} }
term = new Terminal({ term = new Terminal({});
macOptionIsMeta: optionElements.macOptionIsMeta.enabled,
cursorBlink: optionElements.cursorBlink.checked,
scrollback: parseInt(optionElements.scrollback.value, 10),
tabStopWidth: parseInt(optionElements.tabstopwidth.value, 10),
screenReaderMode: optionElements.screenReaderMode.checked
});
window.term = term; // Expose `term` to window for debugging purposes window.term = term; // Expose `term` to window for debugging purposes
term.on('resize', function (size) { term.on('resize', function (size) {
if (!pid) { if (!pid) {
@@ -145,7 +84,7 @@ function createTerminal() {
paddingElement.value = 0; paddingElement.value = 0;
// Set terminal size again to set the specific dimensions on the demo // Set terminal size again to set the specific dimensions on the demo
setTerminalSize(); updateTerminalSize();
fetch('/terminals?cols=' + term.cols + '&rows=' + term.rows, {method: 'POST'}).then(function (res) { fetch('/terminals?cols=' + term.cols + '&rows=' + term.rows, {method: 'POST'}).then(function (res) {
@@ -247,7 +186,7 @@ function initOptions(term) {
} }
}); });
var html = '<h1>Options</h1>'; var html = '';
booleanOptions.forEach(o => { booleanOptions.forEach(o => {
html += `<div><label><input id="opt-${o}" type="checkbox" ${term.getOption(o) ? 'checked' : ''}/> ${o}</label></div>`; html += `<div><label><input id="opt-${o}" type="checkbox" ${term.getOption(o) ? 'checked' : ''}/> ${o}</label></div>`;
}); });
@@ -262,21 +201,19 @@ function initOptions(term) {
} }
}); });
const container = document.createElement('div'); var container = document.getElementById('options-container');
container.innerHTML = html; container.innerHTML = html;
document.body.appendChild(container);
// Attach listeners // Attach listeners
// var allOptions = booleanOptions.concat(numberOptions, Object.keys(stringOptions));
booleanOptions.forEach(o => { booleanOptions.forEach(o => {
const input = document.getElementById(`opt-${o}`); var input = document.getElementById(`opt-${o}`);
input.addEventListener('change', () => { input.addEventListener('change', () => {
console.log('change', o, input.checked); console.log('change', o, input.checked);
term.setOption(o, input.checked); term.setOption(o, input.checked);
}); });
}); });
numberOptions.concat(Object.keys(stringOptions)).forEach(o => { numberOptions.concat(Object.keys(stringOptions)).forEach(o => {
const input = document.getElementById(`opt-${o}`); var input = document.getElementById(`opt-${o}`);
input.addEventListener('change', () => { input.addEventListener('change', () => {
console.log('change', o, input.value); console.log('change', o, input.value);
if (o === 'cols' || o === 'rows') { if (o === 'cols' || o === 'rows') {