forked from Alex/Pterodactyl-Panel
37 lines
63 KiB
JavaScript
Executable File
37 lines
63 KiB
JavaScript
Executable File
/**@license
|
|
* __ _____ ________ __
|
|
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
|
|
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
|
|
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
|
|
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
|
|
* \/ /____/ version 0.11.6
|
|
*
|
|
* This file is part of jQuery Terminal. http://terminal.jcubic.pl
|
|
*
|
|
* Copyright (c) 2010-2016 Jakub Jankiewicz <http://jcubic.pl>
|
|
* Released under the MIT license
|
|
*
|
|
* Contains:
|
|
*
|
|
* Storage plugin Distributed under the MIT License
|
|
* Copyright (c) 2010 Dave Schindler
|
|
*
|
|
* jQuery Timers licenced with the WTFPL
|
|
* <http://jquery.offput.ca/timers/>
|
|
*
|
|
* Cross-Browser Split 1.1.1
|
|
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
|
|
* Available under the MIT License
|
|
*
|
|
* jQuery Caret
|
|
* Copyright (c) 2009, Gideon Sireling
|
|
* 3 clause BSD License
|
|
*
|
|
* sprintf.js
|
|
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
|
|
* licensed under 3 clause BSD license
|
|
*
|
|
* Date: Thu, 15 Sep 2016 20:19:15 +0000
|
|
*/
|
|
(function(e){var n=function(){if(!n.cache.hasOwnProperty(arguments[0])){n.cache[arguments[0]]=n.parse(arguments[0])}return n.format.call(null,n.cache[arguments[0]],arguments)};n.format=function(e,r){var o=1,a=e.length,s="",l,f=[],c,u,h,p,m,g;for(c=0;c<a;c++){s=t(e[c]);if(s==="string"){f.push(e[c])}else if(s==="array"){h=e[c];if(h[2]){l=r[o];for(u=0;u<h[2].length;u++){if(!l.hasOwnProperty(h[2][u])){throw n('[sprintf] property "%s" does not exist',h[2][u])}l=l[h[2][u]]}}else if(h[1]){l=r[h[1]]}else{l=r[o++]}if(/[^s]/.test(h[8])&&t(l)!="number"){throw n("[sprintf] expecting number but found %s",t(l))}switch(h[8]){case"b":l=l.toString(2);break;case"c":l=String.fromCharCode(l);break;case"d":l=parseInt(l,10);break;case"e":l=h[7]?l.toExponential(h[7]):l.toExponential();break;case"f":l=h[7]?parseFloat(l).toFixed(h[7]):parseFloat(l);break;case"o":l=l.toString(8);break;case"s":l=(l=String(l))&&h[7]?l.substring(0,h[7]):l;break;case"u":l=l>>>0;break;case"x":l=l.toString(16);break;case"X":l=l.toString(16).toUpperCase();break}l=/[def]/.test(h[8])&&h[3]&&l>=0?"+"+l:l;m=h[4]?h[4]=="0"?"0":h[4].charAt(1):" ";g=h[6]-String(l).length;p=h[6]?i(m,g):"";f.push(h[5]?l+p:p+l)}}return f.join("")};n.cache={};n.parse=function(e){var n=e,r=[],t=[],i=0;while(n){if((r=/^[^\x25]+/.exec(n))!==null){t.push(r[0])}else if((r=/^\x25{2}/.exec(n))!==null){t.push("%")}else if((r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(n))!==null){if(r[2]){i|=1;var o=[],a=r[2],s=[];if((s=/^([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1]);while((a=a.substring(s[0].length))!==""){if((s=/^\.([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1])}else if((s=/^\[(\d+)\]/.exec(a))!==null){o.push(s[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}r[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}t.push(r)}else{throw"[sprintf] huh?"}n=n.substring(r[0].length)}return t};var r=function(e,r,t){t=r.slice(0);t.splice(0,0,e);return n.apply(null,t)};function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,n){for(var r=[];n>0;r[--n]=e){}return r.join("")}e.sprintf=n;e.vsprintf=r})(typeof global!="undefined"?global:window);(function(e,n){"use strict";e.omap=function(n,r){var t={};e.each(n,function(e,i){t[e]=r.call(n,e,i)});return t};var r={clone_object:function(n){var r={};if(typeof n=="object"){if(e.isArray(n)){return this.clone_array(n)}else if(n===null){return n}else{for(var t in n){if(e.isArray(n[t])){r[t]=this.clone_array(n[t])}else if(typeof n[t]=="object"){r[t]=this.clone_object(n[t])}else{r[t]=n[t]}}}}return r},clone_array:function(n){if(!e.isFunction(Array.prototype.map)){throw new Error("You'r browser don't support ES5 array map "+"use es5-shim")}return n.slice(0).map(function(e){if(typeof e=="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var t=function(e){return r.clone_object(e)};var i=function(){var e="test",n=window.localStorage;try{n.setItem(e,"1");n.removeItem(e);return true}catch(r){return false}};var o=i();function a(e,n){var r;if(typeof e==="string"&&typeof n==="string"){localStorage[e]=n;return true}else if(typeof e==="object"&&typeof n==="undefined"){for(r in e){if(e.hasOwnProperty(r)){localStorage[r]=e[r]}}return true}return false}function s(e,n){var r,t,i;r=new Date;r.setTime(r.getTime()+31536e6);t="; expires="+r.toGMTString();if(typeof e==="string"&&typeof n==="string"){document.cookie=e+"="+n+t+"; path=/";return true}else if(typeof e==="object"&&typeof n==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+t+"; path=/"}}return true}return false}function l(e){return localStorage[e]}function f(e){var n,r,t,i;n=e+"=";r=document.cookie.split(";");for(t=0;t<r.length;t++){i=r[t];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(n)===0){return i.substring(n.length,i.length)}}return null}function c(e){return delete localStorage[e]}function u(e){return s(e,"",-1)}e.extend({Storage:{set:o?a:s,get:o?l:f,remove:o?c:u}});var h=e;h.fn.extend({everyTime:function(e,n,r,t,i){return this.each(function(){h.timer.add(this,e,n,r,t,i)})},oneTime:function(e,n,r){return this.each(function(){h.timer.add(this,e,n,r,1)})},stopTime:function(e,n){return this.each(function(){h.timer.remove(this,e,n)})}});h.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1e3,das:1e4,hs:1e5,ks:1e6},timeParse:function(e){if(e===n||e===null){return null}var r=this.regex.exec(h.trim(e.toString()));if(r[2]){var t=parseInt(r[1],10);var i=this.powers[r[2]]||1;return t*i}else{return e}},add:function(e,n,r,t,i,o){var a=0;if(h.isFunction(r)){if(!i){i=t}t=r;r=n}n=h.timer.timeParse(n);if(typeof n!=="number"||isNaN(n)||n<=0){return}if(i&&i.constructor!==Number){o=!!i;i=0}i=i||0;o=o||false;if(!e.$timers){e.$timers={}}if(!e.$timers[r]){e.$timers[r]={}}t.$timerID=t.$timerID||this.guid++;var s=function(){if(o&&s.inProgress){return}s.inProgress=true;if(++a>i&&i!==0||t.call(e,a)===false){h.timer.remove(e,r,t)}s.inProgress=false};s.$timerID=t.$timerID;if(!e.$timers[r][t.$timerID]){e.$timers[r][t.$timerID]=window.setInterval(s,n)}if(!this.global[r]){this.global[r]=[]}this.global[r].push(e)},remove:function(e,n,r){var t=e.$timers,i;if(t){if(!n){for(var o in t){if(t.hasOwnProperty(o)){this.remove(e,o,r)}}}else if(t[n]){if(r){if(r.$timerID){window.clearInterval(t[n][r.$timerID]);delete t[n][r.$timerID]}}else{for(var a in t[n]){if(t[n].hasOwnProperty(a)){window.clearInterval(t[n][a]);delete t[n][a]}}}for(i in t[n]){if(t[n].hasOwnProperty(i)){break}}if(!i){i=null;delete t[n]}}for(i in t){if(t.hasOwnProperty(i)){break}}if(!i){e.$timers=null}}}}});if(/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())){h(window).one("unload",function(){var e=h.timer.global;for(var n in e){if(e.hasOwnProperty(n)){var r=e[n],t=r.length;while(--t){h.timer.remove(r[t],n)}}}})}(function(e){if(!String.prototype.split.toString().match(/\[native/)){return}var n=String.prototype.split,r=/()??/.exec("")[1]===e,t;t=function(t,i,o){if(Object.prototype.toString.call(i)!=="[object RegExp]"){return n.call(t,i,o)}var a=[],s=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.extended?"x":"")+(i.sticky?"y":""),l=0,f,c,u,h;i=new RegExp(i.source,s+"g");t+="";if(!r){f=new RegExp("^"+i.source+"$(?!\\s)",s)}o=o===e?-1>>>0:o>>>0;while(c=i.exec(t)){u=c.index+c[0].length;if(u>l){a.push(t.slice(l,c.index));if(!r&&c.length>1){c[0].replace(f,function(){for(var n=1;n<arguments.length-2;n++){if(arguments[n]===e){c[n]=e}}})}if(c.length>1&&c.index<t.length){Array.prototype.push.apply(a,c.slice(1))}h=c[0].length;l=u;if(a.length>=o){break}}if(i.lastIndex===c.index){i.lastIndex++}}if(l===t.length){if(h||!i.test("")){a.push("")}}else{a.push(t.slice(l))}return a.length>o?a.slice(0,o):a};String.prototype.split=function(e,n){return t(this,e,n)};return t})();e.fn.caret=function(e){var n=this[0];var r=n.contentEditable==="true";if(arguments.length==0){if(window.getSelection){if(r){n.focus();var t=window.getSelection().getRangeAt(0),i=t.cloneRange();i.selectNodeContents(n);i.setEnd(t.endContainer,t.endOffset);return i.toString().length}return n.selectionStart}if(document.selection){n.focus();if(r){var t=document.selection.createRange(),i=document.body.createTextRange();i.moveToElementText(n);i.setEndPoint("EndToEnd",t);return i.text.length}var e=0,o=n.createTextRange(),i=document.selection.createRange().duplicate(),a=i.getBookmark();o.moveToBookmark(a);while(o.moveStart("character",-1)!==0)e++;return e}return 0}if(e==-1)e=this[r?"text":"val"]().length;if(window.getSelection){if(r){n.focus();window.getSelection().collapse(n.firstChild,e)}else n.setSelectionRange(e,e)}else if(document.body.createTextRange){var o=document.body.createTextRange();o.moveToElementText(n);o.moveStart("character",e);o.collapse(true);o.select()}if(!r)n.focus();return e};function p(e,n){var r=[];var t=e.length;if(t<n){return[e]}else if(n<0){throw new Error("str_parts: length can't be negative")}for(var i=0;i<t;i+=n){r.push(e.substring(i,i+n))}return r}function m(n){var r=n?[n]:[];var t=0;e.extend(this,{get:function(){return r},rotate:function(){if(!r.filter(Boolean).length){return}if(r.length===1){return r[0]}else{if(t===r.length-1){t=0}else{++t}if(r[t]){return r[t]}else{return this.rotate()}}},length:function(){return r.length},remove:function(e){delete r[e]},set:function(e){for(var n=r.length;n--;){if(r[n]===e){t=n;return}}this.append(e)},front:function(){if(r.length){var e=t;var n=false;while(!r[e]){e++;if(e>r.length){if(n){break}e=0;n=true}}return r[e]}},append:function(e){r.push(e)}})}function g(n){var r=n instanceof Array?n:n?[n]:[];e.extend(this,{data:function(){return r},map:function(n){return e.map(r,n)},size:function(){return r.length},pop:function(){if(r.length===0){return null}else{var e=r[r.length-1];r=r.slice(0,r.length-1);return e}},push:function(e){r=r.concat([e]);return e},top:function(){return r.length>0?r[r.length-1]:null},clone:function(){return new g(r.slice(0))}})}e.json_stringify=function(r,t){var i="",o;t=t===n?1:t;var a=typeof r;switch(a){case"function":i+=r;break;case"boolean":i+=r?"true":"false";break;case"object":if(r===null){i+="null"}else if(r instanceof Array){i+="[";var s=r.length;for(o=0;o<s-1;++o){i+=e.json_stringify(r[o],t+1)}i+=e.json_stringify(r[s-1],t+1)+"]"}else{i+="{";for(var l in r){if(r.hasOwnProperty(l)){i+='"'+l+'":'+e.json_stringify(r[l],t+1)}}i+="}"}break;case"string":var f=r;var c={"\\\\":"\\\\",'"':'\\"',"/":"\\/","\\n":"\\n","\\r":"\\r","\\t":"\\t"};for(o in c){if(c.hasOwnProperty(o)){f=f.replace(new RegExp(o,"g"),c[o])}}i+='"'+f+'"';break;case"number":i+=String(r);break}i+=t>1?",":"";if(t===1){i=i.replace(/,([\]}])/g,"$1")}return i.replace(/([\[{]),/g,"$1")};function d(n,r){var t=true;var i="";if(typeof n==="string"&&n!==""){i=n+"_"}i+="commands";var o=e.Storage.get(i);o=o?e.parseJSON(o):[];var a=o.length-1;e.extend(this,{append:function(n){if(t){if(o[o.length-1]!==n){o.push(n);if(r&&o.length>r){o=o.slice(-r)}a=o.length-1;e.Storage.set(i,e.json_stringify(o))}}},data:function(){return o},reset:function(){a=o.length-1},last:function(){return o[length-1]},end:function(){return a===o.length-1},position:function(){return a},current:function(){return o[a]},next:function(){if(a<o.length-1){++a}if(a!==-1){return o[a]}},previous:function(){var e=a;if(a>0){--a}if(e!==-1){return o[a]}},clear:function(){o=[];this.purge()},enabled:function(){return t},enable:function(){t=true},purge:function(){e.Storage.remove(i)},disable:function(){t=false}})}var v=function(){var e=document.createElement("div");e.setAttribute("onpaste","return;");return typeof e.onpaste=="function"}();var y=true;e.fn.cmd=function(r){var t=this;var i=t.data("cmd");if(i){return i}t.addClass("cmd");t.append('<span class="prompt"></span><span></span>'+'<span class="cursor"> </span><span></span>');var o=e("<textarea>").addClass("clipboard").appendTo(t);if(r.width){t.width(r.width)}var a;var s;var l=t.find(".prompt");var f=false;var c="";var u=null;var h;var m=r.mask||false;var g="";var y;var _="";var w="";var C=0;var S;var T;var F=r.historySize||60;var A,j;var E=t.find(".cursor");var R;var $=0;function I(){var e=o.is(":focus");if(T){if(!e){o.focus();t.oneTime(10,function(){o.focus()})}}else{if(e){o.blur()}}}function z(){if(x){t.oneTime(10,function(){o.val(g);t.oneTime(10,function(){o.caret(C)})})}}if(b&&!k){R=function(e){if(e){E.addClass("blink")}else{E.removeClass("blink")}}}else{var O=false;R=function(e){if(e&&!O){O=true;E.addClass("inverted blink");t.everyTime(500,"blink",K)}else if(O&&!e){O=false;t.stopTime("blink",K);E.removeClass("inverted blink")}}}function K(e){E.toggleClass("inverted")}function N(){S="(reverse-i-search)`"+c+"': ";q()}function P(){S=h;f=false;u=null;c=""}function L(n){var r=j.data();var i,o;var a=r.length;if(n&&u>0){a-=u}if(c.length>0){for(var s=c.length;s>0;s--){o=e.terminal.escape_regex(c.substring(0,s));i=new RegExp(o);for(var l=a;l--;){if(i.test(r[l])){u=r.length-l;t.position(r[l].indexOf(o));t.set(r[l],true);H();if(c.length!==s){c=c.substring(0,s);N()}return}}}}c=""}function D(){var e=t.width();var n=E[0].getBoundingClientRect().width;a=Math.floor(e/n)}function B(e){var n=e.substring(0,a-s);var r=e.substring(a-s);return[n].concat(p(r,a))}var H=function(n){var r=E.prev();var t=E.next();function i(n,i){var o=n.length;if(i===o){r.html(e.terminal.encode(n));E.html(" ");t.html("")}else if(i===0){r.html("");E.html(e.terminal.encode(n.slice(0,1)));t.html(e.terminal.encode(n.slice(1)))}else{var a=n.slice(0,i);r.html(e.terminal.encode(a));var s=n.slice(i,i+1);E.html(e.terminal.encode(s));if(i===n.length-1){t.html("")}else{t.html(e.terminal.encode(n.slice(i+1)))}}}function o(n){return"<div>"+e.terminal.encode(n)+"</div>"}function l(n){var r=t;e.each(n,function(n,t){r=e(o(t)).insertAfter(r).addClass("clear")})}function f(n){e.each(n,function(e,n){r.before(o(n))})}var c=0;return function(){var c;var u;switch(typeof m){case"boolean":c=m?g.replace(/./g,"*"):g;break;case"string":c=g.replace(/./g,m);break}var h,d;n.find("div").remove();r.html("");if(c.length>a-s-1||c.match(/\n/)){var v;var y=c.match(/\t/g);var _=y?y.length*3:0;if(y){c=c.replace(/\t/g,"\x00\x00\x00\x00")}if(c.match(/\n/)){var w=c.split("\n");d=a-s-1;for(h=0;h<w.length-1;++h){w[h]+=" "}if(w[0].length>d){v=[w[0].substring(0,d)];u=w[0].substring(d);v=v.concat(p(u,a))}else{v=[w[0]]}for(h=1;h<w.length;++h){if(w[h].length>a){v=v.concat(p(w[h],a))}else{v.push(w[h])}}}else{v=B(c)}if(y){v=e.map(v,function(e){return e.replace(/\x00\x00\x00\x00/g," ")})}d=v[0].length;if(d===0&&v.length===1){}else if(C<d){i(v[0],C);l(v.slice(1))}else if(C===d){r.before(o(v[0]));i(v[1],0);l(v.slice(2))}else{var b=v.length;var k=0;if(C<d){i(v[0],C);l(v.slice(1))}else if(C===d){r.before(o(v[0]));i(v[1],0);l(v.slice(2))}else{var x=v.slice(-1)[0];var S=c.length-C-_;var T=x.length;var F=0;if(S<=T){f(v.slice(0,-1));if(T===S){F=0}else{F=T-S}i(x,F)}else{if(b===3){u=e.terminal.encode(v[0]);r.before("<div>"+u+"</div>");i(v[1],C-d-1);u=e.terminal.encode(v[2]);t.after('<div class="clear">'+u+"</div>")}else{var A;var j;F=C;for(h=0;h<v.length;++h){var R=v[h].length;if(F>R){F-=R}else{break}}j=v[h];A=h;if(F===j.length){F=0;j=v[++A]}i(j,F);f(v.slice(0,A));l(v.slice(A+1))}}}}}else{if(c===""){r.html("");E.html(" ");t.html("")}else{i(c,C)}}}}(t);var q=function(){function n(n){l.html(e.terminal.format(e.terminal.encode(n)));s=l.text().length}return function(){switch(typeof S){case"string":n(S);break;case"function":S(n);break}}}();function J(e){if($++>0){return}if(e.originalEvent){e=e.originalEvent}if(t.isenabled()){var n=t.find("textarea");if(!n.is(":focus")){n.focus()}t.oneTime(100,function(){t.insert(n.val());n.val("");z()})}}var M=true;var U=false;var Y;function G(i){var a,s,l;if(T){if(e.isFunction(r.keydown)){a=r.keydown(i);if(a!==n){return a}}if(i.which!==38&&!(i.which===80&&i.ctrlKey)){M=true}if(f&&(i.which===35||i.which===36||i.which===37||i.which===38||i.which===39||i.which===40||i.which===13||i.which===27)){P();q();if(i.which===27){t.set("")}H();G.call(this,i)}else if(i.altKey){if(i.which===68){t.set(g.slice(0,C)+g.slice(C).replace(/ *[^ ]+ *(?= )|[^ ]+$/,""),true);return false}return true}else if(i.keyCode===13){if(i.shiftKey){t.insert("\n")}else{if(j&&g&&!m&&(e.isFunction(r.historyFilter)&&r.historyFilter(g))||r.historyFilter instanceof RegExp&&g.match(r.historyFilter)||!r.historyFilter){j.append(g)}var u=g;j.reset();t.set("");if(r.commands){r.commands(u)}if(e.isFunction(S)){q()}}}else if(i.which===8){if(f){c=c.slice(0,-1);N()}else{if(g!==""&&C>0){t["delete"](-1)}}if(x){return true}}else if(i.which===67&&i.ctrlKey&&i.shiftKey){_=W()}else if(i.which===86&&i.ctrlKey&&i.shiftKey){if(_!==""){t.insert(_)}}else if(i.which===9&&!(i.ctrlKey||i.altKey)){t.insert(" ")}else if(i.which===46){t["delete"](1);return}else if(j&&(i.which===38&&!i.ctrlKey)||i.which===80&&i.ctrlKey){if(M){y=g;t.set(j.current())}else{t.set(j.previous())}M=false}else if(j&&(i.which===40&&!i.ctrlKey)||i.which===78&&i.ctrlKey){t.set(j.end()?y:j.next())}else if(i.which===37||i.which===66&&i.ctrlKey){if(i.ctrlKey&&i.which!==66){l=C-1;s=0;if(g[l]===" "){--l}for(var p=l;p>0;--p){if(g[p]===" "&&g[p+1]!==" "){s=p+1;break}else if(g[p]==="\n"&&g[p+1]!=="\n"){s=p;break}}t.position(s)}else{if(C>0){t.position(-1,true);H()}}}else if(i.which===82&&i.ctrlKey){if(f){L(true)}else{h=S;N();y=g;t.set("");H();f=true}}else if(i.which==71&&i.ctrlKey){if(f){S=h;q();t.set(y);H();f=false;c=""}}else if(i.which===39||i.which===70&&i.ctrlKey){if(i.ctrlKey&&i.which!==70){if(g[C]===" "){++C}var d=/\S[\n\s]{2,}|[\n\s]+\S?/;var b=g.slice(C).match(d);if(!b||b[0].match(/^\s+$/)){t.position(g.length)}else{if(b[0][0]!==" "){C+=b.index+1}else{C+=b.index+b[0].length-1;if(b[0][b[0].length-1]!==" "){--C}}}H()}else{if(C<g.length){t.position(1,true)}}}else if(i.which===123){return}else if(i.which===36){t.position(0)}else if(i.which===35){t.position(g.length)}else if(i.shiftKey&&i.which==45){o.val("");$=0;if(!v){J(i)}else{o.focus()}return}else if(i.ctrlKey||i.metaKey){if(i.which===192){return}if(i.metaKey){if(i.which===82){return}else if(i.which===76){return}}if(i.shiftKey){if(i.which===84){return}}else{if(i.which===81){if(g!==""&&C!==0){var k=g.slice(0,C).match(/([^ ]+ *$)/);w=t["delete"](-k[0].length)}return false}else if(i.which===72){if(g!==""&&C>0){t["delete"](-1)}return false}else if(i.which===65){t.position(0)}else if(i.which===69){t.position(g.length)}else if(i.which===88||i.which===67||i.which===84){return}else if(i.which===89){if(w!==""){t.insert(w)}}else if(i.which===86||i.which===118){o.val("");$=0;if(!v){J(i)}else{o.focus();o.on("input",function F(e){J(e);o.off("input",F)})}return}else if(i.which===75){w=t["delete"](g.length-C)}else if(i.which===85){if(g!==""&&C!==0){w=t["delete"](-C)}}else if(i.which===17){return false}}}else{U=false;Y=true;return}i.preventDefault()}}function Q(){if(e.isFunction(r.onCommandChange)){r.onCommandChange(g)}}e.extend(t,{name:function(e){if(e!==n){A=e;var r=j&&j.enabled()||!j;j=new d(e,F);if(!r){j.disable()}return t}else{return A}},purge:function(){j.clear();return t},history:function(){return j},"delete":function(e,n){var r;if(e===0){return t}else if(e<0){if(C>0){r=g.slice(0,C).slice(e);g=g.slice(0,C+e)+g.slice(C,g.length);if(!n){t.position(C+e)}else{Q()}}}else{if(g!==""&&C<g.length){r=g.slice(C).slice(0,e);g=g.slice(0,C)+g.slice(C+e,g.length);Q()}}H();z();return r},set:function(e,r){if(e!==n){g=e;if(!r){t.position(g.length)}H();z();Q()}return t},insert:function(e,n){if(C===g.length){g+=e}else if(C===0){g=e+g}else{g=g.slice(0,C)+e+g.slice(C)}if(!n){t.position(e.length,true)}else{z()}H();Q();return t},get:function(){return g},commands:function(e){if(e){r.commands=e;return t}else{return e}},destroy:function(){Z.unbind("keypress.cmd",V);Z.unbind("keydown.cmd",G);Z.unbind("paste.cmd",J);Z.unbind("input.cmd",en);t.stopTime("blink",K);t.find(".cursor").next().remove().end().prev().remove().end().remove();t.find(".prompt, .clipboard").remove();t.removeClass("cmd").removeData("cmd");return t},prompt:function(e){if(e===n){return S}else{if(typeof e==="string"||typeof e==="function"){S=e}else{throw new Error("prompt must be a function or string")}q();H();return t}},kill_text:function(){return w},position:function(n,i){if(typeof n==="number"){if(i){C+=n}else{if(n<0){C=0}else if(n>g.length){C=g.length}else{C=n}}if(e.isFunction(r.onPositionChange)){r.onPositionChange(C)}H();z();return t}else{return C}},visible:function(){var e=t.visible;return function(){e.apply(t,[]);H();q()}}(),show:function(){var e=t.show;return function(){e.apply(t,[]);H();q()}}(),resize:function(e){if(e){a=e}else{D()}H();return t},enable:function(){T=true;t.addClass("enabled");R(true);I();return t},isenabled:function(){return T},disable:function(){T=false;t.removeClass("enabled");R(false);I();return t},mask:function(e){if(typeof e==="undefined"){return m}else{m=e;H();return t}}});t.name(r.name||r.prompt||"");if(typeof r.prompt=="string"){S=r.prompt}else{S="> "}q();if(r.enabled===n||r.enabled===true){t.enable()}var X;var Z=e(document.documentElement||window);function V(i){var o;Y=false;if((i.ctrlKey||i.metaKey)&&[99,118,86].indexOf(i.which)!==-1){return}if(U){return}if(!f&&e.isFunction(r.keypress)){o=r.keypress(i)}if(o===n||o){if(T){if(e.inArray(i.which,[38,13,0,8])>-1&&!(i.which===38&&i.shiftKey)){if(i.keyCode==123){return}return false}else if(!i.ctrlKey&&!(i.altKey&&i.which===100)||i.altKey){if(f){c+=String.fromCharCode(i.which);L();N()}else{t.insert(String.fromCharCode(i.which))}return false}}}else{return o}}function en(e){if(Y){var n=o.val();if(n||e.which==8){t.set(n)}}}Z.bind("keypress.cmd",V).bind("keydown.cmd",G).bind("input.cmd",en);t.data("cmd",t);return t};function _(n){return e("<div>"+e.terminal.strip(n)+"</div>").text().length}function w(e){return e.length-_(e)}var b=function(){var e=false,r="animation",t="",i="Webkit Moz O ms Khtml".split(" "),o="",a=document.createElement("div");if(a.style.animationName){e=true}if(e===false){for(var s=0;s<i.length;s++){var l=i[s]+"AnimationName";if(a.style[l]!==n){o=i[s];r=o+"Animation";t="-"+o.toLowerCase()+"-";e=true;break}}}return e}();var k=navigator.userAgent.toLowerCase().indexOf("android")!=-1;var x=function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch}();function C(n,r){var t=r(n);if(t.length){var i=t.shift();var o=new RegExp("^"+e.terminal.escape_regex(i));var a=n.replace(o,"").trim();return{command:n,name:i,args:t,rest:a}}else{return{command:n,name:"",args:[],rest:""}}}var S=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?)/i;var T=/\[\[([!gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var F=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var A=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]/gi;var j=/^\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]$/gi;var E=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;var R=/(\bhttps?:\/\/(?:(?:(?!&[^;]+;)|(?=&))[^\s"'<>\]\[)])+\b)/gi;var $=/\b(https?:\/\/(?:(?:(?!&[^;]+;)|(?=&))[^\s"'<>\][)])+)\b(?![^[\]]*])/gi;var I=/((([^<>('")[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})))/g;var z=/('[^']*'|"(\\"|[^"])*"|(?:\/(\\\/|[^\/])+\/[gimy]*)(?=:? |$)|(\\ |[^ ])+|[\w-]+)/gi;var O=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var K=/^(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var N=/\[\[[!gbiuso]*;[^;]*;[^\]]*\]?$/i;var P=/(\[\[(?:[^\]]|\\\])*\]\])/;e.terminal={version:"0.11.6",color_names:["black","silver","gray","white","maroon","red","purple","fuchsia","green","lime","olive","yellow","navy","blue","teal","aqua","aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"],valid_color:function(n){if(n.match(E)){return true}else{return e.inArray(n.toLowerCase(),e.terminal.color_names)!==-1}},escape_regex:function(e){if(typeof e=="string"){var n=/([-\\\^$\[\]()+{}?*.|])/g;return e.replace(n,"\\$1")}},have_formatting:function(e){return typeof e=="string"&&!!e.match(A)},is_formatting:function(e){return typeof e=="string"&&!!e.match(j)},format_split:function(e){return e.split(S)},split_equal:function(n,r,t){var i=false;var o=false;var a="";var s=[];var l=n.replace(F,function(e,n,r){var t=n.match(/;/g).length;if(t>=4){return e}else if(t==2){t=";;"}else if(t==3){t=";"}else{t=""}var i=r.replace(/\\\]/g,"]").replace(/\n/g,"\\n").replace(/ /g," ");return"[["+n+t+i+"]"+r+"]"}).split(/\n/g);function f(){return h.substring(d-6,d)==" "||h.substring(d-1,d)==" "}for(var c=0,u=l.length;c<u;++c){if(l[c]===""){s.push("");continue}var h=l[c];var p=0;var m=0;var g=-1;for(var d=0,v=h.length;d<v;++d){if(h.substring(d).match(K)){i=true;o=false}else if(i&&h[d]==="]"){if(o){i=false;o=false}else{o=true}}else if(i&&o||!i){if(h[d]==="&"){var y=h.substring(d).match(/^(&[^;]+;)/);if(!y){throw new Error("Unclosed html entity in line "+(c+1)+" at char "+(d+1))}d+=y[1].length-2;if(d===v-1){s.push(_+y[1])}continue}else if(h[d]==="]"&&h[d-1]==="\\"){--m}else{++m}}if(f()&&(i&&o||!i||h[d]==="["&&h[d+1]==="[")){g=d}if((m===r||d===v-1)&&(i&&o||!i)){var _;var w=e.terminal.strip(h.substring(g));w=e("<span>"+w+"</span>").text();var b=w.length;w=w.substring(0,d+r+1);var k=!!w.match(/\s/)||d+r+1>b;if(t&&g!=-1&&d!==v-1&&k){_=h.substring(p,g);d=g-1}else{_=h.substring(p,d+1)}if(t){_=_.replace(/( |\s)+$/g,"")}g=-1;p=d+1;m=0;if(a){_=a+_;if(_.match("]")){a=""}}var x=_.match(F);if(x){var C=x[x.length-1];if(C[C.length-1]!=="]"){a=C.match(O)[1];_+="]"}else if(_.match(N)){var S=_.length;_=_.replace(N,"");a=C.match(O)[1]}}s.push(_)}}}return s},encode:function(e){e=e.replace(/&(?!#[0-9]+;|[a-zA-Z]+;)/g,"&");return e.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/\t/g," ")},escape_formatting:function(n){return e.terminal.escape_brackets(e.terminal.encode(n))},format:function(n,r){var t=e.extend({},{linksNoReferrer:false},r||{});if(typeof n==="string"){var i=e.terminal.format_split(n);n=e.map(i,function(n){if(n===""){return n}else if(e.terminal.is_formatting(n)){n=n.replace(/\[\[[^\]]+\]/,function(e){return e.replace(/ /g," ")});return n.replace(T,function(n,r,i,o,a,s,l){if(l===""){return""}l=l.replace(/\\]/g,"]");var f="";if(r.indexOf("b")!==-1){f+="font-weight:bold;"}var c=[];if(r.indexOf("u")!==-1){c.push("underline")}if(r.indexOf("s")!==-1){c.push("line-through")}if(r.indexOf("o")!==-1){c.push("overline")}if(c.length){f+="text-decoration:"+c.join(" ")+";"}if(r.indexOf("i")!==-1){f+="font-style:italic;"}if(e.terminal.valid_color(i)){f+="color:"+i+";";if(r.indexOf("g")!==-1){f+="text-shadow:0 0 5px "+i+";"}}if(e.terminal.valid_color(o)){f+="background-color:"+o}var u;if(s===""){u=l}else{u=s.replace(/]/g,"]")}var h;if(r.indexOf("!")!==-1){if(u.match(I)){h='<a href="mailto:'+u+'" '}else{h='<a target="_blank" href="'+u+'" ';if(t.linksNoReferrer){h+='rel="noreferrer" '}}}else{h="<span"}if(f!==""){h+=' style="'+f+'"'}if(a!==""){h+=' class="'+a+'"'}if(r.indexOf("!")!==-1){h+=">"+l+"</a>"}else{h+=' data-text="'+u.replace('"',""e;")+'">'+l+"</span>"}return h})}else{return"<span>"+n.replace(/\\\]/g,"]")+"</span>"}}).join("");return n.replace(/<span><br\s*\/?><\/span>/gi,"<br/>")}else{return""}},escape_brackets:function(e){return e.replace(/\[/g,"[").replace(/\]/g,"]")},strip:function(e){return e.replace(T,"$6")},active:function(){return Z.front()},last_id:function(){var e=Z.length();if(e){return e-1}},parseArguments:function(n){return e.terminal.parse_arguments(n)},splitArguments:function(n){return e.terminal.split_arguments(n)},parseCommand:function(n){return e.terminal.parse_command(n)},splitCommand:function(n){return e.terminal.split_command(n)},parse_arguments:function(n){var r=/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/;return e.map(n.match(z)||[],function(e){if(e[0]==="'"&&e[e.length-1]==="'"){return e.replace(/^'|'$/g,"")}else if(e[0]==='"'&&e[e.length-1]==='"'){e=e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1");return e.replace(/\\\\|\\t|\\n/g,function(e){if(e[1]==="t"){return" "}else if(e[1]==="n"){return"\n"}else{return"\\"}}).replace(/\\x([0-9a-f]+)/gi,function(e,n){return String.fromCharCode(parseInt(n,16))}).replace(/\\0([0-7]+)/g,function(e,n){return String.fromCharCode(parseInt(n,8))})}else if(e.match(/^\/(\\\/|[^\/])+\/[gimy]*$/)){var n=e.match(/^\/([^\/]+)\/([^\/]*)$/);return new RegExp(n[1],n[2])}else if(e.match(/^-?[0-9]+$/)){return parseInt(e,10)}else if(e.match(r)){return parseFloat(e)}else{return e.replace(/\\ /g," ")}})},split_arguments:function(n){return e.map(n.match(z)||[],function(e){if(e[0]==="'"&&e[e.length-1]==="'"){return e.replace(/^'|'$/g,"")}else if(e[0]==='"'&&e[e.length-1]==='"'){return e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1")}else if(e.match(/\/.*\/[gimy]*$/)){return e}else{return e.replace(/\\ /g," ")}})},parse_command:function(n){return C(n,e.terminal.parse_arguments)},split_command:function(n){return C(n,e.terminal.split_arguments)},extended_command:function(e,n){try{nn=false;e.exec(n,true).then(function(){nn=true})}catch(r){}}};e.fn.visible=function(){return this.css("visibility","visible")};e.fn.hidden=function(){return this.css("visibility","hidden")};var L={};e.jrpc=function(n,r,t,i,o){L[n]=L[n]||0;var a=e.json_stringify({jsonrpc:"2.0",method:r,params:t,id:++L[n]});return e.ajax({url:n,data:a,success:function(n,r,t){var a=t.getResponseHeader("Content-Type");if(!a.match(/application\/json/)){var s="Response Content-Type is not application/json";if(console&&console.warn){console.warn(s)}else{throw new Error("WARN: "+s)}}var l;try{l=e.parseJSON(n)}catch(f){if(o){o(t,"Invalid JSON",f)}else{throw new Error("Invalid JSON")}return}i(l,r,t)},error:o,contentType:"application/json",dataType:"text",async:true,cache:false,type:"POST"})};function D(){var n=e('<div class="terminal temp"><div class="cmd"><span cla'+'ss="cursor"> </span></div></div>').appendTo("body");var r=n.find("span");var t={width:r.width(),height:r.outerHeight()};n.remove();return t}function B(n){var r=e('<div class="terminal wrap"><span class="cursor">'+" </span></div>").appendTo("body").css("padding",0);var t=r.find("span");var i=t[0].getBoundingClientRect().width;var o=Math.floor(n.width()/i);r.remove();if(q(n)){var a=20;var s=n.innerWidth()-n.width();o-=Math.ceil((a-s/2)/(i-1))}return o}function H(e){return Math.floor(e.height()/D().height)}function W(){if(window.getSelection||document.getSelection){var e=(window.getSelection||document.getSelection)();if(e.text){return e.text}else{return e.toString()}}else if(document.selection){return document.selection.createRange().text}}function q(n){if(n.css("overflow")=="scroll"||n.css("overflow-y")=="scroll"){return true}else if(n.is("body")){return e("body").height()>e(window).height()}else{return n.get(0).scrollHeight>n.innerHeight()}}var J=!e.terminal.version.match(/^\{\{/);var M="Copyright (c) 2011-2016 Jakub Jankiewicz <http://jcubic"+".pl>";var U=J?" v. "+e.terminal.version:" ";var Y=new RegExp(" {"+U.length+"}$");var G="jQuery Terminal Emulator"+(J?U:"");var Q=[["jQuery Terminal","(c) 2011-2016 jcubic"],[G,M.replace(/^Copyright | *<.*>/g,"")],[G,M.replace(/^Copyright /,"")],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/_/_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(Y," ")+U,M],[" __ _____ ________ __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ \\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // / /__","\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\__\\_\\___/"," \\/ /____/ ".replace(Y,"")+U,M]];
|
|
e.terminal.defaults={prompt:"> ",history:true,exit:true,clear:true,enabled:true,historySize:60,maskChar:"*",checkArity:true,raw:false,exceptionHandler:null,cancelableAjax:true,processArguments:true,linksNoReferrer:false,processRPCResponse:null,Token:true,convertLinks:true,historyState:false,echoCommand:true,login:null,outputLimit:-1,formatters:[],onAjaxError:null,onRPCError:null,completion:false,historyFilter:null,onInit:e.noop,onClear:e.noop,onBlur:e.noop,onFocus:e.noop,onTerminalChange:e.noop,onExit:e.noop,keypress:e.noop,keydown:e.noop,strings:{wrongPasswordTryAgain:"Wrong password try again!",wrongPassword:"Wrong password!",ajaxAbortError:"Error while aborting ajax call!",wrongArity:"Wrong number of arguments. Function '%s' expects %s got"+" %s!",commandNotFound:"Command '%s' Not Found!",oneRPCWithIgnore:"You can use only one rpc with ignoreSystemDescr"+"ibe",oneInterpreterFunction:"You can't use more than one function (rpc"+"with ignoreSystemDescribe counts as one)",loginFunctionMissing:"You didn't specify a login function",noTokenError:"Access denied (no token)",serverResponse:"Server responded",wrongGreetings:"Wrong value of greetings parameter",notWhileLogin:"You can't call `%s' function while in login",loginIsNotAFunction:"Authenticate must be a function",canExitError:"You can't exit from main interpreter",invalidCompletion:"Invalid completion",invalidSelector:'Sorry, but terminal said that "%s" is not valid '+"selector!",invalidTerminalId:"Invalid Terminal ID",login:"login",password:"password",recursiveCall:"Recursive call detected, skip"}};var X=[];var Z=new m;var V=[];var en;var nn=false;var rn=true;var tn=true;var on;e.fn.terminal=function(r,i){function o(n){if(e.isFunction(Fn.processArguments)){return C(n,Fn.processArguments)}else if(Fn.processArguments){return e.terminal.parse_command(n)}else{return e.terminal.split_command(n)}}function a(n){if(typeof n==="string"){ln.echo(n)}else if(n instanceof Array){ln.echo(e.map(n,function(n){return e.json_stringify(n)}).join(" "))}else if(typeof n==="object"){ln.echo(e.json_stringify(n))}else{ln.echo(n)}}function s(n){var r=/(.*):([0-9]+):([0-9]+)$/;var t=n.match(r);if(t){ln.pause();e.get(t[1],function(n){var r=location.href.replace(/[^\/]+$/,"");var i=t[1].replace(r,"");ln.echo("[[b;white;]"+i+"]");var o=n.split("\n");var a=+t[2]-1;ln.echo(o.slice(a-2,a+3).map(function(n,r){if(r==2){n="[[;#f00;]"+e.terminal.escape_brackets(n)+"]"}return"["+(a+r)+"]: "+n}).join("\n")).resume()},"text")}}function l(n){if(e.isFunction(Fn.onRPCError)){Fn.onRPCError.call(ln,n)}else{ln.error("[RPC] "+n.message);if(n.error&&n.error.message){n=n.error;var r=" "+n.message;if(n.file){r+=' in file "'+n.file.replace(/.*\//,"")+'"'}if(n.at){r+=" at line "+n.at}ln.error(r)}}}function f(n,r){var t=function(r,t){ln.pause();e.jrpc(n,r,t,function(n){if(n.error){l(n.error)}else{if(e.isFunction(Fn.processRPCResponse)){Fn.processRPCResponse.call(ln,n.result,ln)}else{a(n.result)}}ln.resume()},u)};return function(e,n){if(e===""){return}try{e=o(e)}catch(i){n.error(i.toString());return}if(!r||e.name==="help"){t(e.name,e.args)}else{var a=n.token();if(a){t(e.name,[a].concat(e.args))}else{n.error("[AUTH] "+An.noTokenError)}}}}function c(r,t,i,a){return function(s,l){if(s===""){return}var f;try{f=o(s)}catch(u){ln.error(u.toString());return}var h=r[f.name];var p=e.type(h);if(p==="function"){if(t&&h.length!==f.args.length){ln.error("[Arity] "+sprintf(An.wrongArity,f.name,h.length,f.args.length))}else{return h.apply(ln,f.args)}}else if(p==="object"||p==="string"){var m=[];if(p==="object"){m=Object.keys(h);h=c(h,t,i)}l.push(h,{prompt:f.name+"> ",name:f.name,completion:p==="object"?m:n})}else{if(e.isFunction(a)){a(s,ln)}else if(e.isFunction(Fn.onCommandNotFound)){Fn.onCommandNotFound(s,ln)}else{l.error(sprintf(An.commandNotFound,f.name))}}}}function u(n,r,t){ln.resume();if(e.isFunction(Fn.onAjaxError)){Fn.onAjaxError.call(ln,n,r,t)}else if(r!=="abort"){ln.error("[AJAX] "+r+" - "+An.serverResponse+": \n"+e.terminal.escape_brackets(n.responseText))}}function h(n,r,t){e.jrpc(n,"system.describe",[],function(i){var o=[];if(i.procs){var s={};e.each(i.procs,function(t,i){s[i.name]=function(){var t=r&&i.name!="help";var o=Array.prototype.slice.call(arguments);var s=o.length+(t?1:0);if(Fn.checkArity&&i.params&&i.params.length!==s){ln.error("[Arity] "+sprintf(An.wrongArity,i.name,i.params.length,s))}else{ln.pause();if(t){var f=ln.token(true);if(f){o=[f].concat(o)}else{ln.error("[AUTH] "+An.noTokenError)}}e.jrpc(n,i.name,o,function(n){if(n.error){l(n.error)}else{if(e.isFunction(Fn.processRPCResponse)){Fn.processRPCResponse.call(ln,n.result,ln)}else{a(n.result)}}ln.resume()},u)}}});s.help=s.help||function(n){if(typeof n=="undefined"){ln.echo("Available commands: "+i.procs.map(function(e){return e.name}).join(", ")+", help")}else{var r=false;e.each(i.procs,function(e,t){if(t.name==n){r=true;var i="";i+="[[bu;#fff;]"+t.name+"]";if(t.params){i+=" "+t.params.join(" ")}if(t.help){i+="\n"+t.help}ln.echo(i);return false}});if(!r){if(n=="help"){ln.echo("[[bu;#fff;]help] [method]\ndisplay help "+"for the method or list of methods if not"+" specified")}else{var t="Method `"+n.toString()+"' not found ";ln.error(t)}}}};t(s)}else{t(null)}},function(){t(null)})}function p(n,r,t){t=t||e.noop;var i=e.type(n);var o;var a={};var s=0;var l;if(i==="array"){o={};(function u(n,t){if(n.length){var i=n[0];var a=n.slice(1);var c=e.type(i);if(c==="string"){s++;ln.pause();if(Fn.ignoreSystemDescribe){if(s===1){l=f(i,r)}else{ln.error(An.oneRPCWithIgnore)}u(a,t)}else{h(i,r,function(n){if(n){e.extend(o,n)}ln.resume();u(a,t)})}}else if(c==="function"){if(l){ln.error(An.oneInterpreterFunction)}else{l=i}u(a,t)}else if(c==="object"){e.extend(o,i);u(a,t)}}else{t()}})(n,function(){t({interpreter:c(o,false,r,l),completion:Object.keys(o)})})}else if(i==="string"){if(Fn.ignoreSystemDescribe){o={interpreter:f(n,r)};if(e.isArray(Fn.completion)){o.completion=Fn.completion}t(o)}else{ln.pause();h(n,r,function(e){if(e){a.interpreter=c(e,false,r);a.completion=Object.keys(e)}else{a.interpreter=f(n,r)}t(a);ln.resume()})}}else if(i==="object"){t({interpreter:c(n,Fn.checkArity),completion:Object.keys(n)})}else{if(i==="undefined"){n=e.noop}else if(i!=="function"){throw i+" is invalid interpreter value"}t({interpreter:n,completion:Fn.completion})}}function m(n,r){var t=e.type(r)==="boolean"?"login":r;return function(r,i,o,a){ln.pause();e.jrpc(n,t,[r,i],function(e){if(!e.error&&e.result){o(e.result)}else{o(null)}ln.resume()},u)}}function d(e){if(typeof e==="string"){return e}else if(typeof e.fileName==="string"){return e.fileName+": "+e.message}else{return e.message}}function v(n,r){if(e.isFunction(Fn.exceptionHandler)){Fn.exceptionHandler.call(ln,n)}else{ln.exception(n,r)}}function y(){var e;if(fn.prop){e=fn.prop("scrollHeight")}else{e=fn.attr("scrollHeight")}fn.scrollTop(e)}function _(n,r){try{if(e.isFunction(r)){r(function(){})}else if(typeof r!=="string"){var t=n+" must be string or function";throw t}}catch(i){v(i,n.toUpperCase());return false}return true}var w=[];var b=1;function k(n,r){if(Fn.convertLinks){n=n.replace(I,"[[!;;]$1]").replace($,"[[!;;]$1]")}var t=e.terminal.defaults.formatters;var i,o;if(!r.raw){for(i=0;i<t.length;++i){try{if(typeof t[i]=="function"){var a=t[i](n);if(typeof a=="string"){n=a}}}catch(s){alert("formatting error at formatters["+i+"]\n"+(s.stack?s.stack:s))}}n=e.terminal.encode(n)}w.push(b);if(!r.raw&&(n.length>dn||n.match(/\n/))){var l=r.keepWords;var f=e.terminal.split_equal(n,dn,l);for(i=0,o=f.length;i<o;++i){if(f[i]===""||f[i]==="\r"){w.push("<span></span>")}else{if(r.raw){w.push(f[i])}else{w.push(e.terminal.format(f[i],{linksNoReferrer:Fn.linksNoReferrer}))}}}}else{if(!r.raw){n=e.terminal.format(n,{linksNoReferrer:Fn.linksNoReferrer})}w.push(n)}w.push(r.finalize)}function S(n,r){try{var t=e.extend({exec:true,raw:false,finalize:e.noop},r||{});var i=e.type(n)==="function"?n():n;i=e.type(i)==="string"?i:String(i);if(i!==""){if(t.exec){i=e.map(i.split(P),function(n){if(n.match(P)&&!e.terminal.is_formatting(n)){n=n.replace(/^\[\[|\]\]$/g,"");if(cn&&cn.command==n){ln.error(An.recursiveCall)}else{e.terminal.extended_command(ln,n)}return""}else{return n}}).join("");if(i!==""){k(i,t)}}else{k(i,t)}}}catch(o){w=[];alert("[Internal Exception(process_line)]:"+d(o)+"\n"+o.stack)}}function T(){Bn.resize(dn);var n=mn.empty().detach();var r;if(Fn.outputLimit>=0){var t=Fn.outputLimit===0?ln.rows():Fn.outputLimit;r=pn.slice(pn.length-t-1)}else{r=pn}try{w=[];e.each(r,function(e,n){S.apply(null,n)});Bn.before(n);ln.flush()}catch(i){alert("Exception in redraw\n"+i.stack)}}function F(){if(Fn.greetings===n){ln.echo(ln.signature)}else if(Fn.greetings){var e=typeof Fn.greetings;if(e==="string"){ln.echo(Fn.greetings)}else if(e==="function"){Fn.greetings.call(ln,ln.echo)}else{ln.error(An.wrongGreetings)}}}function A(n){var r=Bn.prompt();var t=Bn.mask();switch(typeof t){case"string":n=n.replace(/./g,t);break;case"boolean":if(t){n=n.replace(/./g,Fn.maskChar)}else{n=e.terminal.escape_formatting(n)}break}var i={finalize:function(e){e.addClass("command")}};if(e.isFunction(r)){r(function(e){ln.echo(e+n,i)})}else{ln.echo(r+n,i)}}function j(e){var n=Z.get()[e[0]];if(!n){throw new Error(An.invalidTerminalId)}var r=e[1];if(V[r]){n.import_view(V[r])}else{nn=false;var t=e[2];if(t){n.exec(t).then(function(){nn=true;V[r]=n.export_view()})}}}function E(){if(nn){rn=false;location.hash="#"+e.json_stringify(en);setTimeout(function(){rn=true},100)}}var z=true;var O;var K=[];var N=false;function L(r,t,i){O=r;if(z){z=false;if(Fn.historyState||Fn.execHash&&i){if(!V.length){ln.save_state()}else{ln.save_state(null)}}}function o(){if(!i){nn=true;if(Fn.historyState){ln.save_state(r,false)}nn=f}l.resolve();if(e.isFunction(Fn.onAfterCommand)){Fn.onAfterCommand(ln,r)}}try{if(e.isFunction(Fn.onBeforeCommand)){if(Fn.onBeforeCommand(ln,r)===false){return}}if(!i){cn=e.terminal.split_command(r)}if(!an()){if(i&&(e.isFunction(Fn.historyFilter)&&Fn.historyFilter(r)||r.match(Fn.historyFilter))){Bn.history().append(r)}}var s=Dn.top();if(!t&&Fn.echoCommand){A(r)}var l=new e.Deferred;var f=nn;if(r.match(/^\s*login\s*$/)&&ln.token(true)){if(ln.level()>1){ln.logout(true)}else{ln.logout()}o()}else if(Fn.exit&&r.match(/^\s*exit\s*$/)&&!kn){var c=ln.level();if(c==1&&ln.get_token()||c>1){if(ln.get_token(true)){ln.set_token(n,true)}ln.pop()}o()}else if(Fn.clear&&r.match(/^\s*clear\s*$/)&&!kn){ln.clear();o()}else{var u=pn.length-1;var h=s.interpreter.call(ln,r,ln);if(h!==n){ln.pause(true);return e.when(h).then(function(e){if(e&&u===pn.length-1){a(e)}o();ln.resume()})}else if(Rn){var p=r;K.push(function(){o()})}else{o()}}return l.promise()}catch(m){v(m,"USER");ln.resume();throw m}}function D(){if(e.isFunction(Fn.onBeforeLogout)){try{if(Fn.onBeforeLogout(ln)===false){return}}catch(n){v(n,"onBeforeLogout")}}J();if(e.isFunction(Fn.onAfterLogout)){try{Fn.onAfterLogout(ln)}catch(n){v(n,"onAfterlogout")}}ln.login(Fn.login,true,G)}function J(){var n=ln.prefix_name(true)+"_";e.Storage.remove(n+"token");e.Storage.remove(n+"login")}function M(n){var r=ln.prefix_name()+"_interpreters";var t=e.Storage.get(r);if(t){t=e.parseJSON(t)}else{t=[]}if(e.inArray(n,t)==-1){t.push(n);e.Storage.set(r,e.json_stringify(t))}}function U(n){var r=Dn.top();var t=ln.prefix_name(true);if(!an()){M(t)}Bn.name(t);if(e.isFunction(r.prompt)){Bn.prompt(function(e){r.prompt(e,ln)})}else{Bn.prompt(r.prompt)}Bn.set("");if(!n&&e.isFunction(r.onStart)){r.onStart(ln)}}var Y;function G(){U();F();var n=false;if(e.isFunction(Fn.onInit)){xn=function(){n=true};try{Fn.onInit(ln)}catch(r){v(r,"OnInit")}finally{xn=e.noop;if(!n){ln.resume()}}}function t(){if(rn&&Fn.execHash){try{if(location.hash){var n=location.hash.replace(/^#/,"");en=e.parseJSON(decodeURIComponent(n))}else{en=[]}if(en.length){j(en[en.length-1])}else if(V[0]){ln.import_view(V[0])}}catch(r){v(r,"TERMINAL")}}}if(tn){tn=false;if(e.fn.hashchange){e(window).hashchange(t)}else{e(window).bind("hashchange",t)}}}function on(n,r,t){if(Fn.clear&&e.inArray("clear",t)==-1){t.push("clear")}if(Fn.exit&&e.inArray("exit",t)==-1){t.push("exit")}var i=Bn.get().substring(0,Bn.position());if(i!==n){return}var o=new RegExp("^"+e.terminal.escape_regex(r));var a=[];for(var s=t.length;s--;){if(o.test(t[s])){a.push(t[s])}}if(a.length===1){ln.insert(a[0].replace(o,""))}else if(a.length>1){if(hn>=2){A(n);var l=a.reverse().join(" ");ln.echo(e.terminal.escape_brackets(l),{keepWords:true});hn=0}else{var f=false;var c;var u;e:for(u=r.length;u<a[0].length;++u){for(s=1;s<a.length;++s){if(a[0].charAt(u)!==a[s].charAt(u)){break e}}f=true}if(f){ln.insert(a[0].slice(0,u).replace(o,""))}}}}function an(){return kn||Bn.mask()!==false}function sn(r){var t,i,o=Dn.top(),a;if(!ln.paused()&&ln.enabled()){if(e.isFunction(o.keydown)){t=o.keydown(r,ln);if(t!==n){return t}}else if(e.isFunction(Fn.keydown)){t=Fn.keydown(r,ln);if(t!==n){return t}}if(Fn.completion&&e.type(Fn.completion)!="boolean"&&o.completion===n){a=Fn.completion}else{a=o.completion}if(a=="settings"){a=Fn.completion}ln.oneTime(10,function(){In()});if(r.which!==9){hn=0}if(r.which===68&&r.ctrlKey){if(!kn){if(Bn.get()===""){if(Dn.size()>1||Fn.login!==n){ln.pop("")}else{ln.resume();ln.echo("")}}else{ln.set_command("")}}return false}else if(r.which===76&&r.ctrlKey){ln.clear()}else if(a&&r.which===9){++hn;var s=Bn.position();var l=Bn.get().substring(0,s);var f=l.split(" ");var c;if(An.length==1){c=f[0]}else{c=f[f.length-1];for(i=f.length-1;i>0;i--){if(f[i-1][f[i-1].length-1]=="\\"){c=f[i-1]+" "+c}else{break}}}switch(e.type(a)){case"function":a(ln,c,function(e){on(l,c,e)});break;case"array":on(l,c,a);break;default:throw new Error(An.invalidCompletion)}return false}else if((r.which===118||r.which===86)&&(r.ctrlKey||r.metaKey)){ln.oneTime(1,function(){y()});return}else if(r.which===9&&r.ctrlKey){if(Z.length()>1){ln.focus(false);return false}}else if(r.which===34){ln.scroll(ln.height())}else if(r.which===33){ln.scroll(-ln.height())}else{ln.attr({scrollTop:ln.attr("scrollHeight")})}}else if(r.which===68&&r.ctrlKey){if(X.length){for(i=X.length;i--;){var u=X[i];if(4!==u.readyState){try{u.abort()}catch(h){ln.error(An.ajaxAbortError)}}}X=[];ln.resume()}return false}}var ln=this;if(this.length>1){return this.each(function(){e.fn.terminal.call(e(this),r,e.extend({name:ln.selector},i))})}if(ln.data("terminal")){return ln.data("terminal")}if(ln.length===0){throw sprintf(e.terminal.defaults.strings.invalidSelector,ln.selector)}var fn;var cn;var un=false;var hn=0;var pn=[];var mn;var gn=Z.length();var dn;var vn;var yn=[];var _n;var wn=new g;var bn=e.Deferred();var kn=false;var xn=e.noop;var Cn,Sn;var Tn=[];var Fn=e.extend({},e.terminal.defaults,{name:ln.selector},i||{});var An=e.terminal.defaults.strings;var jn=Fn.enabled,En;var Rn=false;var $n=true;e.extend(ln,e.omap({id:function(){return gn},clear:function(){mn.html("");pn=[];try{Fn.onClear(ln)}catch(e){v(e,"onClear")}ln.attr({scrollTop:0});return ln},export_view:function(){var n={};if(e.isFunction(Fn.onExport)){try{n=Fn.onExport()}catch(r){v(r,"onExport")}}return e.extend({},{focus:jn,mask:Bn.mask(),prompt:ln.get_prompt(),command:ln.get_command(),position:Bn.position(),lines:t(pn),interpreters:Dn.clone()},n)},import_view:function(n){if(kn){throw new Error(sprintf(An.notWhileLogin,"import_view"))}if(e.isFunction(Fn.onImport)){try{Fn.onImport(n)}catch(r){v(r,"onImport")}}bn.then(function(){ln.set_prompt(n.prompt);ln.set_command(n.command);Bn.position(n.position);Bn.mask(n.mask);if(n.focus){ln.focus()}pn=t(n.lines);Dn=n.interpreters;T()});return ln},save_state:function(r,t,i){if(typeof i!="undefined"){V[i]=ln.export_view()}else{V.push(ln.export_view())}if(!e.isArray(en)){en=[]}if(r!==n&&!t){var o=[gn,V.length-1,r];en.push(o);E()}},exec:function(n,r,t){var i=t||new e.Deferred;function o(){if(e.isArray(n)){(function t(){var e=n.shift();if(e){ln.exec(e,r).then(t)}else{i.resolve()}})()}else if(Rn){Tn.push([n,r,i])}else{L(n,r,true).then(function(){i.resolve(ln)})}}if(bn.state()!="resolved"){bn.then(o)}else{o()}return i.promise()},autologin:function(e,n,r){ln.trigger("terminal.autologin",[e,n,r]);return ln},login:function(n,r,t,i){wn.push([].slice.call(arguments));if(kn){throw new Error(sprintf(An.notWhileLogin,"login"))}if(!e.isFunction(n)){throw new Error(An.loginIsNotAFunction)}kn=true;if(ln.token()&&ln.level()==1&&!$n){kn=false;ln.logout(true)}else{if(ln.token(true)&&ln.login_name(true)){kn=false;if(e.isFunction(t)){t()}return ln}}var o=null;if(Fn.history){Bn.history().disable()}var a=ln.level();function s(n,o,s,l){if(o){while(ln.level()>a){ln.pop()}if(Fn.history){Bn.history().enable()}var f=ln.prefix_name(true)+"_";e.Storage.set(f+"token",o);e.Storage.set(f+"login",n);kn=false;if(e.isFunction(t)){t()}}else{if(r){if(!s){ln.error(An.wrongPasswordTryAgain)}ln.pop().set_mask(false)}else{kn=false;if(!s){ln.error(An.wrongPassword)}ln.pop().pop()}if(e.isFunction(i)){i()}}ln.off("terminal.autologin")}ln.on("terminal.autologin",function(e,n,r,t){s(n,r,t)});ln.push(function(e){ln.set_mask(Fn.maskChar).push(function(r){try{n.call(ln,e,r,function(n,r){s(e,n,r)})}catch(t){v(t,"AUTH")}},{prompt:An.password+": ",name:"password"})},{prompt:An.login+": ",name:"login"});return ln},settings:function(){return Fn},commands:function(){return Dn.top().interpreter},setInterpreter:function(){if(window.console&&console.warn){console.warn("This function is deprecated, use set_inte"+"rpreter insead!")}return ln.set_interpreter.apply(ln,arguments)},set_interpreter:function(n,r){function t(){ln.pause();p(n,!!r,function(n){ln.resume();var r=Dn.top();e.extend(r,n);U(true)})}if(e.type(n)=="string"&&r){ln.login(m(n,r),true,t)}else{t()}return ln},greetings:function(){F();return ln},paused:function(){return Rn},pause:function(n){xn();if(!Rn&&Bn){bn.then(function(){Rn=true;Bn.disable();if(!n){Bn.hidden()}if(e.isFunction(Fn.onPause)){Fn.onPause()}})}return ln},resume:function(){function n(){Rn=false;if(Z.front()==ln){Bn.enable()}Bn.visible();var n=Tn;Tn=[];for(var r=0;r<n.length;++r){ln.exec.apply(ln,n[r])}ln.trigger("resume");var t=K.shift();if(t){t()}y();if(e.isFunction(Fn.onResume)){Fn.onResume()}}if(Rn&&Bn){if(bn.state()!="resolved"){bn.then(n)}else{n()}}return ln},cols:function(){return Fn.numChars?Fn.numChars:B(ln)},rows:function(){return Fn.numRows?Fn.numRows:H(ln)},history:function(){return Bn.history()},history_state:function(e){if(e){ln.oneTime(1,function(){Fn.historyState=true;if(!V.length){ln.save_state()}else if(Z.length()>1){ln.save_state(null)}})}else{Fn.historyState=false}return ln},clear_history_state:function(){en=[];V=[]},next:function(){if(Z.length()===1){return ln}else{var n=ln.offset().top;var r=ln.height();var t=ln.scrollTop();Z.front().disable();var i=Z.rotate().enable();var o=i.offset().top-50;e("html,body").animate({scrollTop:o},500);try{Fn.onTerminalChange(i)}catch(a){v(a,"onTerminalChange")}return i}},focus:function(e,n){bn.then(function(){if(Z.length()===1){if(e===false){try{if(!n&&Fn.onBlur(ln)!==false||n){ln.disable()}}catch(r){v(r,"onBlur")}}else{try{if(!n&&Fn.onFocus(ln)!==false||n){ln.enable()}}catch(r){v(r,"onFocus")}}}else{if(e===false){ln.next()}else{var t=Z.front();if(t!=ln){t.disable();if(!n){try{Fn.onTerminalChange(ln)}catch(r){v(r,"onTerminalChange")}}}Z.set(ln);ln.enable()}}});return ln},freeze:function(e){bn.then(function(){if(e){ln.disable();En=true}else{En=false;ln.enable()}})},frozen:function(){return En},enable:function(){if(!jn&&!En){if(dn===n){ln.resize()}bn.then(function(){Bn.enable();jn=true})}return ln},disable:function(){if(jn&&!En){bn.then(function(){jn=false;Bn.disable()})}return ln},enabled:function(){return jn},signature:function(){var e=ln.cols();var n=e<15?null:e<35?0:e<55?1:e<64?2:e<75?3:4;if(n!==null){return Q[n].join("\n")+"\n"}else{return""}},version:function(){return e.terminal.version},cmd:function(){return Bn},get_command:function(){return Bn.get()},set_command:function(e){bn.then(function(){Bn.set(e)});return ln},insert:function(e){if(typeof e==="string"){bn.then(function(){Bn.insert(e)});return ln}else{throw"insert function argument is not a string"}},set_prompt:function(n){bn.then(function(){if(_("prompt",n)){if(e.isFunction(n)){Bn.prompt(function(e){n(e,ln)})}else{Bn.prompt(n)}Dn.top().prompt=n}});return ln},get_prompt:function(){return Dn.top().prompt},set_mask:function(e){bn.then(function(){Bn.mask(e===true?Fn.maskChar:e)});return ln},get_output:function(n){if(n){return pn}else{return e.map(pn,function(n){return e.isFunction(n[0])?n[0]():n[0]}).join("\n")}},resize:function(n,r){if(!ln.is(":visible")){ln.stopTime("resize");ln.oneTime(500,"resize",function(){ln.resize(n,r)})}else{if(n&&r){ln.width(n);ln.height(r)}n=ln.width();r=ln.height();var t=ln.cols();var i=ln.rows();if(t!==dn||i!==vn){dn=t;vn=i;T();var o=Dn.top();if(e.isFunction(o.resize)){o.resize(ln)}else if(e.isFunction(Fn.onResize)){Fn.onResize(ln)}Sn=r;Cn=n;y()}}return ln},flush:function(){try{var n;e.each(w,function(r,t){if(t===b){n=e("<div></div>")}else if(e.isFunction(t)){n.appendTo(mn);try{t(n)}catch(i){v(i,"USER:echo(finalize)")}}else{e("<div/>").html(t).appendTo(n).width("100%")}});if(Fn.outputLimit>=0){var r=Fn.outputLimit===0?ln.rows():Fn.outputLimit;var t=mn.find("div div");if(t.length>r){var i=pn.length-r+1;var o=t.slice(0,i);var a=o.parent();o.remove();a.each(function(){var n=e(this);if(n.is(":empty")){n.remove()}})}}y();w=[]}catch(s){alert("[Flush] "+d(s)+"\n"+s.stack)}return ln},update:function(e,n){bn.then(function(){if(e<0){e=pn.length+e}if(!pn[e]){ln.error("Invalid line number "+e)}else{if(n==null){pn.splice(e,1)}else{pn[e][0]=n}T()}});return ln},last_index:function(){return pn.length-1},echo:function(n,r){n=n||"";e.when(n).then(function(n){try{var t=e.extend({flush:true,raw:Fn.raw,finalize:e.noop,keepWords:false},r||{});if(t.flush){w=[]}S(n,t);pn.push([n,e.extend(t,{exec:false})]);if(t.flush){ln.flush()}vn=H(ln);In()}catch(i){alert("[Terminal.echo] "+d(i)+"\n"+i.stack)}});return ln},error:function(n,r){var t=e.terminal.escape_brackets(n).replace(/\\$/,"\").replace(R,"]$1[[;;;error]");return ln.echo("[[;;;error]"+t+"]",r)},exception:function(n,r){var t=d(n);if(r){t="["+r+"]: "+t}if(t){ln.error(t,{finalize:function(e){e.addClass("exception message")}})}if(typeof n.fileName==="string"){ln.pause();e.get(n.fileName,function(e){ln.resume();var r=n.lineNumber-1;var t=e.split("\n")[r];if(t){ln.error("["+n.lineNumber+"]: "+t)}})}if(n.stack){var i=e.terminal.escape_brackets(n.stack);ln.echo(i.split(/\n/g).map(function(e){return"[[;;;error]"+e.replace(R,function(e){return"]"+e+"[[;;;error]"})+"]"}).join("\n"),{finalize:function(e){e.addClass("exception stack-trace")}})}},scroll:function(e){var n;e=Math.round(e);if(fn.prop){if(e>fn.prop("scrollTop")&&e>0){fn.prop("scrollTop",0)}n=fn.prop("scrollTop");fn.scrollTop(n+e)}else{if(e>fn.attr("scrollTop")&&e>0){fn.attr("scrollTop",0)}n=fn.attr("scrollTop");fn.scrollTop(n+e)}return ln},logout:function(e){if(kn){throw new Error(sprintf(An.notWhileLogin,"logout"))}bn.then(function(){if(e){var r=wn.pop();ln.set_token(n,true);ln.login.apply(ln,r)}else{while(Dn.size()>0){if(ln.pop()){break}}}});return ln},token:function(n){return e.Storage.get(ln.prefix_name(n)+"_token")},set_token:function(n,r){var t=ln.prefix_name(r)+"_token";if(typeof n=="undefined"){e.Storage.remove(t,n)}else{e.Storage.set(t,n)}return ln},get_token:function(n){return e.Storage.get(ln.prefix_name(n)+"_token")},login_name:function(n){return e.Storage.get(ln.prefix_name(n)+"_login")},name:function(){return Dn.top().name},prefix_name:function(e){var n=(Fn.name?Fn.name+"_":"")+gn;if(e&&Dn.size()>1){var r=Dn.map(function(e){return e.name}).slice(1).join("_");if(r){n+="_"+r}}return n},read:function(n,r){var t=new e.Deferred;ln.push(function(n){ln.pop();if(e.isFunction(r)){r(n)}t.resolve(n)},{prompt:n});return t.promise()},push:function(r,t){bn.then(function(){t=t||{};var i={infiniteLogin:false};var o=e.extend({},i,t);if(!o.name&&cn){o.name=cn.name}if(o.prompt===n){o.prompt=(o.name||">")+" "}var a=Dn.top();if(a){a.mask=Bn.mask()}var s=Rn;p(r,!!t.login,function(n){Dn.push(e.extend({},n,o));if(e.isArray(n.completion)&&o.completion===true){Dn.top().completion=n.completion}else if(!n.completion&&o.completion===true){Dn.top().completion=false}if(o.login){var t=e.type(o.login);if(t=="function"){ln.login(o.login,o.infiniteLogin,U,o.infiniteLogin?e.noop:ln.pop)}else if(e.type(r)=="string"&&t=="string"||t=="boolean"){ln.login(m(r,o.login),o.infiniteLogin,U,o.infiniteLogin?e.noop:ln.pop)}}else{U()}if(!s){ln.resume()}})});return ln},pop:function(r){if(r!==n){A(r)}var t=ln.token(true);if(Dn.size()==1){if(Fn.login){D();if(e.isFunction(Fn.onExit)){try{Fn.onExit(ln)}catch(i){v(i,"onExit")}}return true}else{ln.error(An.canExitError)}}else{if(ln.token(true)){J()}var o=Dn.pop();U();if(kn&&ln.get_prompt()!=An.login+": "){kn=false}if(e.isFunction(o.onExit)){try{o.onExit(ln)}catch(i){v(i,"onExit")}}ln.set_mask(Dn.top().mask)}return ln},option:function(n,r){if(typeof r=="undefined"){if(typeof n=="string"){return Fn[n]}else if(typeof n=="object"){e.each(n,function(e,n){Fn[e]=n})}}else{Fn[n]=r}return ln},level:function(){return Dn.size()},reset:function(){bn.then(function(){ln.clear();while(Dn.size()>1){Dn.pop()}G()});return ln},purge:function(){bn.then(function(){var n=ln.prefix_name()+"_";var r=e.Storage.get(n+"interpreters");e.each(e.parseJSON(r),function(n,r){e.Storage.remove(r+"_commands");e.Storage.remove(r+"_token");e.Storage.remove(r+"_login")});Bn.purge();e.Storage.remove(n+"interpreters")});return ln},destroy:function(){bn.then(function(){Bn.destroy().remove();mn.remove();e(document).unbind(".terminal");e(window).unbind(".terminal");ln.unbind("click mousewheel mousedown mouseup");ln.removeData("terminal").removeClass("terminal");if(Fn.width){ln.css("width","")}if(Fn.height){ln.css("height","")}e(window).off("blur",qn).off("focus",Wn);Z.remove(gn)});return ln}},function(e,n){return function(){try{return n.apply(ln,[].slice.apply(arguments))}catch(r){if(e!=="exec"&&e!=="resume"){v(r,"TERMINAL")}throw r}}}));var In=function(){var e=q(ln);return function(){if(e!==q(ln)){ln.resize();e=q(ln)}}}();if(Fn.width){ln.width(Fn.width)}if(Fn.height){ln.height(Fn.height)}var zn=navigator.userAgent.toLowerCase();if(!zn.match(/(webkit)[ \/]([\w.]+)/)&&ln[0].tagName.toLowerCase()=="body"){fn=e("html")}else{fn=ln}e(document).bind("ajaxSend.terminal",function(e,n,r){X.push(n)});mn=e("<div>").addClass("terminal-output").appendTo(ln);ln.addClass("terminal");if(Fn.login&&e.isFunction(Fn.onBeforeLogin)){try{if(Fn.onBeforeLogin(ln)===false){$n=false}}catch(On){v(On,"onBeforeLogin");throw On}}var Kn=Fn.login;var Nn;if(typeof r=="string"){Nn=r}else if(r instanceof Array){for(var Pn=0,Ln=r.length;Pn<Ln;++Pn){if(typeof r[Pn]=="string"){Nn=r[Pn];break}}}if(Nn&&(typeof Fn.login==="string"||Fn.login===true)){Fn.login=m(Nn,Fn.login)}Z.append(ln);var Dn;var Bn;var Hn;function Wn(){if(Hn){ln.focus()}}function qn(){Hn=jn;ln.disable()}p(r,!!Fn.login,function(r){if(Fn.completion&&typeof Fn.completion!="boolean"||!Fn.completion){r.completion="settings"}Dn=new g(e.extend({name:Fn.name,prompt:Fn.prompt,keypress:Fn.keypress,keydown:Fn.keydown,resize:Fn.onResize,greetings:Fn.greetings,mousewheel:Fn.mousewheel},r));Bn=e("<div/>").appendTo(ln).cmd({prompt:Fn.prompt,history:Fn.history,historyFilter:Fn.historyFilter,historySize:Fn.historySize,width:"100%",enabled:jn&&!x,keydown:sn,keypress:function(n){var r,t,i=Dn.top();if(e.isFunction(i.keypress)){return i.keypress(n,ln)}else if(e.isFunction(Fn.keypress)){return Fn.keypress(n,ln)}},onCommandChange:function(n){if(e.isFunction(Fn.onCommandChange)){try{Fn.onCommandChange(n,ln)}catch(r){v(r,"onCommandChange");throw r}}y()},commands:L});if(jn&&ln.is(":visible")&&!x){ln.focus(n,true)}else{ln.disable()}ln.oneTime(100,function(){function n(n){var r=e(n.target);if(!r.closest(".terminal").length&&ln.enabled()&&Fn.onBlur(ln)!==false){ln.disable()}}e(document).bind("click.terminal",n).bind("contextmenu.terminal",n)});var t=e(window);if(!x){t.on("focus",Wn).on("blur",qn)}else{}(function(){var n=0;var r=false;ln.mousedown(function(){e(window).mousemove(function(){r=true;n=0;e(window).unbind("mousemove")})}).mouseup(function(){var t=r;r=false;e(window).unbind("mousemove");if(!t&&n++==1){if(!ln.enabled()){ln.focus();Bn.enable()}}})})();if(x){ln.click(function(){if(!ln.enabled()){ln.focus();Bn.enable()}else{ln.focus(false)}})}ln.delegate(".exception a","click",function(n){var r=e(this).attr("href");if(r.match(/:[0-9]+$/)){n.preventDefault();s(r)}});if(!navigator.platform.match(/linux/i)){ln.mousedown(function(e){if(e.which==2){var n=W();ln.insert(n)}})}if(ln.is(":visible")){dn=ln.cols();Bn.resize(dn);vn=H(ln)}if(Fn.login){ln.login(Fn.login,true,G)}else{G()}ln.oneTime(100,function(){t.bind("resize.terminal",function(){if(ln.is(":visible")){var e=ln.width();var n=ln.height();if(Sn!==n||Cn!==e){ln.resize()}}})});function i(n){var r=Z.get()[n[0]];if(r&&gn==r.id()){if(n[2]){try{if(Rn){var t=e.Deferred();K.push(function(){return r.exec(n[2]).then(function(e,i){r.save_state(n[2],true,n[1]);t.resolve()})});return t.promise()}else{return r.exec(n[2]).then(function(e,t){r.save_state(n[2],true,n[1])})}}catch(i){var o=e.terminal.escape_brackets(command);var a="Error while exec with command "+o;r.error(a).exception(i)}}}}if(Fn.execHash){if(location.hash){setTimeout(function(){try{var n=location.hash.replace(/^#/,"");en=e.parseJSON(decodeURIComponent(n));var r=0;(function o(){var e=en[r++];if(e){i(e).then(o)}else{nn=true}})()}catch(t){}})}else{nn=true}}else{nn=true}if(e.event.special.mousewheel){var o=false;e(document).bind("keydown.terminal",function(e){if(e.shiftKey){o=true}}).bind("keyup.terminal",function(e){if(e.shiftKey||e.which==16){o=false}});ln.mousewheel(function(n,r){if(!o){var t=Dn.top();if(e.isFunction(t.mousewheel)){var i=t.mousewheel(n,r,ln);if(i===false){return}}else if(e.isFunction(Fn.mousewheel)){Fn.mousewheel(n,r,ln)}if(r>0){ln.scroll(-40)}else{ln.scroll(40)}}})}bn.resolve()});ln.data("terminal",ln);return ln}})(jQuery); |