mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-06-03 19:09:42 +00:00
And... done
This commit is contained in:
@@ -1,41 +1,57 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
var ws;
|
||||
var cols, rows, term, ws;
|
||||
|
||||
ws = null;
|
||||
term = ws = null;
|
||||
|
||||
cols = rows = null;
|
||||
|
||||
$(function() {
|
||||
ws = new WebSocket('ws://' + document.location.host + '/ws');
|
||||
ws.onopen = function() {
|
||||
return console.log("WebSocket open", arguments);
|
||||
console.log("WebSocket open", arguments);
|
||||
term = new Terminal({
|
||||
visualBell: true,
|
||||
screenKeys: true
|
||||
});
|
||||
term.on("data", function(data) {
|
||||
return ws.send('SH|' + data);
|
||||
});
|
||||
term.on("title", function(title) {
|
||||
return document.title = title;
|
||||
});
|
||||
term.open($('main').get(0));
|
||||
$('.terminal').attr('style', '');
|
||||
return $(window).trigger('resize');
|
||||
};
|
||||
ws.onclose = function() {
|
||||
if (term) {
|
||||
term.destroy();
|
||||
}
|
||||
return console.log("WebSocket closed", arguments);
|
||||
};
|
||||
ws.onerror = function() {
|
||||
return console.log("WebSocket error", arguments);
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
return $('.term code').html($('.term code').html() + event.data);
|
||||
return term.write(event.data);
|
||||
};
|
||||
return $('html,body').on('keypress', function(event) {
|
||||
var code;
|
||||
code = event.keyCode;
|
||||
ws.send(String.fromCharCode(code));
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}).on('keydown', function(event) {
|
||||
var code;
|
||||
code = event.keyCode;
|
||||
if (code === 17) {
|
||||
return;
|
||||
}
|
||||
if (event.ctrlKey) {
|
||||
code -= 64;
|
||||
ws.send(String.fromCharCode(code));
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
return $(window).resize(function() {
|
||||
var $main, $termtest, $test, eh, ew, h, w;
|
||||
$main = $('main');
|
||||
$termtest = $('<div>').addClass('terminal');
|
||||
$test = $('<div>').css({
|
||||
display: 'inline-block'
|
||||
}).text('0123456789');
|
||||
$termtest.append($test);
|
||||
$main.append($termtest);
|
||||
ew = $test.outerWidth() / 10;
|
||||
eh = $test.outerHeight();
|
||||
$termtest.remove();
|
||||
w = $main.outerWidth();
|
||||
h = $main.outerHeight();
|
||||
cols = Math.floor(w / ew);
|
||||
rows = Math.floor(h / eh);
|
||||
term.resize(cols, rows);
|
||||
return ws.send("RS|" + cols + "," + rows);
|
||||
});
|
||||
});
|
||||
|
||||
5756
app/static/javascripts/term.js
Normal file
5756
app/static/javascripts/term.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user