1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 17:12:30 +01:00
Pterodactyl-Panel/public/js/jquery.terminal-0.11.23.min.js
Jakob Schrettenbrunner d844c4135c update jquery.terminal to v0.11.23
set new scrollBottomOffset to 5 to hopefully resolve issues with chrome
2016-12-10 13:51:07 +01:00

38 lines
63 KiB
JavaScript

/**@license
* __ _____ ________ __
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
* \/ /____/ version 0.11.23
*
* 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: Sat, 10 Dec 2016 10:56:53 +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,t){var o=1,a=e.length,s="",l,f=[],c,u,h,p,m,g;for(c=0;c<a;c++){s=r(e[c]);if(s==="string"){f.push(e[c])}else if(s==="array"){h=e[c];if(h[2]){l=t[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=t[h[1]]}else{l=t[o++]}if(/[^s]/.test(h[8])&&r(l)!="number"){throw n("[sprintf] expecting number but found %s",r(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,t=[],r=[],i=0;while(n){if((t=/^[^\x25]+/.exec(n))!==null){r.push(t[0])}else if((t=/^\x25{2}/.exec(n))!==null){r.push("%")}else if((t=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(n))!==null){if(t[2]){i|=1;var o=[],a=t[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?"}t[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}r.push(t)}else{throw"[sprintf] huh?"}n=n.substring(t[0].length)}return r};var t=function(e,t,r){r=t.slice(0);r.splice(0,0,e);return n.apply(null,r)};function r(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,n){for(var t=[];n>0;t[--n]=e){}return t.join("")}e.sprintf=n;e.vsprintf=t})(typeof global!="undefined"?global:window);(function(e,n){"use strict";e.omap=function(n,t){var r={};e.each(n,function(e,i){r[e]=t.call(n,e,i)});return r};var t={clone_object:function(n){var t={};if(typeof n=="object"){if(e.isArray(n)){return this.clone_array(n)}else if(n===null){return n}else{for(var r in n){if(e.isArray(n[r])){t[r]=this.clone_array(n[r])}else if(typeof n[r]=="object"){t[r]=this.clone_object(n[r])}else{t[r]=n[r]}}}}return t},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 r=function(e){return t.clone_object(e)};var i=function(){var e="test",n=window.localStorage;try{n.setItem(e,"1");n.removeItem(e);return true}catch(t){return false}};var o=i();function a(e,n){var t;if(typeof e==="string"&&typeof n==="string"){localStorage[e]=n;return true}else if(typeof e==="object"&&typeof n==="undefined"){for(t in e){if(e.hasOwnProperty(t)){localStorage[t]=e[t]}}return true}return false}function s(e,n){var t,r,i;t=new Date;t.setTime(t.getTime()+31536e6);r="; expires="+t.toGMTString();if(typeof e==="string"&&typeof n==="string"){document.cookie=e+"="+n+r+"; path=/";return true}else if(typeof e==="object"&&typeof n==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+r+"; path=/"}}return true}return false}function l(e){return localStorage[e]}function f(e){var n,t,r,i;n=e+"=";t=document.cookie.split(";");for(r=0;r<t.length;r++){i=t[r];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,t,r,i){return this.each(function(){h.timer.add(this,e,n,t,r,i)})},oneTime:function(e,n,t){return this.each(function(){h.timer.add(this,e,n,t,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 t=this.regex.exec(h.trim(e.toString()));if(t[2]){var r=parseInt(t[1],10);var i=this.powers[t[2]]||1;return r*i}else{return e}},add:function(e,n,t,r,i,o){var a=0;if(h.isFunction(t)){if(!i){i=r}r=t;t=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[t]){e.$timers[t]={}}r.$timerID=r.$timerID||this.guid++;var s=function(){if(o&&s.inProgress){return}s.inProgress=true;if(++a>i&&i!==0||r.call(e,a)===false){h.timer.remove(e,t,r)}s.inProgress=false};s.$timerID=r.$timerID;if(!e.$timers[t][r.$timerID]){e.$timers[t][r.$timerID]=window.setInterval(s,n)}if(!this.global[t]){this.global[t]=[]}this.global[t].push(e)},remove:function(e,n,t){var r=e.$timers,i;if(r){if(!n){for(var o in r){if(r.hasOwnProperty(o)){this.remove(e,o,t)}}}else if(r[n]){if(t){if(t.$timerID){window.clearInterval(r[n][t.$timerID]);delete r[n][t.$timerID]}}else{for(var a in r[n]){if(r[n].hasOwnProperty(a)){window.clearInterval(r[n][a]);delete r[n][a]}}}for(i in r[n]){if(r[n].hasOwnProperty(i)){break}}if(!i){i=null;delete r[n]}}for(i in r){if(r.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 t=e[n],r=t.length;while(--r){h.timer.remove(t[r],n)}}}})}(function(e){if(!String.prototype.split.toString().match(/\[native/)){return}var n=String.prototype.split,t=/()??/.exec("")[1]===e,r;r=function(r,i,o){if(Object.prototype.toString.call(i)!=="[object RegExp]"){return n.call(r,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");r+="";if(!t){f=new RegExp("^"+i.source+"$(?!\\s)",s)}o=o===e?-1>>>0:o>>>0;while(c=i.exec(r)){u=c.index+c[0].length;if(u>l){a.push(r.slice(l,c.index));if(!t&&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<r.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===r.length){if(h||!i.test("")){a.push("")}}else{a.push(r.slice(l))}return a.length>o?a.slice(0,o):a};String.prototype.split=function(e,n){return r(this,e,n)};return r})();e.fn.caret=function(e){var n=this[0];var t=n.contentEditable==="true";if(arguments.length==0){if(window.getSelection){if(t){n.focus();var r=window.getSelection().getRangeAt(0),i=r.cloneRange();i.selectNodeContents(n);i.setEnd(r.endContainer,r.endOffset);return i.toString().length}return n.selectionStart}if(document.selection){n.focus();if(t){var r=document.selection.createRange(),i=document.body.createTextRange();i.moveToElementText(n);i.setEndPoint("EndToEnd",r);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[t?"text":"val"]().length;if(window.getSelection){if(t){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(!t)n.focus();return e};function p(e,n){var t=[];var r=e.length;if(r<n){return[e]}else if(n<0){throw new Error("str_parts: length can't be negative")}for(var i=0;i<r;i+=n){t.push(e.substring(i,i+n))}return t}function m(n){var t=n?[n]:[];var r=0;e.extend(this,{get:function(){return t},rotate:function(){if(!t.filter(Boolean).length){return}if(t.length===1){return t[0]}else{if(r===t.length-1){r=0}else{++r}if(t[r]){return t[r]}else{return this.rotate()}}},length:function(){return t.length},remove:function(e){delete t[e]},set:function(e){for(var n=t.length;n--;){if(t[n]===e){r=n;return}}this.append(e)},front:function(){if(t.length){var e=r;var n=false;while(!t[e]){e++;if(e>t.length){if(n){break}e=0;n=true}}return t[e]}},append:function(e){t.push(e)}})}function g(n){var t=n instanceof Array?n:n?[n]:[];e.extend(this,{data:function(){return t},map:function(n){return e.map(t,n)},size:function(){return t.length},pop:function(){if(t.length===0){return null}else{var e=t[t.length-1];t=t.slice(0,t.length-1);return e}},push:function(e){t=t.concat([e]);return e},top:function(){return t.length>0?t[t.length-1]:null},clone:function(){return new g(t.slice(0))}})}function d(n,t,r){var i=true;var o="";if(typeof n==="string"&&n!==""){o=n+"_"}o+="commands";var a;if(r){a=[]}else{a=e.Storage.get(o);a=a?e.parseJSON(a):[]}var s=a.length-1;e.extend(this,{append:function(n){if(i){if(a[a.length-1]!==n){a.push(n);if(t&&a.length>t){a=a.slice(-t)}s=a.length-1;if(!r){e.Storage.set(o,JSON.stringify(a))}}}},data:function(){return a},reset:function(){s=a.length-1},last:function(){return a[a.length-1]},end:function(){return s===a.length-1},position:function(){return s},current:function(){return a[s]},next:function(){if(s<a.length-1){++s}if(s!==-1){return a[s]}},previous:function(){var e=s;if(s>0){--s}if(e!==-1){return a[s]}},clear:function(){a=[];this.purge()},enabled:function(){return i},enable:function(){i=true},purge:function(){if(!r){e.Storage.remove(o)}},disable:function(){i=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(t){var r=this;var i=r.data("cmd");if(i){return i}r.addClass("cmd");r.append('<span class="prompt"></span><span></span>'+'<span class="cursor">&nbsp;</span><span></span>');var o=e("<textarea>").attr({autocapitalize:"off",spellcheck:"false"}).addClass("clipboard").appendTo(r);if(t.width){r.width(t.width)}var a;var s;var l=r.find(".prompt");var f=false;var c="";var u=null;var h;var m=t.mask||false;var g="";var y;var w="";var _="";var C=0;var S;var T;var F=t.historySize||60;var E,A;var R=r.find(".cursor");var j;var $=0;function O(){var e=o.is(":focus");if(T){if(!e){o.focus();r.oneTime(10,function(){o.focus()})}}else{if(e){o.blur()}}}function z(){r.oneTime(10,function(){o.val(g);if(T){r.oneTime(10,function(){o.caret(C)})}})}if(b&&!k){j=function(e){if(e){R.addClass("blink")}else{R.removeClass("blink")}}}else{var I=false;j=function(e){if(e&&!I){I=true;R.addClass("inverted blink");r.everyTime(500,"blink",N)}else if(I&&!e){I=false;r.stopTime("blink",N);R.removeClass("inverted blink")}}}function N(e){R.toggleClass("inverted")}function K(){S="(reverse-i-search)`"+c+"': ";W()}function L(){S=h;f=false;u=null;c=""}function P(n){var t=A.data();var i,o;var a=t.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(t[l])){u=t.length-l;r.position(t[l].indexOf(o));r.set(t[l],true);H();if(c.length!==s){c=c.substring(0,s);K()}return}}}}c=""}function D(){var e=r.width();var n=R[0].getBoundingClientRect().width;a=Math.floor(e/n)}function B(e){var n=e.substring(0,a-s);var t=e.substring(a-s);return[n].concat(p(t,a))}var H=function(n){var t=R.prev();var r=R.next();function i(n,i){var o=n.length;if(i===o){t.html(e.terminal.encode(n));R.html("&nbsp;");r.html("")}else if(i===0){t.html("");R.html(e.terminal.encode(n.slice(0,1)));r.html(e.terminal.encode(n.slice(1)))}else{var a=n.slice(0,i);t.html(e.terminal.encode(a));var s=n.slice(i,i+1);R.html(e.terminal.encode(s));if(i===n.length-1){r.html("")}else{r.html(e.terminal.encode(n.slice(i+1)))}}}function o(n){return"<div>"+e.terminal.encode(n)+"</div>"}function l(n){var t=r;e.each(n,function(n,r){t=e(o(r)).insertAfter(t).addClass("clear")})}function f(n){e.each(n,function(e,n){t.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();t.html("");if(c.length>a-s-1||c.match(/\n/)){var v;var y=c.match(/\t/g);var w=y?y.length*3:0;if(y){c=c.replace(/\t/g,"\x00\x00\x00\x00")}if(c.match(/\n/)){var _=c.split("\n");d=a-s-1;for(h=0;h<_.length-1;++h){_[h]+=" "}if(_[0].length>d){v=[_[0].substring(0,d)];u=_[0].substring(d);v=v.concat(p(u,a))}else{v=[_[0]]}for(h=1;h<_.length;++h){if(_[h].length>a){v=v.concat(p(_[h],a))}else{v.push(_[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){t.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){t.before(o(v[0]));i(v[1],0);l(v.slice(2))}else{var x=v.slice(-1)[0];var S=c.length-C-w;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]);t.before("<div>"+u+"</div>");i(v[1],C-d-1);u=e.terminal.encode(v[2]);r.after('<div class="clear">'+u+"</div>")}else{var E;var A;F=C;for(h=0;h<v.length;++h){var j=v[h].length;if(F>j){F-=j}else{break}}A=v[h];E=h;if(F===A.length){F=0;A=v[++E]}i(A,F);f(v.slice(0,E));l(v.slice(E+1))}}}}}else{if(c===""){t.html("");R.html("&nbsp;");r.html("")}else{i(c,C)}}}}(r);var W=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 q(e){if($++>0){return}if(e.originalEvent){e=e.originalEvent}if(r.isenabled()){var n=r.find("textarea");if(!n.is(":focus")){n.focus()}r.oneTime(100,function(){r.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(t.keydown)){a=t.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)){L();W();if(i.which===27){r.set("")}H();G.call(this,i)}else if(i.altKey){if(i.which===68){r.set(g.slice(0,C)+g.slice(C).replace(/ *[^ ]+ *(?= )|[^ ]+$/,""),true);return false}return true}else if(i.keyCode===13){if(i.shiftKey){r.insert("\n")}else{if(A&&g&&!m&&(e.isFunction(t.historyFilter)&&t.historyFilter(g))||t.historyFilter instanceof RegExp&&g.match(t.historyFilter)||!t.historyFilter){A.append(g)}var u=g;A.reset();r.set("");if(t.commands){t.commands(u)}if(e.isFunction(S)){W()}e(".clipboard").val("")}}else if(i.which===8){if(f){c=c.slice(0,-1);K()}else{if(g!==""&&C>0){r["delete"](-1)}}if(x){return true}}else if(i.which===67&&i.ctrlKey&&i.shiftKey){w=J()}else if(i.which===86&&i.ctrlKey&&i.shiftKey){if(w!==""){r.insert(w)}}else if(i.which===9&&!(i.ctrlKey||i.altKey)){r.insert(" ")}else if(i.which===46){r["delete"](1);return}else if(A&&(i.which===38&&!i.ctrlKey)||i.which===80&&i.ctrlKey){if(M){y=g;r.set(A.current())}else{r.set(A.previous())}M=false}else if(A&&(i.which===40&&!i.ctrlKey)||i.which===78&&i.ctrlKey){r.set(A.end()?y:A.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}}r.position(s)}else{if(C>0){r.position(-1,true);H()}}}else if(i.which===82&&i.ctrlKey){if(f){P(true)}else{h=S;K();y=g;r.set("");H();f=true}}else if(i.which==71&&i.ctrlKey){if(f){S=h;W();r.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+$/)){r.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){r.position(1,true)}}}else if(i.which===123){return}else if(i.which===36){r.position(0)}else if(i.which===35){r.position(g.length)}else if(i.shiftKey&&i.which==45){o.val("");$=0;if(!v){q(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(/([^ ]+ *$)/);_=r["delete"](-k[0].length)}return false}else if(i.which===72){if(g!==""&&C>0){r["delete"](-1)}return false}else if(i.which===65){r.position(0)}else if(i.which===69){r.position(g.length)}else if(i.which===88||i.which===67||i.which===84){return}else if(i.which===89){if(_!==""){r.insert(_)}}else if(i.which===86||i.which===118){o.val("");$=0;if(!v){q(i)}else{o.focus();o.on("input",function F(e){q(e);o.off("input",F)})}return}else if(i.which===75){_=r["delete"](g.length-C)}else if(i.which===85){if(g!==""&&C!==0){_=r["delete"](-C)}}else if(i.which===17){return false}}}else{U=false;Y=true;return}i.preventDefault()}}function Q(){if(e.isFunction(t.onCommandChange)){t.onCommandChange(g)}}e.extend(r,{name:function(e){if(e!==n){E=e;var i=A&&A.enabled()||!A;A=new d(e,F,t.history=="memory");if(!i){A.disable()}return r}else{return E}},purge:function(){A.clear();return r},history:function(){return A},"delete":function(e,n){var t;if(e===0){return r}else if(e<0){if(C>0){t=g.slice(0,C).slice(e);g=g.slice(0,C+e)+g.slice(C,g.length);if(!n){r.position(C+e)}else{Q()}}}else{if(g!==""&&C<g.length){t=g.slice(C).slice(0,e);g=g.slice(0,C)+g.slice(C+e,g.length);Q()}}H();z();return t},set:function(e,t){if(e!==n){g=e;if(!t){r.position(g.length)}H();z();Q()}return r},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){r.position(e.length,true)}else{z()}H();Q();return r},get:function(){return g},commands:function(e){if(e){t.commands=e;return r}else{return e}},destroy:function(){Z.unbind("keypress.cmd",V);Z.unbind("keydown.cmd",G);Z.unbind("paste.cmd",q);Z.unbind("input.cmd",ee);r.stopTime("blink",N);r.find(".cursor").next().remove().end().prev().remove().end().remove();r.find(".prompt, .clipboard").remove();r.removeClass("cmd").removeData("cmd");return r},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")}W();H();return r}},kill_text:function(){return _},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(t.onPositionChange)){t.onPositionChange(C)}H();z();return r}else{return C}},visible:function(){var e=r.visible;return function(){e.apply(r,[]);H();W()}}(),show:function(){var e=r.show;return function(){e.apply(r,[]);H();W()}}(),resize:function(e){if(e){a=e}else{D()}H();return r},enable:function(){T=true;r.addClass("enabled");o.caret(C);j(true);O();return r},isenabled:function(){return T},disable:function(){T=false;r.removeClass("enabled");j(false);O();return r},mask:function(e){if(typeof e==="undefined"){return m}else{m=e;H();return r}}});r.name(t.name||t.prompt||"");if(typeof t.prompt=="string"){S=t.prompt}else{S="> "}W();if(t.enabled===n||t.enabled===true){r.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(t.keypress)){o=t.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);P();K()}else{r.insert(String.fromCharCode(i.which))}return false}}}else{return o}}function ee(e){if(Y){var n=o.val();if(n||e.which==8){r.set(n)}}}Z.bind("keypress.cmd",V).bind("keydown.cmd",G).bind("input.cmd",ee);r.data("cmd",r);return r};function w(n){return e("<div>"+e.terminal.strip(n)+"</div>").text().length}function _(e){return e.length-w(e)}var b=function(){var e=false,t="animation",r="",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];t=o+"Animation";r="-"+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,t){var r=t(n);if(r.length){var i=r.shift();var o=new RegExp("^"+e.terminal.escape_regex(i));var a=n.replace(o,"").trim();return{command:n,name:i,args:r,rest:a}}else{return{command:n,name:"",args:[],rest:""}}}var S=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?)/i;var T=/\[\[([!gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var F=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var E=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]/gi;var A=/^\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]$/gi;var R=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;var j=/(\bhttps?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\]\[)])+\b)/gi;var $=/\b(https?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\][)])+)\b(?![^[\]]*])/gi;var O=/((([^<>('")[\]\\.,;:\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 I=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var N=/^(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var K=/\[\[[!gbiuso]*;[^;]*;[^\]]*\]?$/i;var L=/(\[\[(?:[^\]]|\\\])*\]\])/;e.terminal={version:"0.11.23",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(R)){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(E)},is_formatting:function(e){return typeof e=="string"&&!!e.match(A)},format_split:function(e){return e.split(S)},split_equal:function(n,t,r){var i=false;var o=false;var a="";var s=[];var l=n.replace(F,function(e,n,t){var r=n.match(/;/g).length;if(r>=4){return e}else if(r==2){r=";;"}else if(r==3){r=";"}else{r=""}var i=t.replace(/\\\]/g,"&#93;").replace(/\n/g,"\\n").replace(/&nbsp;/g," ");return"[["+n+r+i+"]"+t+"]"}).split(/\n/g);function f(){return h.substring(d-6,d)=="&nbsp;"||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(N)){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(w+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===t||d===v-1)&&(i&&o||!i)){var w;var _=e.terminal.strip(h.substring(g));_=e("<span>"+_+"</span>").text();var b=_.length;_=_.substring(0,d+t+1);var k=!!_.match(/\s/)||d+t+1>b;if(r&&g!=-1&&d!==v-1&&k){w=h.substring(p,g);d=g-1}else{w=h.substring(p,d+1)}if(r){w=w.replace(/(&nbsp;|\s)+$/g,"")}g=-1;p=d+1;m=0;if(a){w=a+w;if(w.match("]")){a=""}}var x=w.match(F);if(x){var C=x[x.length-1];if(C[C.length-1]!=="]"){a=C.match(I)[1];w+="]"}else if(w.match(K)){var S=w.length;w=w.replace(K,"");a=C.match(I)[1]}}s.push(w)}}}return s},encode:function(e){e=e.replace(/&(?!#[0-9]+;|[a-zA-Z]+;)/g,"&amp;");return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")},escape_formatting:function(n){return e.terminal.escape_brackets(e.terminal.encode(n))},format:function(n,t){var r=e.extend({},{linksNoReferrer:false},t||{});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(/&nbsp;/g," ")});return n.replace(T,function(n,t,i,o,a,s,l){if(l===""){return""}l=l.replace(/\\]/g,"]");var f="";if(t.indexOf("b")!==-1){f+="font-weight:bold;"}var c=[];if(t.indexOf("u")!==-1){c.push("underline")}if(t.indexOf("s")!==-1){c.push("line-through")}if(t.indexOf("o")!==-1){c.push("overline")}if(c.length){f+="text-decoration:"+c.join(" ")+";"}if(t.indexOf("i")!==-1){f+="font-style:italic;"}if(e.terminal.valid_color(i)){f+="color:"+i+";";if(t.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(/&#93;/g,"]")}var h;if(t.indexOf("!")!==-1){if(u.match(O)){h='<a href="mailto:'+u+'" '}else{h='<a target="_blank" href="'+u+'" ';if(r.linksNoReferrer){h+='rel="noreferrer" '}}}else{h="<span"}if(f!==""){h+=' style="'+f+'"'}if(a!==""){h+=' class="'+a+'"'}if(t.indexOf("!")!==-1){h+=">"+l+"</a>"}else{h+=' data-text="'+u.replace('"',"&quote;")+'">'+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,"&#91;").replace(/\]/g,"&#93;")},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 t=/^[-+]?[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(t)){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{ne=false;e.exec(n,true).then(function(){ne=true})}catch(t){}}};e.fn.visible=function(){return this.css("visibility","visible")};e.fn.hidden=function(){return this.css("visibility","hidden")};var P={};e.jrpc=function(n,t,r,i,o){P[n]=P[n]||0;var a=JSON.stringify({jsonrpc:"2.0",method:t,params:r,id:++P[n]});return e.ajax({url:n,data:a,success:function(n,t,r){var a=r.getResponseHeader("Content-Type");if(!a.match(/(application|text)\/json/)){var s="Response Content-Type is neither application/json nor text/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(r,"Invalid JSON",f)}else{throw new Error("Invalid JSON")}return}i(l,t,r)},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">&nbsp;</span></div></div>').appendTo("body");var t=n.find("span");var r={width:t.width(),height:t.outerHeight()};n.remove();return r}function B(n){var t=e('<div class="terminal wrap"><span class="cursor">'+"&nbsp;</span></div>").appendTo("body").css("padding",0);var r=t.find("span");var i=r[0].getBoundingClientRect().width;var o=Math.floor(n.width()/i);t.remove();if(W(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 J(){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 W(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 q=!e.terminal.version.match(/^\{\{/);var M="Copyright (c) 2011-2016 Jakub Jankiewicz <http://jcubic"+".pl>";var U=q?" v. "+e.terminal.version:" ";var Y=new RegExp(" {"+U.length+"}$");var G="jQuery Terminal Emulator"+(q?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:"*",wrap:true,checkArity:true,raw:false,exceptionHandler:null,memory:false,cancelableAjax:true,processArguments:true,linksNoReferrer:false,processRPCResponse:null,Token:true,convertLinks:true,historyState:false,echoCommand:true,scrollOnEcho:true,login:null,outputLimit:-1,formatters:[],onAjaxError:null,scrollBottomOffset:20,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 ee;var ne=false;var te=true;var re=true;var ie;e.fn.terminal=function(t,i){function o(n){if(n){this.storage={}}this.set=function(t,r){if(n){this.storage[t]=r}else{e.Storage.set(t,r)}};this.get=function(t){if(n){return this.storage[t]}else{return e.Storage.get(t)}};this.remove=function(t){if(n){delete this.storage[t]}else{e.Storage.remove(t)}}}function a(n){if(e.isFunction(Ee.processArguments)){return C(n,Ee.processArguments)}else if(Ee.processArguments){return e.terminal.parse_command(n)}else{return e.terminal.split_command(n)}}function s(n){if(typeof n==="string"){le.echo(n)}else if(n instanceof Array){le.echo(e.map(n,function(e){return JSON.stringify(e)}).join(" "))}else if(typeof n==="object"){le.echo(JSON.stringify(n))}else{le.echo(n)}}function l(n){var t=/(.*):([0-9]+):([0-9]+)$/;var r=n.match(t);if(r){le.pause();e.get(r[1],function(n){var t=location.href.replace(/[^\/]+$/,"");var i=r[1].replace(t,"");le.echo("[[b;white;]"+i+"]");var o=n.split("\n");var a=+r[2]-1;le.echo(o.slice(a-2,a+3).map(function(n,t){if(t==2){n="[[;#f00;]"+e.terminal.escape_brackets(n)+"]"}return"["+(a+t)+"]: "+n}).join("\n")).resume()},"text")}}function f(n){if(e.isFunction(Ee.onRPCError)){Ee.onRPCError.call(le,n)}else{le.error("&#91;RPC&#93; "+n.message);if(n.error&&n.error.message){n=n.error;var t=" "+n.message;if(n.file){t+=' in file "'+n.file.replace(/.*\//,"")+'"'}if(n.at){t+=" at line "+n.at}le.error(t)}}}function c(n,t){var r=function(t,r){le.pause();e.jrpc(n,t,r,function(n){if(n.error){f(n.error)}else{if(e.isFunction(Ee.processRPCResponse)){Ee.processRPCResponse.call(le,n.result,le)}else{s(n.result)}}le.resume()},h)};return function(e,n){if(e===""){return}try{e=a(e)}catch(i){n.error(i.toString());return}if(!t||e.name==="help"){r(e.name,e.args)}else{var o=n.token();if(o){r(e.name,[o].concat(e.args))}else{n.error("&#91;AUTH&#93; "+Re.noTokenError)}}}}function u(t,r,i,o){return function(s,l){if(s===""){return}var f;try{f=a(s)}catch(c){le.error(c.toString());return}var h=t[f.name];var p=e.type(h);if(p==="function"){if(r&&h.length!==f.args.length){le.error("&#91;Arity&#93; "+sprintf(Re.wrongArity,f.name,h.length,f.args.length))}else{return h.apply(le,f.args)}}else if(p==="object"||p==="string"){var m=[];if(p==="object"){m=Object.keys(h);h=u(h,r,i)}l.push(h,{prompt:f.name+"> ",name:f.name,completion:p==="object"?m:n})}else{if(e.isFunction(o)){o(s,le)}else if(e.isFunction(Ee.onCommandNotFound)){Ee.onCommandNotFound(s,le)}else{l.error(sprintf(Re.commandNotFound,f.name))}}}}function h(n,t,r){le.resume();if(e.isFunction(Ee.onAjaxError)){Ee.onAjaxError.call(le,n,t,r)}else if(t!=="abort"){le.error("&#91;AJAX&#93; "+t+" - "+Re.serverResponse+": \n"+e.terminal.escape_brackets(n.responseText))}}function p(n,t,r){e.jrpc(n,"system.describe",[],function(i){var o=[];if(i.procs){var a={};e.each(i.procs,function(r,i){a[i.name]=function(){var r=t&&i.name!="help";var o=Array.prototype.slice.call(arguments);var a=o.length+(r?1:0);if(Ee.checkArity&&i.params&&i.params.length!==a){le.error("&#91;Arity&#93; "+sprintf(Re.wrongArity,i.name,i.params.length,a))}else{le.pause();if(r){var l=le.token(true);if(l){o=[l].concat(o)}else{le.error("&#91;AUTH&#93; "+Re.noTokenError)}}e.jrpc(n,i.name,o,function(n){if(n.error){f(n.error)}else{if(e.isFunction(Ee.processRPCResponse)){Ee.processRPCResponse.call(le,n.result,le)}else{s(n.result)}}le.resume()},h)}}});a.help=a.help||function(n){if(typeof n=="undefined"){le.echo("Available commands: "+i.procs.map(function(e){return e.name}).join(", ")+", help")}else{var t=false;e.each(i.procs,function(e,r){if(r.name==n){t=true;var i="";i+="[[bu;#fff;]"+r.name+"]";if(r.params){i+=" "+r.params.join(" ")}if(r.help){i+="\n"+r.help}le.echo(i);return false}});if(!t){if(n=="help"){le.echo("[[bu;#fff;]help] [method]\ndisplay help "+"for the method or list of methods if not"+" specified")}else{var r="Method `"+n.toString()+"' not found ";le.error(r)}}}};r(a)}else{r(null)}},function(){r(null)})}function m(n,t,r){r=r||e.noop;var i=e.type(n);var o;var a={};var s=0;var l;if(i==="array"){o={};(function f(n,r){if(n.length){var i=n[0];var a=n.slice(1);var u=e.type(i);if(u==="string"){s++;le.pause();if(Ee.ignoreSystemDescribe){if(s===1){l=c(i,t)}else{le.error(Re.oneRPCWithIgnore)}f(a,r)}else{p(i,t,function(n){if(n){e.extend(o,n)}le.resume();f(a,r)})}}else if(u==="function"){if(l){le.error(Re.oneInterpreterFunction)}else{l=i}f(a,r)}else if(u==="object"){e.extend(o,i);f(a,r)}}else{r()}})(n,function(){r({interpreter:u(o,false,t,l),completion:Object.keys(o)})})}else if(i==="string"){if(Ee.ignoreSystemDescribe){o={interpreter:c(n,t)};if(e.isArray(Ee.completion)){o.completion=Ee.completion}r(o)}else{le.pause();p(n,t,function(e){if(e){a.interpreter=u(e,false,t);a.completion=Object.keys(e)}else{a.interpreter=c(n,t)}r(a);le.resume()})}}else if(i==="object"){r({interpreter:u(n,Ee.checkArity),completion:Object.keys(n)})}else{if(i==="undefined"){n=e.noop}else if(i!=="function"){throw i+" is invalid interpreter value"}r({interpreter:n,completion:Ee.completion})}}function d(n,t){var r=e.type(t)==="boolean"?"login":t;return function(t,i,o,a){le.pause();e.jrpc(n,r,[t,i],function(e){if(!e.error&&e.result){o(e.result)}else{o(null)}le.resume()},h)}}function v(e){if(typeof e==="string"){return e}else if(typeof e.fileName==="string"){return e.fileName+": "+e.message}else{return e.message}}function y(n,t){if(e.isFunction(Ee.exceptionHandler)){Ee.exceptionHandler.call(le,n)}else{le.exception(n,t)}}function w(){var e;if(fe.prop){e=fe.prop("scrollHeight")}else{e=fe.attr("scrollHeight")}fe.scrollTop(e)}function _(n,t){try{if(e.isFunction(t)){t(function(){})}else if(typeof t!=="string"){var r=n+" must be string or function";throw r}}catch(i){y(i,n.toUpperCase());return false}return true}var b=[];var k=1;function S(t,r){if(Ee.convertLinks&&!r.raw){t=t.replace(O,"[[!;;]$1]").replace($,"[[!;;]$1]")}var i=e.terminal.defaults.formatters;var o,a;if(!r.raw){for(o=0;o<i.length;++o){try{if(typeof i[o]=="function"){var s=i[o](t);if(typeof s=="string"){t=s}}}catch(l){alert("formatting error at formatters["+o+"]\n"+(l.stack?l.stack:l))}}t=e.terminal.encode(t)}b.push(k);if(!r.raw&&(t.length>de||t.match(/\n/))&&(Ee.wrap===true&&r.wrap===n||Ee.wrap===false&&r.wrap===true)){var f=r.keepWords;var c=e.terminal.split_equal(t,de,f);for(o=0,a=c.length;o<a;++o){if(c[o]===""||c[o]==="\r"){b.push("<span></span>")}else{if(r.raw){b.push(c[o])}else{b.push(e.terminal.format(c[o],{linksNoReferrer:Ee.linksNoReferrer}))}}}}else if(!r.raw){t=e.terminal.format(t,{linksNoReferrer:Ee.linksNoReferrer});t.split(/\n/).forEach(function(e){b.push(e)})}else{b.push(t)}b.push(r.finalize)}function T(n,t){try{var r=e.extend({exec:true,raw:false,finalize:e.noop},t||{});var i=e.type(n)==="function"?n():n;i=e.type(i)==="string"?i:String(i);if(i!==""){if(r.exec){i=e.map(i.split(L),function(n){if(n.match(L)&&!e.terminal.is_formatting(n)){n=n.replace(/^\[\[|\]\]$/g,"");if(ce&&ce.command==n){le.error(Re.recursiveCall)}else{e.terminal.extended_command(le,n)}return""}else{return n}}).join("");if(i!==""){S(i,r)}}else{S(i,r)}}}catch(o){b=[];alert("[Internal Exception(process_line)]:"+v(o)+"\n"+o.stack)}}function F(){Je.resize(de);var n=me.empty().detach();var t;if(Ee.outputLimit>=0){var r=Ee.outputLimit===0?le.rows():Ee.outputLimit;t=pe.slice(pe.length-r-1)}else{t=pe}try{b=[];e.each(t,function(e,n){T.apply(null,n)});Je.before(n);le.flush()}catch(i){alert("Exception in redraw\n"+i.stack)}}function E(){if(Ee.greetings===n){le.echo(le.signature)}else if(Ee.greetings){var e=typeof Ee.greetings;if(e==="string"){le.echo(Ee.greetings)}else if(e==="function"){Ee.greetings.call(le,le.echo)}else{le.error(Re.wrongGreetings)}}}function A(n){var t=Je.prompt();var r=Je.mask();switch(typeof r){case"string":n=n.replace(/./g,r);break;case"boolean":if(r){n=n.replace(/./g,Ee.maskChar)}else{n=e.terminal.escape_formatting(n)}break}var i={finalize:function(e){e.addClass("command")}};if(e.isFunction(t)){t(function(e){le.echo(e+n,i)})}else{le.echo(t+n,i)}}function R(e){var n=Z.get()[e[0]];if(!n){throw new Error(Re.invalidTerminalId)}var t=e[1];if(V[t]){n.import_view(V[t])}else{ne=false;var r=e[2];if(r){n.exec(r).then(function(){ne=true;V[t]=n.export_view()})}}}function z(){if(ne){te=false;location.hash="#"+JSON.stringify(ee);setTimeout(function(){te=true},100)}}var I=true;var N;var K=[];var P=false;function D(t,r,i){N=t;if(I){I=false;if(Ee.historyState||Ee.execHash&&i){if(!V.length){le.save_state()}else{le.save_state(null)}}}function o(){if(!i){ne=true;if(Ee.historyState){le.save_state(t,false)}ne=f}l.resolve();if(e.isFunction(Ee.onAfterCommand)){Ee.onAfterCommand(le,t)}}try{if(e.isFunction(Ee.onBeforeCommand)){if(Ee.onBeforeCommand(le,t)===false){return}}if(!i){ce=e.terminal.split_command(t)}if(!ae()){if(i&&(e.isFunction(Ee.historyFilter)&&Ee.historyFilter(t)||t.match(Ee.historyFilter))){Je.history().append(t)}}var a=He.top();if(!r&&Ee.echoCommand){A(t)}var l=new e.Deferred;var f=ne;if(t.match(/^\s*login\s*$/)&&le.token(true)){if(le.level()>1){le.logout(true)}else{le.logout()}o()}else if(Ee.exit&&t.match(/^\s*exit\s*$/)&&!xe){var c=le.level();if(c==1&&le.get_token()||c>1){if(le.get_token(true)){le.set_token(n,true)}le.pop()}o()}else if(Ee.clear&&t.match(/^\s*clear\s*$/)&&!xe){le.clear();o()}else{var u=pe.length-1;var h=a.interpreter.call(le,t,le);if(h!==n){le.pause(true);return e.when(h).then(function(e){if(e&&u===pe.length-1){s(e)}o();le.resume()})}else if(Oe){var p=t;K.push(function(){o()})}else{o()}}return l.promise()}catch(m){y(m,"USER");le.resume();throw m}}function q(){if(e.isFunction(Ee.onBeforeLogout)){try{if(Ee.onBeforeLogout(le)===false){return}}catch(n){y(n,"onBeforeLogout")}}M();if(e.isFunction(Ee.onAfterLogout)){try{Ee.onAfterLogout(le)}catch(n){y(n,"onAfterlogout")}}le.login(Ee.login,true,ie)}function M(){var e=le.prefix_name(true)+"_";Ae.remove(e+"token");Ae.remove(e+"login")}function U(n){var t=le.prefix_name()+"_interpreters";var r=Ae.get(t);if(r){r=e.parseJSON(r)}else{r=[]}if(e.inArray(n,r)==-1){r.push(n);Ae.set(t,JSON.stringify(r))}}function Y(n){var t=He.top();var r=le.prefix_name(true);if(!ae()){U(r)}Je.name(r);if(e.isFunction(t.prompt)){Je.prompt(function(e){t.prompt(e,le)})}else{Je.prompt(t.prompt)}Je.set("");if(!n&&e.isFunction(t.onStart)){t.onStart(le)}}var G;function ie(){Y();E();var n=false;if(e.isFunction(Ee.onInit)){Ce=function(){n=true};try{Ee.onInit(le)}catch(t){y(t,"OnInit")}finally{Ce=e.noop;if(!n){le.resume()}}}function r(){if(te&&Ee.execHash){try{if(location.hash){var n=location.hash.replace(/^#/,"");ee=e.parseJSON(decodeURIComponent(n))}else{ee=[]}if(ee.length){R(ee[ee.length-1])}else if(V[0]){le.import_view(V[0])}}catch(t){y(t,"TERMINAL")}}}if(re){re=false;if(e.fn.hashchange){e(window).hashchange(r)}else{e(window).bind("hashchange",r)}}}function oe(n,t,r){if(Ee.clear&&e.inArray("clear",r)==-1){r.push("clear")}if(Ee.exit&&e.inArray("exit",r)==-1){r.push("exit")}var i=Je.get().substring(0,Je.position());if(i!==n){return}var o=new RegExp("^"+e.terminal.escape_regex(t));var a=[];for(var s=r.length;s--;){if(o.test(r[s])){a.push(r[s])}}if(a.length===1){le.insert(a[0].replace(o,""))}else if(a.length>1){if(he>=2){A(n);var l=a.reverse().join(" ");le.echo(e.terminal.escape_brackets(l),{keepWords:true});he=0}else{var f=false;var c;var u;e:for(u=t.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){le.insert(a[0].slice(0,u).replace(o,""))}}}}function ae(){return xe||Je.mask()!==false}function se(t){var r,i,o=He.top(),a;if(!le.paused()&&le.enabled()){if(e.isFunction(o.keydown)){r=o.keydown(t,le);if(r!==n){return r}}else if(e.isFunction(Ee.keydown)){r=Ee.keydown(t,le);if(r!==n){return r}}if(Ee.completion&&e.type(Ee.completion)!="boolean"&&o.completion===n){a=Ee.completion}else{a=o.completion}if(a=="settings"){a=Ee.completion}le.oneTime(10,function(){Ie()});if(t.which!==9){he=0}if(t.which===68&&t.ctrlKey){if(!xe){if(Je.get()===""){if(He.size()>1||Ee.login!==n){le.pop("")}else{le.resume();le.echo("")}}else{le.set_command("")}}return false}else if(t.which===76&&t.ctrlKey){le.clear()}else if(a&&t.which===9){++he;var s=Je.position();var l=Je.get().substring(0,s);var f=l.split(" ");var c;if(Re.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(le,c,function(e){oe(l,c,e)});break;case"array":oe(l,c,a);break;default:throw new Error(Re.invalidCompletion)}return false}else if((t.which===118||t.which===86)&&(t.ctrlKey||t.metaKey)){le.oneTime(1,function(){w()});return}else if(t.which===9&&t.ctrlKey){if(Z.length()>1){le.focus(false);return false}}else if(t.which===34){le.scroll(le.height())}else if(t.which===33){le.scroll(-le.height())}else{le.attr({scrollTop:le.attr("scrollHeight")})}}else if(t.which===68&&t.ctrlKey){if(X.length){for(i=X.length;i--;){var u=X[i];if(4!==u.readyState){try{u.abort()}catch(h){le.error(Re.ajaxAbortError)}}}X=[];le.resume()}return false}}var le=this;if(this.length>1){return this.each(function(){e.fn.terminal.call(e(this),t,e.extend({name:le.selector},i))})}if(le.data("terminal")){return le.data("terminal")}if(le.length===0){throw sprintf(e.terminal.defaults.strings.invalidSelector,le.selector)}var fe;var ce;var ue=false;var he=0;var pe=[];var me;var ge=Z.length();var de;var ve;var ye=[];var we;var _e;var be=new g;var ke=e.Deferred();var xe=false;var Ce=e.noop;var Se,Te;var Fe=[];var Ee=e.extend({},e.terminal.defaults,{name:le.selector},i||{});var Ae=new o(Ee.memory);var Re=e.terminal.defaults.strings;var je=Ee.enabled,$e=false;var Oe=false;var ze=true;e.extend(le,e.omap({id:function(){return ge},clear:function(){me.html("");pe=[];try{Ee.onClear(le)}catch(e){y(e,"onClear")}le.attr({scrollTop:0});return le},export_view:function(){var n={};if(e.isFunction(Ee.onExport)){try{n=Ee.onExport()}catch(t){y(t,"onExport")}}return e.extend({},{focus:je,mask:Je.mask(),prompt:le.get_prompt(),command:le.get_command(),position:Je.position(),lines:r(pe),interpreters:He.clone()},n)},import_view:function(n){if(xe){throw new Error(sprintf(Re.notWhileLogin,"import_view"))}if(e.isFunction(Ee.onImport)){try{Ee.onImport(n)}catch(t){y(t,"onImport")}}ke.then(function(){le.set_prompt(n.prompt);le.set_command(n.command);Je.position(n.position);Je.mask(n.mask);if(n.focus){le.focus()}pe=r(n.lines);He=n.interpreters;F()});return le},save_state:function(t,r,i){if(typeof i!="undefined"){V[i]=le.export_view()}else{V.push(le.export_view())}if(!e.isArray(ee)){ee=[]}if(t!==n&&!r){var o=[ge,V.length-1,t];ee.push(o);z()}},exec:function(n,t,r){var i=r||new e.Deferred;function o(){if(e.isArray(n)){(function r(){var e=n.shift();if(e){le.exec(e,t).then(r)}else{i.resolve()}})()}else if(Oe){Fe.push([n,t,i])}else{D(n,t,true).then(function(){i.resolve(le)})}}if(ke.state()!="resolved"){ke.then(o)}else{o()}return i.promise()},autologin:function(e,n,t){le.trigger("terminal.autologin",[e,n,t]);return le},login:function(n,t,r,i){be.push([].slice.call(arguments));if(xe){throw new Error(sprintf(Re.notWhileLogin,"login"))}if(!e.isFunction(n)){throw new Error(Re.loginIsNotAFunction)}xe=true;if(le.token()&&le.level()==1&&!ze){xe=false;le.logout(true)}else{if(le.token(true)&&le.login_name(true)){xe=false;if(e.isFunction(r)){r()}return le}}var o=null;if(Ee.history){Je.history().disable()}var a=le.level();function s(n,o,s,l){if(o){while(le.level()>a){le.pop()}if(Ee.history){Je.history().enable()}var f=le.prefix_name(true)+"_";Ae.set(f+"token",o);Ae.set(f+"login",n);xe=false;if(e.isFunction(r)){r()}}else{if(t){if(!s){le.error(Re.wrongPasswordTryAgain)}le.pop().set_mask(false)}else{xe=false;if(!s){le.error(Re.wrongPassword)}le.pop().pop()}if(e.isFunction(i)){i()}}le.off("terminal.autologin")}le.on("terminal.autologin",function(e,n,t,r){s(n,t,r)});le.push(function(e){le.set_mask(Ee.maskChar).push(function(t){try{n.call(le,e,t,function(n,t){s(e,n,t)})}catch(r){y(r,"AUTH")}},{prompt:Re.password+": ",name:"password"})},{prompt:Re.login+": ",name:"login"});return le},settings:function(){return Ee},commands:function(){return He.top().interpreter},setInterpreter:function(){if(window.console&&console.warn){console.warn("This function is deprecated, use set_inte"+"rpreter insead!")}return le.set_interpreter.apply(le,arguments)},set_interpreter:function(n,t){function r(){le.pause();m(n,!!t,function(n){le.resume();var t=He.top();e.extend(t,n);Y(true)})}if(e.type(n)=="string"&&t){le.login(d(n,t),true,r)}else{r()}return le},greetings:function(){E();return le},paused:function(){return Oe},pause:function(n){Ce();if(!Oe&&Je){ke.then(function(){Oe=true;Je.disable();if(!n){Je.hidden()}if(e.isFunction(Ee.onPause)){Ee.onPause()}})}return le},resume:function(){function n(){Oe=false;if(Z.front()==le){Je.enable()}Je.visible();var n=Fe;Fe=[];for(var t=0;t<n.length;++t){le.exec.apply(le,n[t])}le.trigger("resume");var r=K.shift();if(r){r()}w();if(e.isFunction(Ee.onResume)){Ee.onResume()}}if(Oe&&Je){if(ke.state()!="resolved"){ke.then(n)}else{n()}}return le},cols:function(){return Ee.numChars?Ee.numChars:B(le)},rows:function(){return Ee.numRows?Ee.numRows:H(le)},history:function(){return Je.history()},history_state:function(e){if(e){le.oneTime(1,function(){Ee.historyState=true;if(!V.length){le.save_state()}else if(Z.length()>1){le.save_state(null)}})}else{Ee.historyState=false}return le},clear_history_state:function(){ee=[];V=[];return le},next:function(){if(Z.length()===1){return le}else{var n=le.offset().top;var t=le.height();var r=le.scrollTop();Z.front().disable();var i=Z.rotate().enable();var o=i.offset().top-50;e("html,body").animate({scrollTop:o},500);try{Ee.onTerminalChange(i)}catch(a){y(a,"onTerminalChange")}return i}},focus:function(e,n){ke.then(function(){if(Z.length()===1){if(e===false){try{if(!n&&Ee.onBlur(le)!==false||n){le.disable()}}catch(t){y(t,"onBlur")}}else{try{if(!n&&Ee.onFocus(le)!==false||n){le.enable()}}catch(t){y(t,"onFocus")}}}else{if(e===false){le.next()}else{var r=Z.front();if(r!=le){r.disable();if(!n){try{Ee.onTerminalChange(le)}catch(t){y(t,"onTerminalChange")}}}Z.set(le);le.enable()}}});return le},freeze:function(e){ke.then(function(){if(e){le.disable();$e=true}else{$e=false;le.enable()}})},frozen:function(){return $e},enable:function(){if(!je&&!$e){if(de===n){le.resize()}ke.then(function(){Je.enable();je=true})}return le},disable:function(){if(je&&!$e){ke.then(function(){je=false;Je.disable()})}return le},enabled:function(){return je},signature:function(){var e=le.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 Je},get_command:function(){return Je.get()},set_command:function(e){ke.then(function(){Je.set(e)});return le},insert:function(e){if(typeof e==="string"){ke.then(function(){Je.insert(e)});return le}else{throw"insert function argument is not a string"}},set_prompt:function(n){ke.then(function(){if(_("prompt",n)){if(e.isFunction(n)){Je.prompt(function(e){n(e,le)})}else{Je.prompt(n)}He.top().prompt=n}});return le},get_prompt:function(){return He.top().prompt},set_mask:function(e){ke.then(function(){Je.mask(e===true?Ee.maskChar:e)});return le},get_output:function(n){if(n){return pe}else{return e.map(pe,function(n){return e.isFunction(n[0])?n[0]():n[0]}).join("\n")}},resize:function(n,t){if(!le.is(":visible")){le.stopTime("resize");le.oneTime(500,"resize",function(){le.resize(n,t)})}else{if(n&&t){le.width(n);le.height(t)}n=le.width();t=le.height();var r=le.cols();var i=le.rows();if(r!==de||i!==ve){de=r;ve=i;F();var o=He.top();if(e.isFunction(o.resize)){o.resize(le)}else if(e.isFunction(Ee.onResize)){Ee.onResize(le)}Te=t;Se=n;w()}}return le},flush:function(){try{var n=le.is_bottom();var t;e.each(b,function(n,r){if(r===k){t=e("<div></div>")}else if(e.isFunction(r)){t.appendTo(me);try{r(t)}catch(i){y(i,"USER:echo(finalize)")}}else{e("<div/>").html(r).appendTo(t).width("100%")}});if(Ee.outputLimit>=0){var r=Ee.outputLimit===0?le.rows():Ee.outputLimit;var i=me.find("div div");if(i.length>r){var o=i.length-r+1;var a=i.slice(0,o);var s=a.parent();a.remove();s.each(function(){var n=e(this);if(n.is(":empty")){n.remove()}})}}ve=H(le);Ie();if(Ee.scrollOnEcho||n){w()}b=[]}catch(l){alert("[Flush] "+v(l)+"\n"+l.stack)}return le},update:function(e,n){ke.then(function(){if(e<0){e=pe.length+e}if(!pe[e]){le.error("Invalid line number "+e)}else{if(n===null){pe.splice(e,1)}else{pe[e][0]=n}F()}});return le},last_index:function(){return pe.length-1},echo:function(n,t){n=n||"";e.when(n).then(function(n){try{var r=e.extend({flush:true,raw:Ee.raw,finalize:e.noop,keepWords:false},t||{});if(r.flush){b=[]}T(n,r);pe.push([n,e.extend(r,{exec:false})]);if(r.flush){le.flush()}}catch(i){alert("[Terminal.echo] "+v(i)+"\n"+i.stack)}});return le},error:function(n,t){var r=e.terminal.escape_brackets(n).replace(/\\$/,"&#92;").replace(j,"]$1[[;;;error]");return le.echo("[[;;;error]"+r+"]",t)},exception:function(n,t){var r=v(n);if(t){r="&#91;"+t+"&#93;: "+r}if(r){le.error(r,{finalize:function(e){e.addClass("exception message")}})}if(typeof n.fileName==="string"){le.pause();e.get(n.fileName,function(e){le.resume();var t=n.lineNumber-1;var r=e.split("\n")[t];if(r){le.error("["+n.lineNumber+"]: "+r)}})}if(n.stack){var i=e.terminal.escape_brackets(n.stack);le.echo(i.split(/\n/g).map(function(e){return"[[;;;error]"+e.replace(j,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(fe.prop){if(e>fe.prop("scrollTop")&&e>0){fe.prop("scrollTop",0)}n=fe.prop("scrollTop");fe.scrollTop(n+e)}else{if(e>fe.attr("scrollTop")&&e>0){fe.attr("scrollTop",0)}n=fe.attr("scrollTop");fe.scrollTop(n+e)}return le},logout:function(e){if(xe){throw new Error(sprintf(Re.notWhileLogin,"logout"))}ke.then(function(){if(e){var t=be.pop();le.set_token(n,true);le.login.apply(le,t)}else{while(He.size()>0){if(le.pop()){break}}}});return le},token:function(e){return Ae.get(le.prefix_name(e)+"_token")},set_token:function(e,n){var t=le.prefix_name(n)+"_token";if(typeof e=="undefined"){Ae.remove(t,e)}else{Ae.set(t,e)}return le},get_token:function(e){return Ae.get(le.prefix_name(e)+"_token")},login_name:function(e){return Ae.get(le.prefix_name(e)+"_login")},name:function(){return He.top().name},prefix_name:function(e){var n=(Ee.name?Ee.name+"_":"")+ge;if(e&&He.size()>1){var t=He.map(function(e){return e.name}).slice(1).join("_");if(t){n+="_"+t}}return n},read:function(n,t){var r=new e.Deferred;le.push(function(n){le.pop();if(e.isFunction(t)){t(n)}r.resolve(n)},{prompt:n});return r.promise()},push:function(t,r){ke.then(function(){r=r||{};var i={infiniteLogin:false};var o=e.extend({},i,r);if(!o.name&&ce){o.name=ce.name}if(o.prompt===n){o.prompt=(o.name||">")+" "}var a=He.top();if(a){a.mask=Je.mask()}var s=Oe;m(t,!!r.login,function(n){He.push(e.extend({},n,o));if(e.isArray(n.completion)&&o.completion===true){He.top().completion=n.completion}else if(!n.completion&&o.completion===true){He.top().completion=false}if(o.login){var r=e.type(o.login);if(r=="function"){le.login(o.login,o.infiniteLogin,Y,o.infiniteLogin?e.noop:le.pop)}else if(e.type(t)=="string"&&r=="string"||r=="boolean"){le.login(d(t,o.login),o.infiniteLogin,Y,o.infiniteLogin?e.noop:le.pop)}}else{Y()}if(!s){le.resume()}})});return le},pop:function(t){if(t!==n){A(t)}var r=le.token(true);if(He.size()==1){if(Ee.login){q();if(e.isFunction(Ee.onExit)){try{Ee.onExit(le)}catch(i){y(i,"onExit")}}return true}else{le.error(Re.canExitError)}}else{if(le.token(true)){M()}var o=He.pop();Y();if(xe&&le.get_prompt()!=Re.login+": "){xe=false}if(e.isFunction(o.onExit)){try{o.onExit(le)}catch(i){y(i,"onExit")}}le.set_mask(He.top().mask)}return le},option:function(n,t){if(typeof t=="undefined"){if(typeof n=="string"){return Ee[n]}else if(typeof n=="object"){e.each(n,function(e,n){Ee[e]=n})}}else{Ee[n]=t}return le},level:function(){return He.size()},reset:function(){ke.then(function(){le.clear();while(He.size()>1){He.pop()}ie()});return le},purge:function(){ke.then(function(){var n=le.prefix_name()+"_";var t=Ae.get(n+"interpreters");e.each(e.parseJSON(t),function(e,n){Ae.remove(n+"_commands");Ae.remove(n+"_token");Ae.remove(n+"_login")});Je.purge();Ae.remove(n+"interpreters")});return le},destroy:function(){ke.then(function(){Je.destroy().remove();me.remove();e(document).unbind(".terminal");e(window).unbind(".terminal");le.unbind("click mousewheel mousedown mouseup");le.removeData("terminal").removeClass("terminal");if(Ee.width){le.css("width","")}if(Ee.height){le.css("height","")}e(window).off("blur",Me).off("focus",qe);Z.remove(ge)});return le},scroll_to_bottom:w,is_bottom:function(){var n,t,r;if(le.is("body")){n=e(document).height();t=e(window).scrollTop();r=window.innerHeight}else{n=fe[0].scrollHeight;t=fe.scrollTop();r=fe.outerHeight()}return t+r>n-Ee.scrollBottomOffset}},function(e,n){return function(){try{return n.apply(le,[].slice.apply(arguments))}catch(t){if(e!=="exec"&&e!=="resume"){y(t,"TERMINAL")}throw t}}}));var Ie=function(){var e=W(le);return function(){if(e!==W(le)){le.resize();e=W(le)}}}();if(Ee.width){le.width(Ee.width)}if(Ee.height){le.height(Ee.height)}var Ne=navigator.userAgent.toLowerCase();if(!Ne.match(/(webkit)[ \/]([\w.]+)/)&&le[0].tagName.toLowerCase()=="body"){fe=e("html")}else{fe=le}e(document).bind("ajaxSend.terminal",function(e,n,t){X.push(n)});me=e("<div>").addClass("terminal-output").appendTo(le);le.addClass("terminal");if(Ee.login&&e.isFunction(Ee.onBeforeLogin)){try{if(Ee.onBeforeLogin(le)===false){ze=false}}catch(Ke){y(Ke,"onBeforeLogin");throw Ke}}var Le=Ee.login;var Pe;if(typeof t=="string"){Pe=t}else if(t instanceof Array){for(var De=0,Be=t.length;De<Be;++De){if(typeof t[De]=="string"){Pe=t[De];break}}}if(Pe&&(typeof Ee.login==="string"||Ee.login===true)){Ee.login=d(Pe,Ee.login)}Z.append(le);var He;var Je;var We;function qe(){if(We){le.focus()}}function Me(){We=je;le.disable()}m(t,!!Ee.login,function(t){if(Ee.completion&&typeof Ee.completion!="boolean"||!Ee.completion){t.completion="settings"}He=new g(e.extend({name:Ee.name,prompt:Ee.prompt,keypress:Ee.keypress,keydown:Ee.keydown,resize:Ee.onResize,greetings:Ee.greetings,mousewheel:Ee.mousewheel},t));Je=e("<div/>").appendTo(le).cmd({prompt:Ee.prompt,history:Ee.memory?"memory":Ee.history,historyFilter:Ee.historyFilter,historySize:Ee.historySize,width:"100%",enabled:je&&!x,keydown:se,keypress:function(n){var t,r,i=He.top();if(e.isFunction(i.keypress)){return i.keypress(n,le)}else if(e.isFunction(Ee.keypress)){return Ee.keypress(n,le)}},onCommandChange:function(n){if(e.isFunction(Ee.onCommandChange)){try{Ee.onCommandChange(n,le)}catch(t){y(t,"onCommandChange");throw t}}w()},commands:D});if(je&&le.is(":visible")&&!x){le.focus(n,true)}else{le.disable()}le.oneTime(100,function(){function n(n){var t=e(n.target);if(!t.closest(".terminal").length&&le.enabled()&&Ee.onBlur(le)!==false){le.disable()}}e(document).bind("click.terminal",n).bind("contextmenu.terminal",n)});var r=e(window);if(!x){r.on("focus",qe).on("blur",Me)}else{}if(x){le.click(function(){if(!le.enabled()&&!$e){le.focus();Je.enable()}else{le.focus(false)}})}else{(function(){var n=0;var t=false;le.mousedown(function(){le.oneTime(1,function(){e(window).mousemove(function(){t=true;n=0;e(window).unbind("mousemove")})})}).mouseup(function(){var r=t;t=false;e(window).unbind("mousemove");if(!r&&++n==1){n=0;if(!le.enabled()&&!$e){le.focus();Je.enable()}}})})()}le.delegate(".exception a","click",function(n){var t=e(this).attr("href");if(t.match(/:[0-9]+$/)){n.preventDefault();l(t)}});if(!navigator.platform.match(/linux/i)){le.mousedown(function(e){if(e.which==2){var n=J();le.insert(n)}})}if(le.is(":visible")){de=le.cols();Je.resize(de);ve=H(le)}if(Ee.login){le.login(Ee.login,true,ie)}else{ie()}le.oneTime(100,function(){r.bind("resize.terminal",function(){if(le.is(":visible")){var e=le.width();var n=le.height();if(Te!==n||Se!==e){le.resize()}}})});function i(n){var t=Z.get()[n[0]];if(t&&ge==t.id()){if(n[2]){try{if(Oe){var r=e.Deferred();K.push(function(){return t.exec(n[2]).then(function(e,i){t.save_state(n[2],true,n[1]);r.resolve()})});return r.promise()}else{return t.exec(n[2]).then(function(e,r){t.save_state(n[2],true,n[1])})}}catch(i){var o=e.terminal.escape_brackets(command);var a="Error while exec with command "+o;t.error(a).exception(i)}}}}if(Ee.execHash){if(location.hash){setTimeout(function(){try{var n=location.hash.replace(/^#/,"");ee=e.parseJSON(decodeURIComponent(n));var t=0;(function o(){var e=ee[t++];if(e){i(e).then(o)}else{ne=true}})()}catch(r){}})}else{ne=true}}else{ne=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}});le.mousewheel(function(n,t){if(!o){var r=He.top();if(e.isFunction(r.mousewheel)){var i=r.mousewheel(n,t,le);if(i===false){return}}else if(e.isFunction(Ee.mousewheel)){Ee.mousewheel(n,t,le)}if(t>0){le.scroll(-40)}else{le.scroll(40)}}})}ke.resolve()});le.data("terminal",le);return le}})(jQuery);