App-screenorama
view release on metacpan or search on metacpan
script/screenorama view on Meta::CPAN
cursor.visible = true;
cursor.style.display = 'inline';
setInterval(
function() {
cursor.style.opacity = cursor.visible ? 0.02 : 1.0;
cursor.visible = !cursor.visible;
},
700
);
var tDown;
attach(document, 'mousedown touchstart', function(e) { tDown = new Date().getTime(); });
attach(document, 'mouseup touchstop', function(e) { if (new Date().getTime() - tDown < 250) input.focus(); });
screenorama.ws.onopen = function() {
input.focus();
attach(input, 'keydown', screenorama.keydown);
attach(input, 'keypress', screenorama.keypress);
attach(input, 'paste', screenorama.paste);
setInterval(function() { screenorama.send('{}'); }, 5000);
};
% }
screenorama.ws.onmessage = function(e) {
if (window.console) console.log(e.data);
var data = JSON.parse(e.data);
if (typeof data.output !== 'undefined') screenorama.printToScreen(data.output.replace(/</g, '<'));
if (typeof data.exit_value !== 'undefined') screenorama.exitStatus(data);
window.scrollTo(0, document.body.scrollHeight);
};
};
screenorama.exitStatus = function(data) {
var cursor = document.querySelector('.cursor');
var shell = document.querySelector('.shell');
var status = document.createElement('div');
cursor.style.display = 'none';
status.className = 'status';
status.innerHTML = '$?=' + data.exit_value;
shell.appendChild(status);
};
screenorama.keydown = function(e) {
var k = e.keyCode || e.which;
if (window.console) console.log('keydown: ' + k);
switch (k) {
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;
( run in 0.802 second using v1.01-cache-2.11-cpan-2398b32b56e )