feature(terminal) rm

This commit is contained in:
coderaiser 2015-02-18 08:26:09 -05:00
parent 744a9d03a5
commit f9c80c709c
6 changed files with 1 additions and 6063 deletions

View file

@ -6,7 +6,6 @@
"markdown",
"config",
"contact",
"terminal",
"upload",
"konsole", [{
"name": "remote",

View file

@ -290,13 +290,7 @@ var CloudCmd, Util, DOM;
case Key.TRA:
DOM.Images.show.load('top');
if (shift)
obj = CloudCmd.Terminal;
else
obj = CloudCmd.Konsole;
if (obj && obj.show)
obj.show();
CloudCmd.Konsole.show();
event.preventDefault();

View file

@ -1,187 +0,0 @@
var CloudCmd, Util, DOM, CloudFunc, Terminal, io;
(function(CloudCmd, Util, DOM, CloudFunc) {
'use strict';
CloudCmd.Terminal = TerminalProto;
function TerminalProto() {
var Name = 'Terminal',
Loading,
Element,
Term,
Cell,
Images = DOM.Images,
Size = {
cols: 0,
rows: 0
},
CHANNEL = CloudFunc.CHANNEL_TERMINAL,
CHANNEL_RESIZE = CloudFunc.CHANNEL_TERMINAL_RESIZE,
CloudTerm = this;
function init() {
Loading = true;
Util.exec.series([
DOM.loadJquery,
CloudCmd.View,
load,
DOM.loadSocket,
CloudTerm.show,
addListeners
]);
}
CloudTerm.show = show;
CloudTerm.write = write;
CloudTerm.hide = function() {
CloudCmd.View.hide();
};
function show(callback) {
if (!Loading) {
Images.show.load('top');
if (!Element) {
Element = DOM.load({
name : 'div',
id : 'terminal',
style : 'height :100%'
});
/* hack to determine console size
* inspired with
*
* https://github.com/petethepig/devtools-terminal
*/
Cell = DOM.load({
name : 'div',
inner : '&nbsp',
parent : Element,
style : 'position: absolute;' +
'top : -1000px;'
});
DOM.load.style({
id : 'terminal-css',
inner : '.view, .terminal {' +
'height' + ': 100%;' +
'}' +
'.terminal-cursor {' +
'background' + ': gray' +
'}'
});
Term = new Terminal({
screenKeys: true,
cursorBlink: false
});
Term.open(Element);
}
CloudCmd.View.show(Element, {
onUpdate : onResize,
afterShow : afterShow.bind(null, callback)
});
}
}
function write(data) {
Term.write(data);
}
function addListeners(callback) {
var href = CloudCmd.HOST,
FIVE_SECONDS = 5000,
socket = io.connect(href + '/terminal', {
'max reconnection attempts' : Math.pow(2, 32),
'reconnection limit' : FIVE_SECONDS
});
socket.on('connect', function() {
write('socket connected' + '\r');
});
socket.on('disconnect', function() {
write('socket disconnected' + '\r');
});
socket.on(CHANNEL, write);
socket.on(CHANNEL_RESIZE, function(size) {
Term.resize(size.cols, size.rows);
});
Term.on('data', function(data) {
socket.emit(CHANNEL, data);
});
Term.on('resize', function(size) {
socket.emit(CHANNEL_RESIZE, size);
});
Util.exec(callback);
}
function getSize() {
var wSubs = Element.offsetWidth - Element.clientWidth,
w = Element.clientWidth - wSubs,
hSubs = Element.offsetHeight - Element.clientHeight,
h = Element.clientHeight - hSubs,
x = Cell.clientWidth,
y = Cell.clientHeight,
cols = Math.max(Math.floor(w / x), 10),
rows = Math.max(Math.floor(h / y), 10),
size = {
cols: cols,
rows: rows
};
return size;
}
function onResize() {
var size = getSize(),
cols = size.cols,
rows = size.rows;
if (Size.cols !== cols || Size.rows !== rows) {
Size = size;
Term.emit('resize', size);
}
}
function afterShow(callback) {
Element.focus();
Terminal.brokenBold = true;
Util.exec(callback);
}
function load(callback) {
var dir = CloudCmd.LIBDIRCLIENT + 'terminal/',
path = dir + 'term.js';
Util.time(Name + ' load');
DOM.load.js(path, function() {
Util.timeEnd(Name + ' load');
Loading = false;
Util.exec(callback);
});
}
init();
}
})(CloudCmd, Util, DOM, CloudFunc);

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,6 @@
edward = require('edward'),
WIN = process.platform === 'WIN32',
terminal = !WIN ? require(DIR_SERVER + 'terminal') : function() {},
emptyFunc = function(req, res, next) {
next();
@ -59,7 +58,6 @@
socket: socket
});
terminal(socket);
config.socket(socket);
edward.listen(socket, {

View file

@ -1,108 +0,0 @@
(function() {
'use strict';
var DIR = __dirname + '/../../',
DIR_LIB = DIR + 'lib/',
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
tryRequire = require('tryrequire'),
pty = tryRequire('pty.js'),
Clients = [],
CHANNEL = CloudFunc.CHANNEL_TERMINAL,
CHANNEL_RESIZE = CloudFunc.CHANNEL_TERMINAL_RESIZE,
ConNum = 0;
module.exports = function(socket) {
Util.check(arguments, ['socket']);
if (pty)
socket
.of('/terminal')
.on('connection', function(socket) {
onConnection(socket, function(channel, data) {
socket.emit(channel, data);
});
});
};
function onConnection(socket, callback) {
var onDisconnect, resizeFunc, dataFunc, term;
++ConNum;
if (!Clients[ConNum]) {
log(ConNum, 'terminal connected');
term = getTerm(callback);
dataFunc = onData.bind(null, term);
resizeFunc = onResize.bind(null, term, callback);
onDisconnect = function(conNum, term) {
Clients[conNum] = null;
log(conNum, 'terminal disconnected');
socket.removeListener(CHANNEL, dataFunc);
socket.removeListener(CHANNEL_RESIZE, resizeFunc);
socket.removeListener('disconnect', onDisconnect);
term.destroy();
}.bind(null, ConNum, term);
socket.on(CHANNEL, dataFunc);
socket.on(CHANNEL_RESIZE, resizeFunc);
socket.on('disconnect', onDisconnect);
} else {
log(ConNum, ' in use. Reconnecting...\n');
socket.disconnect();
}
}
function onResize(term, callback, size) {
term.resize(size.cols, size.rows);
Util.exec(callback, CHANNEL_RESIZE, size);
}
function onData(term, data) {
term.write(data);
}
function getTerm(callback) {
var onData = Util.exec.bind(Util, callback, CHANNEL),
term = pty.spawn('bash', [], {
name: 'xterm-color',
cols: 80,
rows: 25,
cwd : DIR,
env : process.env
});
term.on('data', onData);
return term;
}
function log(pConnNum, pStr, pType) {
var lRet,
lType = ' ';
if (pStr) {
if (pType)
lType += pType + ':';
lRet = 'client #' + pConnNum + lType + pStr;
console.log(lRet);
}
return lRet;
}
})();