/****************** MONITOR *******************/ /* Monitor logger with single command line */ Monitors = [] Monitor = { index : 0, create : function (options) { var id = Monitor.index++; var monitor = { cell : 'MonitorWinOutput'+id, input : 'MonitorWinInput'+id, id : 'monitor'+id, index : id, } if (options.run) monitor.run=options.run; monitor.add = function (line,cls) { if (line[0]!='<') line=line.replace(/&/g,'&') .replace(//g,'>') .replace(/\n/g,'
'); var cell = $('#MonitorWinOutput'+id); var hline = $('',{ class:'', style:'width:100%;display:inline-block;'+(cls=='error'?'color:red;':cls=='warning'?'color:green;':'color:black;word-break: break-all;font-family: droidsansmonow01 , monospace !important;'), }); hline.html(line); hline.appendTo(cell); if (UI('MonitorWinLog'+id).scrollAuto) $('div[view_id="MonitorWinLog'+id+'"]').scrollTop(1000000) } monitor.clear = function () { var cell = $('#MonitorWinOutput'+id); cell.empty(); } function print() { var msg=Array.prototype.slice.call(arguments); function unwrap(str) { if (str[0]=='"'||str[0]=="'") return str.slice(1,str.length-1); return str; } if (msg.length==1) msg=msg[0]; else if (msg.length==0) msg='undefined'; else { msg=msg.map(inspect).map(unwrap).join(' '); } if (msg==undefined) msg='undefined'; if (typeof(msg) == 'object') { msg=inspect(msg); } msg=String(msg); monitor.add(msg!=undefined?msg:'undefined') } function printError() { var msg=Array.prototype.slice.call(arguments); function unwrap(str) { if (str[0]=='"'||str[0]=="'") return str.slice(1,str.length-1); return str; } if (msg.length==1) msg=msg[0]; else if (msg.length==0) msg='undefined'; else { msg=msg.map(inspect).map(unwrap).join(' '); } if (msg==undefined) msg='undefined'; if (typeof(msg) == 'object') { msg=inspect(msg); } msg=String(msg); monitor.add(msg,'error') } monitor.env = { clear:clear, print:print, error:printError, } monitor.print=print; monitor.error=printError; Monitors[id]=monitor; // Simple command line with history setTimeout(function () { var history = [], historyIndex = 0, command = $('#'+monitor.input), prefix = $('',{style:'font-weight:bold;'}), input = $('',{id:monitor.input+'-input',style:'padding-left:5px; width:80%;border:0px;'}); prefix.text(' >'); prefix.appendTo(command) input.appendTo(command); input.on('keydown',function (ev) { switch (ev.keyCode) { // Enter case 13: var line = input.val(); history.push(line); historyIndex=history.length; input.val(''); if (monitor.run) monitor.run(line,print,printError); break; // ArrowUp case 38: if (historyIndex>1) { input.val(history[historyIndex-1]); historyIndex--; } else if (historyIndex) input.val(history[historyIndex-1]); break; // ArrowDown case 40: if (historyIndex'), height:"auto", borderless:true}, {template:('
'), height:"auto", borderless:true}, ] } } }); UI('MonitorWinLog'+id).scrollAuto=true; window.show(); monitor.window=window; monitor.collapse=collapse; monitor.close = function () { window.close(); Monitor.exit(id); } monitor.setLabel = function (label) { UI('MonitorWinLabel'+id).setValue(label); } monitor.handlers=[]; monitor.on = function (ev,handler) { monitor.handlers[ev]=handler; } return monitor; } } UI.Monitor=Monitor;