App-screenorama
view release on metacpan or search on metacpan
script/screenorama view on Meta::CPAN
case 8: // backspace
return screenorama.send('{"key":' + 0x7f + '}', e);
case 9: // tab
return screenorama.send('{"key":9}', e);
}
};
screenorama.keypress = function(e) {
e.preventDefault();
screenorama.send('{"key":' + (e.keyCode || e.which) + '}');
};
screenorama.paste = function(e) {
var keys = e.clipboardData.getData('text/plain');
e.preventDefault();
for (var i = 0; i < keys.length; i++) screenorama.send('{"key":' + keys.charCodeAt(i) + '}');
};
screenorama.printToScreen = function(str) {
var output = document.querySelector('.output');
var clear;
str = str
.replace(/\u001B\[(?:0?(\d?);(\d\d)|(\d*)(X?))m/g, screenorama.replaceColors)
.replace(/(\u001B\[K|\x08\s\x08)/g, function() { screenorama.buf = screenorama.buf.replace(/[\x00-\x1f]*.[\x00-\x1f]*$/, ''); return ''; })
.replace(/\u001B\(B/g, function() { return ''; })
.replace(/\u001B\[3;J\u001B\[H\u001B\[2J(.*)/, function(a, c) { clear = c; })
screenorama.buf += str;
if (typeof clear != 'undefined') {
var shell = output.parentNode;
var lines = shell.querySelectorAll('.line') || [];
for (i = 0; i < lines.length; i++) shell.removeChild(lines[i]);
screenorama.buf = clear;
}
screenorama.buf = screenorama.buf.replace(/(.*?)\r?\n/g, function(a, c) {
var line = document.createElement('pre');
line.className = 'line';
line.innerHTML = c;
output.parentNode.insertBefore(line, output);
return '';
});
output.innerHTML = screenorama.buf;
};
screenorama.replaceColors = function(match, x, a, b) {
var closing = screenorama.replaceColors.span ? '</span>' : '';
var style = [];
console.log('replaceColors("' + [match, x, a, b].join('", "') + '") == ' + (termColors[b || a] || closing));
screenorama.replaceColors.span = false;
if (!a && typeof b == 'undefined') { return closing; } // regular
if (termColors[b]) style.push('color: ' + termColors[b]);
else if (termColors[a]) style.push('background-color: ' + termColors[a]);
if (a == 1) { style.push('font-weight: bold'); }
else if (a == 4) { style.push('text-decoration: underline'); }
screenorama.replaceColors.span = true;
return closing + '<span style="' + style.join(';') + '">';
};
screenorama.send = function(msg, e) {
if (e) e.preventDefault();
console.log(msg);
screenorama.ws.send(msg);
};
window.onload = screenorama;
% end
</head>
<body>
<div class="shell"><span class="output"></span><span class="cursor" style="display:none">▂</span></div>
<input style="position:absolute;top:-100px">
</body>
</html>
( run in 0.418 second using v1.01-cache-2.11-cpan-d7f47b0818f )