mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-25 08:54:10 +00:00
refactor(console) outToTermina -> onMessage
This commit is contained in:
parent
f671238401
commit
a5a4ad98c1
1 changed files with 27 additions and 63 deletions
|
|
@ -2,16 +2,14 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
(function(CloudCmd, Util, DOM, CloudFunc) {
|
||||
'use strict';
|
||||
|
||||
var Buffer = {
|
||||
log : '',
|
||||
error : ''
|
||||
};
|
||||
|
||||
CloudCmd.Console = ConsoleProto;
|
||||
|
||||
function ConsoleProto(CallBack) {
|
||||
var Name = 'Console',
|
||||
Messages= [],
|
||||
Buffer = {
|
||||
log : '',
|
||||
error : ''
|
||||
},
|
||||
Loading,
|
||||
jqconsole,
|
||||
Element,
|
||||
|
|
@ -34,7 +32,11 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
]);
|
||||
}
|
||||
|
||||
this.show = function(callback) {
|
||||
this.show = show;
|
||||
this.log = log;
|
||||
this.error = error;
|
||||
|
||||
function show(callback) {
|
||||
if (!Loading) {
|
||||
Images.showLoad({top:true});
|
||||
|
||||
|
|
@ -101,24 +103,24 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
Util.exec(callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.log = function(pText) {
|
||||
log(pText, 'log');
|
||||
};
|
||||
function log(pText) {
|
||||
write(pText, 'log');
|
||||
}
|
||||
|
||||
this.error = function(pText) {
|
||||
log(pText, 'error');
|
||||
};
|
||||
function error(pText) {
|
||||
write(pText, 'error');
|
||||
}
|
||||
|
||||
function log(msg, status) {
|
||||
var ret;
|
||||
function write(msg, status) {
|
||||
var isContain;
|
||||
|
||||
if (msg) {
|
||||
Buffer[status] += msg;
|
||||
ret = Util.isContainStr(Buffer[status], '\n');
|
||||
isContain = Util.isContainStr(Buffer[status], '\n');
|
||||
|
||||
if (jqconsole && ret) {
|
||||
if (jqconsole && isContain) {
|
||||
jqconsole.Write(Buffer[status], status + '-msg');
|
||||
Notify.send(Buffer[status]);
|
||||
Buffer[status] = '';
|
||||
|
|
@ -149,57 +151,19 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
}
|
||||
|
||||
function addListeners(callback) {
|
||||
CloudCmd.Socket.on('message', function(msg) {
|
||||
var parsed = Util.parseJSON(msg);
|
||||
|
||||
outToTerminal(parsed);
|
||||
});
|
||||
CloudCmd.Socket.on('message', onMessage);
|
||||
|
||||
Util.exec(callback);
|
||||
}
|
||||
|
||||
function outToTerminal(pMsg) {
|
||||
var i, n, lResult, lStdout, lStderr,
|
||||
lConsole = CloudCmd.Console;
|
||||
function onMessage(json) {
|
||||
var msg = Util.parseJSON(json);
|
||||
|
||||
log(msg.stdout);
|
||||
error(msg.stderr);
|
||||
|
||||
DOM.Images.hideLoad();
|
||||
|
||||
if (Util.isObject(lConsole)) {
|
||||
if (Messages.length) {
|
||||
/* show oll msg from buffer */
|
||||
for (i = 0, n = Messages.length; i < n; i++) {
|
||||
lStdout = Messages[i].stdout;
|
||||
lStderr = Messages[i].stderr;
|
||||
|
||||
if (lStdout)
|
||||
lConsole.log(lStdout);
|
||||
|
||||
if (lStderr) {
|
||||
/* if it's object - convert is to string' */
|
||||
if (Util.isObject(lStderr))
|
||||
lStderr = Util.stringifyJSON(lStderr);
|
||||
|
||||
lConsole.error(lStderr);
|
||||
}
|
||||
}
|
||||
Messages = [];
|
||||
}
|
||||
|
||||
lStdout = pMsg.stdout;
|
||||
lStderr = pMsg.stderr;
|
||||
|
||||
if (lStdout)
|
||||
lResult = lConsole.log(lStdout);
|
||||
|
||||
if (lStderr)
|
||||
lResult = lConsole.error(lStderr);
|
||||
}
|
||||
else
|
||||
Messages.push(pMsg);
|
||||
|
||||
Util.log(pMsg);
|
||||
|
||||
return lResult;
|
||||
Util.log(msg);
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue