1
0
term/pkg/jquery.terminal/js/jquery.terminal.min.js
2024-04-06 07:42:07 +09:00

37 lines
60 KiB
JavaScript

/**@license
* __ _____ ________ __
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
* \/ /____/ version 0.10.8
*
* 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: Tue, 17 May 2016 09:01:51 +0000
*/
(function(e){var r=function(){if(!r.cache.hasOwnProperty(arguments[0])){r.cache[arguments[0]]=r.parse(arguments[0])}return r.format.call(null,r.cache[arguments[0]],arguments)};r.format=function(e,n){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=n[o];for(u=0;u<h[2].length;u++){if(!l.hasOwnProperty(h[2][u])){throw r('[sprintf] property "%s" does not exist',h[2][u])}l=l[h[2][u]]}}else if(h[1]){l=n[h[1]]}else{l=n[o++]}if(/[^s]/.test(h[8])&&t(l)!="number"){throw r("[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("")};r.cache={};r.parse=function(e){var r=e,n=[],t=[],i=0;while(r){if((n=/^[^\x25]+/.exec(r))!==null){t.push(n[0])}else if((n=/^\x25{2}/.exec(r))!==null){t.push("%")}else if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(r))!==null){if(n[2]){i|=1;var o=[],a=n[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?"}n[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}t.push(n)}else{throw"[sprintf] huh?"}r=r.substring(n[0].length)}return t};var n=function(e,n,t){t=n.slice(0);t.splice(0,0,e);return r.apply(null,t)};function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,r){for(var n=[];r>0;n[--r]=e){}return n.join("")}e.sprintf=r;e.vsprintf=n})(typeof global!="undefined"?global:window);(function(e,r){"use strict";e.omap=function(r,n){var t={};e.each(r,function(e,i){t[e]=n.call(r,e,i)});return t};var n={clone_object:function(r){var n={};if(typeof r=="object"){if(e.isArray(r)){return this.clone_array(r)}else if(r===null){return r}else{for(var t in r){if(e.isArray(r[t])){n[t]=this.clone_array(r[t])}else if(typeof r[t]=="object"){n[t]=this.clone_object(r[t])}else{n[t]=r[t]}}}}return n},clone_array:function(r){if(!e.isFunction(Array.prototype.map)){throw new Error("You'r browser don't support ES5 array map "+"use es5-shim")}return r.slice(0).map(function(e){if(typeof e=="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var t=function(e){return n.clone_object(e)};var i=function(){var e="test",r=window.localStorage;try{r.setItem(e,"1");r.removeItem(e);return true}catch(n){return false}};var o=i();function a(e,r){var n;if(typeof e==="string"&&typeof r==="string"){localStorage[e]=r;return true}else if(typeof e==="object"&&typeof r==="undefined"){for(n in e){if(e.hasOwnProperty(n)){localStorage[n]=e[n]}}return true}return false}function s(e,r){var n,t,i;n=new Date;n.setTime(n.getTime()+31536e6);t="; expires="+n.toGMTString();if(typeof e==="string"&&typeof r==="string"){document.cookie=e+"="+r+t+"; path=/";return true}else if(typeof e==="object"&&typeof r==="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 r,n,t,i;r=e+"=";n=document.cookie.split(";");for(t=0;t<n.length;t++){i=n[t];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(r)===0){return i.substring(r.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}});jQuery.fn.extend({everyTime:function(e,r,n,t,i){return this.each(function(){jQuery.timer.add(this,e,r,n,t,i)})},oneTime:function(e,r,n){return this.each(function(){jQuery.timer.add(this,e,r,n,1)})},stopTime:function(e,r){return this.each(function(){jQuery.timer.remove(this,e,r)})}});jQuery.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===r||e===null){return null}var n=this.regex.exec(jQuery.trim(e.toString()));if(n[2]){var t=parseInt(n[1],10);var i=this.powers[n[2]]||1;return t*i}else{return e}},add:function(e,r,n,t,i,o){var a=0;if(jQuery.isFunction(n)){if(!i){i=t}t=n;n=r}r=jQuery.timer.timeParse(r);if(typeof r!=="number"||isNaN(r)||r<=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[n]){e.$timers[n]={}}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){jQuery.timer.remove(e,n,t)}s.inProgress=false};s.$timerID=t.$timerID;if(!e.$timers[n][t.$timerID]){e.$timers[n][t.$timerID]=window.setInterval(s,r)}if(!this.global[n]){this.global[n]=[]}this.global[n].push(e)},remove:function(e,r,n){var t=e.$timers,i;if(t){if(!r){for(var o in t){if(t.hasOwnProperty(o)){this.remove(e,o,n)}}}else if(t[r]){if(n){if(n.$timerID){window.clearInterval(t[r][n.$timerID]);delete t[r][n.$timerID]}}else{for(var a in t[r]){if(t[r].hasOwnProperty(a)){window.clearInterval(t[r][a]);delete t[r][a]}}}for(i in t[r]){if(t[r].hasOwnProperty(i)){break}}if(!i){i=null;delete t[r]}}for(i in t){if(t.hasOwnProperty(i)){break}}if(!i){e.$timers=null}}}}});if(/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())){jQuery(window).one("unload",function(){var e=jQuery.timer.global;for(var r in e){if(e.hasOwnProperty(r)){var n=e[r],t=n.length;while(--t){jQuery.timer.remove(n[t],r)}}}})}(function(e){if(!String.prototype.split.toString().match(/\[native/)){return}var r=String.prototype.split,n=/()??/.exec("")[1]===e,t;t=function(t,i,o){if(Object.prototype.toString.call(i)!=="[object RegExp]"){return r.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(!n){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(!n&&c.length>1){c[0].replace(f,function(){for(var r=1;r<arguments.length-2;r++){if(arguments[r]===e){c[r]=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,r){return t(this,e,r)};return t})();e.fn.caret=function(e){var r=this[0];var n=r.contentEditable==="true";if(arguments.length==0){if(window.getSelection){if(n){r.focus();var t=window.getSelection().getRangeAt(0),i=t.cloneRange();i.selectNodeContents(r);i.setEnd(t.endContainer,t.endOffset);return i.toString().length}return r.selectionStart}if(document.selection){r.focus();if(n){var t=document.selection.createRange(),i=document.body.createTextRange();i.moveToElementText(r);i.setEndPoint("EndToEnd",t);return i.text.length}var e=0,o=r.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[n?"text":"val"]().length;if(window.getSelection){if(n){r.focus();window.getSelection().collapse(r.firstChild,e)}else r.setSelectionRange(e,e)}else if(document.body.createTextRange){var o=document.body.createTextRange();o.moveToElementText(r);o.moveStart("character",e);o.collapse(true);o.select()}if(!n)r.focus();return e};function h(e,r){var n=[];var t=e.length;if(t<r){return[e]}else if(r<0){throw new Error("str_parts: length can't be negative")}for(var i=0;i<t;i+=r){n.push(e.substring(i,i+r))}return n}function p(r){var n=r?[r]:[];var t=0;e.extend(this,{get:function(){return n},rotate:function(){if(n.length===1){return n[0]}else{if(t===n.length-1){t=0}else{++t}if(n[t]){return n[t]}else{this.rotate()}}},length:function(){return n.length},remove:function(e){delete n[e]},set:function(e){for(var r=n.length;r--;){if(n[r]===e){t=r;return}}this.append(e)},front:function(){if(n.length){var e=t;while(!n[e]){e++}return n[e]}},append:function(e){n.push(e)}})}function m(r){var n=r instanceof Array?r:r?[r]:[];e.extend(this,{map:function(r){return e.map(n,r)},size:function(){return n.length},pop:function(){if(n.length===0){return null}else{var e=n[n.length-1];n=n.slice(0,n.length-1);return e}},push:function(e){n=n.concat([e]);return e},top:function(){return n.length>0?n[n.length-1]:null},clone:function(){return new m(n.slice(0))}})}e.json_stringify=function(n,t){var i="",o;t=t===r?1:t;var a=typeof n;switch(a){case"function":i+=n;break;case"boolean":i+=n?"true":"false";break;case"object":if(n===null){i+="null"}else if(n instanceof Array){i+="[";var s=n.length;for(o=0;o<s-1;++o){i+=e.json_stringify(n[o],t+1)}i+=e.json_stringify(n[s-1],t+1)+"]"}else{i+="{";for(var l in n){if(n.hasOwnProperty(l)){i+='"'+l+'":'+e.json_stringify(n[l],t+1)}}i+="}"}break;case"string":var f=n;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(n);break}i+=t>1?",":"";if(t===1){i=i.replace(/,([\]}])/g,"$1")}return i.replace(/([\[{]),/g,"$1")};function g(r,n){var t=true;var i="";if(typeof r==="string"&&r!==""){i=r+"_"}i+="commands";var o=e.Storage.get(i);o=o?e.parseJSON(o):[];var a=o.length-1;e.extend(this,{append:function(r){if(t){if(o[o.length-1]!==r){o.push(r);if(n&&o.length>n){o=o.slice(-n)}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 d=function(){var e=document.createElement("div");e.setAttribute("onpaste","return;");return typeof e.onpaste=="function"}();var v=true;e.fn.cmd=function(n){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">&nbsp;</span><span></span>');var o=e("<textarea />").addClass("clipboard").appendTo(t);if(n.width){t.width(n.width)}var a;var s;var l=t.find(".prompt");var f=false;var c="";var u=null;var p;var m=n.mask||false;var v="";var y;var w="";var x="";var C=0;var S;var T;var j=n.historySize||60;var F,A;var E=t.find(".cursor");var R;function $(){if(k){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(k){t.oneTime(10,function(){o.val(v);t.oneTime(10,function(){o.caret(C)})})}}if(_&&!b){R=function(e){if(e){E.addClass("blink")}else{E.removeClass("blink")}}}else{var I=false;R=function(e){if(e&&!I){I=true;E.addClass("inverted");t.everyTime(500,"blink",O)}else if(I&&!e){I=false;t.stopTime("blink",O);E.removeClass("inverted")}}}function O(e){E.toggleClass("inverted")}function N(){S="(reverse-i-search)`"+c+"': ";Q()}function K(){S=p;f=false;u=null;c=""}function D(r){var n=A.data();var i,o;var a=n.length;if(r&&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(n[l])){u=n.length-l;t.position(n[l].indexOf(o));t.set(n[l],true);H();if(c.length!==s){c=c.substring(0,s);N()}return}}}}c=""}function P(){var e=t.width();var r=E.width();a=Math.floor(e/r)}function L(e){var r=e.substring(0,a-s);var n=e.substring(a-s);return[r].concat(h(n,a))}var H=function(r){var n=E.prev();var t=E.next();function i(r,i){var o=r.length;if(i===o){n.html(e.terminal.encode(r));E.html("&nbsp;");t.html("")}else if(i===0){n.html("");E.html(e.terminal.encode(r.slice(0,1)));t.html(e.terminal.encode(r.slice(1)))}else{var a=r.slice(0,i);n.html(e.terminal.encode(a));var s=r.slice(i,i+1);E.html(e.terminal.encode(s));if(i===r.length-1){t.html("")}else{t.html(e.terminal.encode(r.slice(i+1)))}}}function o(r){return"<div>"+e.terminal.encode(r)+"</div>"}function l(r){var n=t;e.each(r,function(r,t){n=e(o(t)).insertAfter(n).addClass("clear")})}function f(r){e.each(r,function(e,r){n.before(o(r))})}var c=0;return function(){var c;var u;switch(typeof m){case"boolean":c=m?v.replace(/./g,"*"):v;break;case"string":c=v.replace(/./g,m)}var p,g;r.find("div").remove();n.html("");if(c.length>a-s-1||c.match(/\n/)){var d;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");g=a-s-1;for(p=0;p<_.length-1;++p){_[p]+=" "}if(_[0].length>g){d=[_[0].substring(0,g)];u=_[0].substring(g);d=d.concat(h(u,a))}else{d=[_[0]]}for(p=1;p<_.length;++p){if(_[p].length>a){d=d.concat(h(_[p],a))}else{d.push(_[p])}}}else{d=L(c)}if(y){d=e.map(d,function(e){return e.replace(/\x00\x00\x00\x00/g," ")})}g=d[0].length;if(g===0&&d.length===1){}else if(C<g){i(d[0],C);l(d.slice(1))}else if(C===g){n.before(o(d[0]));i(d[1],0);l(d.slice(2))}else{var b=d.length;var k=0;if(C<g){i(d[0],C);l(d.slice(1))}else if(C===g){n.before(o(d[0]));i(d[1],0);l(d.slice(2))}else{var x=d.slice(-1)[0];var S=c.length-C-w;var T=x.length;var j=0;if(S<=T){f(d.slice(0,-1));if(T===S){j=0}else{j=T-S}i(x,j)}else{if(b===3){u=e.terminal.encode(d[0]);n.before("<div>"+u+"</div>");i(d[1],C-g-1);u=e.terminal.encode(d[2]);t.after('<div class="clear">'+u+"</div>")}else{var F;var A;j=C;for(p=0;p<d.length;++p){var R=d[p].length;if(j>R){j-=R}else{break}}A=d[p];F=p;if(j===A.length){j=0;A=d[++F]}i(A,j);f(d.slice(0,F));l(d.slice(F+1))}}}}}else{if(c===""){n.html("");E.html("&nbsp;");t.html("")}else{i(c,C)}}}}(t);var Q=function(){function r(r){l.html(e.terminal.format(e.terminal.encode(r)));s=l.text().length}return function(){switch(typeof S){case"string":r(S);break;case"function":S(r);break}}}();function B(e){e=e.originalEvent;if(t.isenabled()){var r=t.find("textarea");if(!r.is(":focus")){r.focus()}var n;if(window.clipboardData&&window.clipboardData.getData){n=window.clipboardData.getData("Text")}else if(e.clipboardData&&e.clipboardData.getData){n=e.clipboardData.getData("text/plain")}else{cmd.oneTime(100,function(){t.insert(r.val());r.val("");z()})}if(n){t.insert(n);r.val("");z()}}}var q=true;var J=false;var M;function U(i){var a,s,l;if(T){if(e.isFunction(n.keydown)){a=n.keydown(i);if(a!==r){return a}}if(i.which!==38&&!(i.which===80&&i.ctrlKey)){q=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)){K();Q();if(i.which===27){t.set("")}H();U.call(this,i)}else if(i.altKey){if(i.which===68){t.set(v.slice(0,C)+v.slice(C).replace(/ *[^ ]+ *(?= )|[^ ]+$/,""),true);return false}return true}else if(i.keyCode===13){if(i.shiftKey){t.insert("\n")}else{if(A&&v&&!m&&(e.isFunction(n.historyFilter)&&n.historyFilter(v))||n.historyFilter instanceof RegExp&&v.match(n.historyFilter)||!n.historyFilter){A.append(v)}var u=v;A.reset();t.set("");if(n.commands){n.commands(u)}if(e.isFunction(S)){Q()}}}else if(i.which===8){if(f){c=c.slice(0,-1);N()}else{if(v!==""&&C>0){t["delete"](-1)}}if(k){return true}}else if(i.which===67&&i.ctrlKey&&i.shiftKey){w=W()}else if(i.which===86&&i.ctrlKey&&i.shiftKey){if(w!==""){t.insert(w)}}else if(i.which===9&&!(i.ctrlKey||i.altKey)){t.insert(" ")}else if(i.which===46){t["delete"](1);return}else if(A&&(i.which===38&&!i.ctrlKey)||i.which===80&&i.ctrlKey){if(q){y=v;t.set(A.current())}else{t.set(A.previous())}q=false}else if(A&&(i.which===40&&!i.ctrlKey)||i.which===78&&i.ctrlKey){t.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(v[l]===" "){--l}for(var h=l;h>0;--h){if(v[h]===" "&&v[h+1]!==" "){s=h+1;break}else if(v[h]==="\n"&&v[h+1]!=="\n"){s=h;break}}t.position(s)}else{if(C>0){t.position(-1,true);H()}}}else if(i.which===82&&i.ctrlKey){if(f){D(true)}else{p=S;N();y=v;t.set("");H();f=true}}else if(i.which==71&&i.ctrlKey){if(f){S=p;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(v[C]===" "){++C}var g=/\S[\n\s]{2,}|[\n\s]+\S?/;var _=v.slice(C).match(g);if(!_||_[0].match(/^\s+$/)){t.position(v.length)}else{if(_[0][0]!==" "){C+=_.index+1}else{C+=_.index+_[0].length-1;if(_[0][_[0].length-1]!==" "){--C}}}H()}else{if(C<v.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(v.length)}else if(i.shiftKey&&i.which==45){o.val("");if(!d){B()}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(v!==""&&C!==0){var b=v.slice(0,C).match(/([^ ]+ *$)/);x=t["delete"](-b[0].length)}return false}else if(i.which===72){if(v!==""&&C>0){t["delete"](-1)}return false}else if(i.which===65){t.position(0)}else if(i.which===69){t.position(v.length)}else if(i.which===88||i.which===67||i.which===84){return}else if(i.which===89){if(x!==""){t.insert(x)}}else if(i.which===86){o.val("");if(!d){B()}else{o.focus()}return}else if(i.which===75){x=t["delete"](v.length-C)}else if(i.which===85){if(v!==""&&C!==0){x=t["delete"](-C)}}else if(i.which===17){return false}}}else{J=false;M=true;return}i.preventDefault()}}function Y(){if(e.isFunction(n.onCommandChange)){n.onCommandChange(v)}}e.extend(t,{name:function(e){if(e!==r){F=e;var n=A&&A.enabled()||!A;A=new g(e,j);if(!n){A.disable()}return t}else{return F}},purge:function(){A.clear();return t},history:function(){return A},"delete":function(e,r){var n;if(e===0){return t}else if(e<0){if(C>0){n=v.slice(0,C).slice(e);v=v.slice(0,C+e)+v.slice(C,v.length);if(!r){t.position(C+e)}else{Y()}}}else{if(v!==""&&C<v.length){n=v.slice(C).slice(0,e);v=v.slice(0,C)+v.slice(C+e,v.length);Y()}}H();z();return n},set:function(e,n){if(e!==r){v=e;if(!n){t.position(v.length)}H();z();Y()}return t},insert:function(e,r){if(C===v.length){v+=e}else if(C===0){v=e+v}else{v=v.slice(0,C)+e+v.slice(C)}if(!r){t.position(e.length,true)}else{z()}H();Y();return t},get:function(){return v},commands:function(e){if(e){n.commands=e;return t}else{return e}},destroy:function(){X.unbind("keypress.cmd",Z);X.unbind("keydown.cmd",U);X.unbind("paste.cmd",B);X.unbind("input.cmd",V);t.stopTime("blink",O);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===r){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 x},position:function(r,i){if(typeof r==="number"){if(i){C+=r}else{if(r<0){C=0}else if(r>v.length){C=v.length}else{C=r}}if(e.isFunction(n.onPositionChange)){n.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{P()}H();return t},enable:function(){T=true;t.addClass("enabled");R(true);$();return t},isenabled:function(){return T},disable:function(){T=false;t.removeClass("enabled");R(false);$();return t},mask:function(e){if(typeof e==="undefined"){return m}else{m=e;H();return t}}});t.name(n.name||n.prompt||"");if(typeof n.prompt=="string"){S=n.prompt}else{S="> "}Q();if(n.enabled===r||n.enabled===true){t.enable()}var G;var X=e(document.documentElement||window);function Z(i){var o;M=false;if(i.ctrlKey&&i.which===99){return}if(J){return}if(!f&&e.isFunction(n.keypress)){o=n.keypress(i)}if(o===r||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);D();N()}else{t.insert(String.fromCharCode(i.which))}return false}}}else{return o}}function V(e){if(M){var r=o.val();if(r||e.which==8){t.set(r)}}}X.bind("keypress.cmd",Z).bind("keydown.cmd",U).bind("input.cmd",V);if(d){X.bind("paste.cmd",B)}t.data("cmd",t);return t};function y(r){return e("<div>"+e.terminal.strip(r)+"</div>").text().length}function w(e){return e.length-y(e)}var _=function(){var e=false,n="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]!==r){o=i[s];n=o+"Animation";t="-"+o.toLowerCase()+"-";e=true;break}}}return e}();var b=navigator.userAgent.toLowerCase().indexOf("android")!=-1;var k=function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch}();function x(r,n){var t=n(r);if(t.length){var i=t.shift();var o=new RegExp("^"+e.terminal.escape_regex(i));var a=r.replace(o,"").trim();return{command:r,name:i,args:t,rest:a}}else{return{command:r,name:"",args:[],rest:""}}}var C=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?)/i;var S=/\[\[([!gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var T=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var j=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]/gi;var F=/^\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]$/gi;var A=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;var E=/(\bhttps?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\]\[)])+\b)/gi;var R=/\b(https?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\][)])+)\b(?![^[\]]*])/gi;var $=/((([^<>('")[\]\\.,;:\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 O=/^(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var N=/\[\[[!gbiuso]*;[^;]*;[^\]]*\]?$/i;var K=/(\[\[(?:[^\]]|\\\])*\]\])/;e.terminal={version:"0.10.8",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(r){if(r.match(A)){return true}else{return e.inArray(r.toLowerCase(),e.terminal.color_names)!==-1}},escape_regex:function(e){if(typeof e=="string"){var r=/([-\\\^$\[\]()+{}?*.|])/g;return e.replace(r,"\\$1")}},have_formatting:function(e){return typeof e=="string"&&!!e.match(j)},is_formatting:function(e){return typeof e=="string"&&!!e.match(F)},format_split:function(e){return e.split(C)},split_equal:function(r,n,t){var i=false;var o=false;var a="";var s=[];var l=r.replace(T,function(e,r,n){var t=r.match(/;/g).length;if(t>=4){return e}else if(t==2){t=";;"}else if(t==3){t=";"}else{t=""}var i=n.replace(/\\\]/g,"&#93;").replace(/\n/g,"\\n").replace(/&nbsp;/g," ");return"[["+r+t+i+"]"+n+"]"}).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(O)){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===n||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+n+1);var k=!!_.match(/\s/)||d+n+1>b;if(t&&g!=-1&&d!==v-1&&k){w=h.substring(p,g);d=g-1}else{w=h.substring(p,d+1)}if(t){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(T);if(x){var C=x[x.length-1];if(C[C.length-1]!=="]"){a=C.match(I)[1];w+="]"}else if(w.match(N)){var S=w.length;w=w.replace(N,"");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(r){return e.terminal.escape_brackets(e.terminal.encode(r))},format:function(r,n){var t=e.extend({},{linksNoReferrer:false},n||{});if(typeof r==="string"){var i=e.terminal.format_split(r);r=e.map(i,function(r){if(r===""){return r}else if(e.terminal.is_formatting(r)){return r.replace(S,function(r,n,i,o,a,s,l){if(l===""){return""}l=l.replace(/\\]/g,"]");var f="";if(n.indexOf("b")!==-1){f+="font-weight:bold;"}var c=[];if(n.indexOf("u")!==-1){c.push("underline")}if(n.indexOf("s")!==-1){c.push("line-through")}if(n.indexOf("o")!==-1){c.push("overline")}if(c.length){f+="text-decoration:"+c.join(" ")+";"}if(n.indexOf("i")!==-1){f+="font-style:italic;"}if(e.terminal.valid_color(i)){f+="color:"+i+";";if(n.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(n.indexOf("!")!==-1){if(u.match($)){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(n.indexOf("!")!==-1){h+=">"+l+"</a>"}else{h+=' data-text="'+u.replace('"',"&quote;")+'">'+l+"</span>"}return h})}else{return"<span>"+r.replace(/\\\]/g,"]")+"</span>"}}).join("");return r.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(S,"$6")},active:function(){return Z.front()},parseArguments:function(r){return e.terminal.parse_arguments(r)},splitArguments:function(r){return e.terminal.split_arguments(r)},parseCommand:function(r){return e.terminal.parse_command(r)},splitCommand:function(r){return e.terminal.split_command(r)},parse_arguments:function(r){var n=/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/;return e.map(r.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,r){return String.fromCharCode(parseInt(r,16))}).replace(/\\0([0-7]+)/g,function(e,r){return String.fromCharCode(parseInt(r,8))})}else if(e.match(/^\/(\\\/|[^\/])+\/[gimy]*$/)){var r=e.match(/^\/([^\/]+)\/([^\/]*)$/);return new RegExp(r[1],r[2])}else if(e.match(/^-?[0-9]+$/)){return parseInt(e,10)}else if(e.match(n)){return parseFloat(e)}else{return e.replace(/\\ /g," ")}})},split_arguments:function(r){return e.map(r.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(r){return x(r,e.terminal.parse_arguments)},split_command:function(r){return x(r,e.terminal.split_arguments)},extended_command:function(e,r){try{rr=false;e.exec(r,true).then(function(){rr=true})}catch(n){}}};e.fn.visible=function(){return this.css("visibility","visible")};e.fn.hidden=function(){return this.css("visibility","hidden")};var D={};e.jrpc=function(r,n,t,i,o){D[r]=D[r]||0;var a=e.json_stringify({jsonrpc:"2.0",method:n,params:t,id:++D[r]});return e.ajax({url:r,data:a,success:function(r,n,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(r)}catch(f){if(o){o(t,"Invalid JSON",f)}else{throw new Error("Invalid JSON")}return}i(l,n,t)},error:o,contentType:"application/json",dataType:"text",async:true,cache:false,type:"POST"})};function P(r){var n=e(window).scrollTop();var t=n+e(window).height();var i=e(r).offset().top;var o=i+e(r).height();return o>=n&&i<=t}function L(){var r=e('<div class="terminal temp"><div class="cmd"><span cla'+'ss="cursor">&nbsp;</span></div></div>').appendTo("body");var n=r.find("span");var t={width:n.width(),height:n.outerHeight()};r.remove();return t}function H(r){var n=e('<div class="terminal"><span class="cursor">'+"</span></div>").appendTo("body").css("padding",0);var t=n.find("span");var i=60;var o="";for(var a=0;a<=i;++a){o+="&nbsp;"}t.html(o);var s=t.width()/i;var l=Math.floor(r.width()/s);n.remove();if(B(r)){var f=20;var c=r.innerWidth()-r.width();l-=Math.ceil((f-c/2)/(s-1))}return l}function Q(e){return Math.floor(e.height()/L().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 B(r){if(r.css("overflow")=="scroll"||r.css("overflow-y")=="scroll"){return true}else if(r.is("body")){return e("body").height()>e(window).height()}else{return r.get(0).scrollHeight>r.innerHeight()}}var q=!e.terminal.version.match(/^\{\{/);var J="Copyright (c) 2011-2016 Jakub Jankiewicz <http://jcubic"+".pl>";var M=q?" v. "+e.terminal.version:" ";var U=new RegExp(" {"+M.length+"}$");var Y="jQuery Terminal Emulator"+(q?M:"");var G=[["jQuery Terminal","(c) 2011-2016 jcubic"],[Y,J.replace(/^Copyright | *<.*>/g,"")],[Y,J.replace(/^Copyright /,"")],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/ /_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(U," ")+M,J],[" __ _____ ________ __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ \\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // / /__","\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\__\\_\\___/"," \\/ /____/ ".replace(U,"")+M,J]];
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,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=window.terminals=new p;var V=[];var er;var rr=false;var nr=true;var tr=true;e.fn.terminal=function(n,i){function o(r){if(e.isFunction(Tr.processArguments)){return x(r,Tr.processArguments)}else if(Tr.processArguments){return e.terminal.parse_command(r)}else{return e.terminal.split_command(r)}}function a(r){if(typeof r==="string"){lr.echo(r)}else if(r instanceof Array){lr.echo(e.map(r,function(r){return e.json_stringify(r)}).join(" "))}else if(typeof r==="object"){lr.echo(e.json_stringify(r))}else{lr.echo(r)}}function s(r){var n=/(.*):([0-9]+):([0-9]+)$/;var t=r.match(n);if(t){lr.pause();e.get(t[1],function(r){var n=location.href.replace(/[^\/]+$/,"");var i=t[1].replace(n,"");lr.echo("[[b;white;]"+i+"]");var o=r.split("\n");var a=+t[2]-1;lr.echo(o.slice(a-2,a+3).map(function(r,n){if(n==2){r="[[;#f00;]"+e.terminal.escape_brackets(r)+"]"}return"["+(a+n)+"]: "+r}).join("\n")).resume()},"text")}}function l(r){if(e.isFunction(Tr.onRPCError)){Tr.onRPCError.call(lr,r)}else{lr.error("&#91;RPC&#93; "+r.message)}}function f(r,n){var t=function(n,t){lr.pause();e.jrpc(r,n,t,function(r){if(r.error){l(r.error)}else{if(e.isFunction(Tr.processRPCResponse)){Tr.processRPCResponse.call(lr,r.result,lr)}else{a(r.result)}}lr.resume()},u)};return function(e,r){if(e===""){return}try{e=o(e)}catch(i){r.error(i.toString());return}if(!n||e.name==="help"){t(e.name,e.args)}else{var a=r.token();if(a){t(e.name,[a].concat(e.args))}else{r.error("&#91;AUTH&#93; "+jr.noTokenError)}}}}function c(n,t,i,a){return function(s,l){if(s===""){return}var f;try{f=o(s)}catch(u){lr.error(u.toString());return}var h=n[f.name];var p=e.type(h);if(p==="function"){if(t&&h.length!==f.args.length){lr.error("&#91;Arity&#93; "+sprintf(jr.wrongArity,f.name,h.length,f.args.length))}else{return h.apply(lr,f.args)}}else if(p==="object"||p==="string"){var m=[];if(p==="object"){m=Object.keys(h);h=c(h,Tr.arity,i)}l.push(h,{prompt:f.name+"> ",name:f.name,completion:p==="object"?m:r})}else{if(e.isFunction(a)){a(s,lr)}else if(e.isFunction(Tr.onCommandNotFound)){Tr.onCommandNotFound(s,lr)}else{l.error(sprintf(jr.commandNotFound,f.name))}}}}function u(r,n,t){lr.resume();if(e.isFunction(Tr.onAjaxError)){Tr.onAjaxError.call(lr,r,n,t)}else if(n!=="abort"){lr.error("&#91;AJAX&#93; "+n+" - "+jr.serverResponse+": \n"+e.terminal.escape_brackets(r.responseText))}}function h(r,n,t){e.jrpc(r,"system.describe",[],function(i){var o=[];if(i.procs){var s={};e.each(i.procs,function(t,i){s[i.name]=function(){var t=n&&i.name!="help";var o=Array.prototype.slice.call(arguments);var s=o.length+(t?1:0);if(Tr.checkArity&&i.params&&i.params.length!==s){lr.error("&#91;Arity&#93; "+sprintf(jr.wrongArity,i.name,i.params.length,s))}else{lr.pause();if(t){var f=lr.token(true);if(f){o=[f].concat(o)}else{lr.error("&#91;AUTH&#93; "+jr.noTokenError)}}e.jrpc(r,i.name,o,function(e){if(e.error){l(e.error)}else{a(e.result)}lr.resume()},u)}}});t(s)}else{t(null)}},function(){t(null)})}function p(r,n,t){t=t||e.noop;var i=e.type(r);var o={};var a=0;var s;if(i==="array"){var l={};(function u(r,t){if(r.length){var i=r[0];var o=r.slice(1);var c=e.type(i);if(c==="string"){a++;lr.pause();if(Tr.ignoreSystemDescribe){if(a===1){s=f(i,n)}else{lr.error(jr.oneRPCWithIgnore)}u(o,t)}else{h(i,n,function(r){if(r){e.extend(l,r)}lr.resume();u(o,t)})}}else if(c==="function"){if(s){lr.error(jr.oneInterpreterFunction)}else{s=i}u(o,t)}else if(c==="object"){e.extend(l,i);u(o,t)}}else{t()}})(r,function(){t({interpreter:c(l,false,n,s),completion:Object.keys(l)})})}else if(i==="string"){if(Tr.ignoreSystemDescribe){t({interpreter:f(r,n),completion:Tr.completion})}else{lr.pause();h(r,n,function(e){if(e){o.interpreter=c(e,false,n);o.completion=Object.keys(e)}else{o.interpreter=f(r,n);o.completion=Tr.completion}t(o);lr.resume()})}}else if(i==="object"){t({interpreter:c(r,Tr.checkArity),completion:Object.keys(r)})}else{if(i==="undefined"){r=e.noop}else if(i!=="function"){throw i+" is invalid interpreter value"}t({interpreter:r,completion:Tr.completion})}}function g(r,n){var t=e.type(n)==="boolean"?"login":n;return function(n,i,o,a){lr.pause();e.jrpc(r,t,[n,i],function(e){if(!e.error&&e.result){o(e.result)}else{o(null)}lr.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(r,n){if(e.isFunction(Tr.exceptionHandler)){Tr.exceptionHandler.call(lr,r)}else{lr.exception(r,n)}}function y(){var e;if(fr.prop){e=fr.prop("scrollHeight")}else{e=fr.attr("scrollHeight")}fr.scrollTop(e)}function w(r,n){try{if(e.isFunction(n)){n(function(){})}else if(typeof n!=="string"){var t=r+" must be string or function";throw t}}catch(i){v(i,r.toUpperCase());return false}return true}var _=[];var b=1;function C(r,n){if(Tr.convertLinks){r=r.replace($,"[[!;;]$1]").replace(R,"[[!;;]$1]")}var t=e.terminal.defaults.formatters;var i,o;if(!n.raw){for(i=0;i<t.length;++i){try{if(typeof t[i]=="function"){var a=t[i](r);if(typeof a=="string"){r=a}}}catch(s){alert("formatting error at formatters["+i+"]\n"+(s.stack?s.stack:s))}}r=e.terminal.encode(r)}_.push(b);if(!n.raw&&(r.length>dr||r.match(/\n/))){var l=n.keepWords;var f=e.terminal.split_equal(r,dr,l);for(i=0,o=f.length;i<o;++i){if(f[i]===""||f[i]==="\r"){_.push("<span></span>")}else{if(n.raw){_.push(f[i])}else{_.push(e.terminal.format(f[i],{linksNoReferrer:Tr.linksNoReferrer}))}}}}else{if(!n.raw){r=e.terminal.format(r,{linksNoReferrer:Tr.linksNoReferrer})}_.push(r)}_.push(n.finalize)}function S(r,n){try{var t=e.extend({exec:true,raw:false,finalize:e.noop},n||{});var i=e.type(r)==="function"?r():r;i=e.type(i)==="string"?i:String(i);if(i!==""){if(t.exec){i=e.map(i.split(K),function(r){if(r.match(K)&&!e.terminal.is_formatting(r)){r=r.replace(/^\[\[|\]\]$/g,"");if(cr&&cr.command==r){lr.error(jr.recursiveCall)}else{e.terminal.extended_command(lr,r)}return""}else{return r}}).join("");if(i!==""){C(i,t)}}else{C(i,t)}}}catch(o){_=[];alert("[Internal Exception(process_line)]:"+d(o)+"\n"+o.stack)}}function T(){Kr.resize(dr);var r=mr.empty().detach();var n;if(Tr.outputLimit>=0){var t=Tr.outputLimit===0?lr.rows():Tr.outputLimit;n=pr.slice(pr.length-t-1)}else{n=pr}try{_=[];e.each(n,function(e,r){S.apply(null,r)});Kr.before(r);lr.flush()}catch(i){alert("Exception in redraw\n"+i.stack)}}function j(){if(Tr.greetings===r){lr.echo(lr.signature)}else if(Tr.greetings){var e=typeof Tr.greetings;if(e==="string"){lr.echo(Tr.greetings)}else if(e==="function"){Tr.greetings.call(lr,lr.echo)}else{lr.error(jr.wrongGreetings)}}}function F(r){var n=Kr.prompt();var t=Kr.mask();switch(typeof t){case"string":r=r.replace(/./g,t);break;case"boolean":if(t){r=r.replace(/./g,Tr.maskChar)}else{r=e.terminal.escape_formatting(r)}break}var i={finalize:function(e){e.addClass("command")}};if(e.isFunction(n)){n(function(e){lr.echo(e+r,i)})}else{lr.echo(n+r,i)}}function A(e){var r=Z.get()[e[0]];if(!r){throw new Error(jr.invalidTerminalId)}var n=e[1];if(V[n]){r.import_view(V[n])}else{rr=false;var t=e[2];if(t){r.exec(t).then(function(){rr=true;V[n]=r.export_view()})}}}function z(){if(rr){nr=false;location.hash=e.json_stringify(er);setTimeout(function(){nr=true},100)}}var I=true;var O;var N=[];var D=false;function L(n,t,i){O=n;if(I){I=false;if(Tr.historyState||Tr.execHash&&i){if(!V.length){lr.save_state()}else{lr.save_state(null)}}}function o(){if(!i){rr=true;if(Tr.historyState){lr.save_state(n,false)}rr=f}l.resolve();if(e.isFunction(Tr.onAfterCommand)){Tr.onAfterCommand(lr,n)}}try{if(e.isFunction(Tr.onBeforeCommand)){if(Tr.onBeforeCommand(lr,n)===false){return}}if(!i){cr=e.terminal.split_command(n)}if(!ar()){if(i&&e.isFunction(Tr.historyFilter)&&Tr.historyFilter(n)||n.match(Tr.historyFilter)){Kr.history().append(n)}}var s=Nr.top();if(!t){F(n)}var l=new e.Deferred;var f=rr;if(n.match(/^\s*login\s*$/)&&lr.token(true)){if(lr.level()>1){lr.logout(true)}else{lr.logout()}o()}else if(Tr.exit&&n.match(/^\s*exit\s*$/)&&!br){var c=lr.level();if(c==1&&lr.get_token()||c>1){if(lr.get_token(true)){lr.set_token(r,true)}lr.pop()}o()}else if(Tr.clear&&n.match(/^\s*clear\s*$/)&&!br){lr.clear();o()}else{var u=pr.length-1;var h=s.interpreter.call(lr,n,lr);if(h!==r){lr.pause();return e.when(h).then(function(e){if(e&&u===pr.length-1){a(e)}o();lr.resume()})}else if(Er){var p=n;N.push(function(){o()})}else{o()}}return l.promise()}catch(m){v(m,"USER");lr.resume();throw m}}function q(){if(e.isFunction(Tr.onBeforeLogout)){try{if(Tr.onBeforeLogout(lr)===false){return}}catch(r){v(r,"onBeforeLogout");throw r}}J();if(e.isFunction(Tr.onAfterLogout)){try{Tr.onAfterLogout(lr)}catch(r){v(r,"onAfterlogout");throw r}}lr.login(Tr.login,true,ir)}function J(){var r=lr.prefix_name(true)+"_";e.Storage.remove(r+"token");e.Storage.remove(r+"login")}function M(r){var n=lr.prefix_name()+"_interpreters";var t=e.Storage.get(n);if(t){t=e.parseJSON(t)}else{t=[]}if(e.inArray(r,t)==-1){t.push(r);e.Storage.set(n,e.json_stringify(t))}}function U(r){var n=Nr.top();var t=lr.prefix_name(true);if(!ar()){M(t)}Kr.name(t);if(e.isFunction(n.prompt)){Kr.prompt(function(e){n.prompt(e,lr)})}else{Kr.prompt(n.prompt)}Kr.set("");if(!r&&e.isFunction(n.onStart)){n.onStart(lr)}}var Y;function ir(){U();j();var r=false;if(e.isFunction(Tr.onInit)){kr=function(){r=true};try{Tr.onInit(lr)}catch(n){v(n,"OnInit")}finally{kr=e.noop;if(!r){lr.resume()}}}function t(){if(nr&&Tr.execHash){try{if(location.hash){var r=location.hash.replace(/^#/,"");er=e.parseJSON(decodeURIComponent(r))}else{er=[]}if(er.length){A(er[er.length-1])}else if(V[0]){lr.import_view(V[0])}}catch(n){v(n,"TERMINAL")}}}if(tr){tr=false;if(e.fn.hashchange){e(window).hashchange(t)}else{e(window).bind("hashchange",t)}}}function or(r,n,t){if(Tr.clear&&e.inArray("clear",t)==-1){t.push("clear")}if(Tr.exit&&e.inArray("exit",t)==-1){t.push("exit")}var i=Kr.get().substring(0,Kr.position());if(i!==r){return}var o=new RegExp("^"+e.terminal.escape_regex(n));var a=[];for(var s=t.length;s--;){if(o.test(t[s])){a.push(t[s])}}if(a.length===1){lr.insert(a[0].replace(o,""))}else if(a.length>1){if(hr>=2){F(r);lr.echo(a.reverse().join(" "),{keepWords:true});hr=0}else{var l=false;var f;var c;e:for(c=n.length;c<a[0].length;++c){for(s=1;s<a.length;++s){if(a[0].charAt(c)!==a[s].charAt(c)){break e}}l=true}if(l){lr.insert(a[0].slice(0,c).replace(o,""))}}}}function ar(){return br||Kr.mask()!==false}function sr(n){var t,i,o=Nr.top();if(!lr.paused()&&lr.enabled()){if(e.isFunction(o.keydown)){t=o.keydown(n,lr);if(t!==r){return t}}else if(e.isFunction(Tr.keydown)){t=Tr.keydown(n,lr);if(t!==r){return t}}var a;if(Tr.completion&&e.type(Tr.completion)!="boolean"&&o.completion===r){a=Tr.completion}else{a=o.completion}lr.oneTime(10,function(){Rr()});if(n.which!==9){hr=0}if(n.which===68&&n.ctrlKey){if(!br){if(Kr.get()===""){if(Nr.size()>1||Tr.login!==r){lr.pop("")}else{lr.resume();lr.echo("")}}else{lr.set_command("")}}return false}else if(n.which===76&&n.ctrlKey){lr.clear()}else if(a&&n.which===9){++hr;var s=Kr.position();var l=Kr.get().substring(0,s);var f=l.split(" ");var c;if(f.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(lr,c,function(e){or(l,c,e)});break;case"array":or(l,c,a);break;default:throw new Error(f.invalidCompletion)}return false}else if(n.which===86&&n.ctrlKey){lr.oneTime(1,function(){y()});return}else if(n.which===9&&n.ctrlKey){if(Z.length()>1){lr.focus(false);return false}}else if(n.which===34){lr.scroll(lr.height())}else if(n.which===33){lr.scroll(-lr.height())}else{lr.attr({scrollTop:lr.attr("scrollHeight")})}}else if(n.which===68&&n.ctrlKey){if(X.length){for(i=X.length;i--;){var u=X[i];if(4!==u.readyState){try{u.abort()}catch(h){lr.error(f.ajaxAbortError)}}}X=[];lr.resume()}return false}}var lr=this;if(this.length>1){return this.each(function(){e.fn.terminal.call(e(this),n,e.extend({name:lr.selector},i))})}if(lr.data("terminal")){return lr.data("terminal")}if(lr.length===0){throw sprintf(e.terminal.defaults.strings.invalidSelector,lr.selector)}var fr;var cr;var ur=false;var hr=0;var pr=[];var mr;var gr=Z.length();var dr;var vr;var yr=[];var wr;var _r=new m;var br=false;var kr=e.noop;var xr,Cr;var Sr=[];var Tr=e.extend({},e.terminal.defaults,{name:lr.selector},i||{});var jr=e.terminal.defaults.strings;var Fr=Tr.enabled,Ar;var Er=false;e.extend(lr,e.omap({id:function(){return gr},clear:function(){mr.html("");pr=[];try{Tr.onClear(lr)}catch(e){v(e,"onClear");throw e}lr.attr({scrollTop:0});return lr},export_view:function(){return e.extend({},{focus:Fr,mask:Kr.mask(),prompt:lr.get_prompt(),command:lr.get_command(),position:Kr.position(),lines:t(pr),interpreters:Nr.clone()},e.isFunction(Tr.onExport)?Tr.onExport():{})},import_view:function(r){if(br){throw new Error(sprintf(jr.notWhileLogin,"import_view"))}if(e.isFunction(Tr.onImport)){Tr.onImport(r)}lr.set_prompt(r.prompt);lr.set_command(r.command);Kr.position(r.position);Kr.mask(r.mask);if(r.focus){lr.focus()}pr=t(r.lines);Nr=r.interpreters;T();return lr},save_state:function(n,t,i){if(typeof i!="undefined"){V[i]=lr.export_view()}else{V.push(lr.export_view())}if(!e.isArray(er)){er=[]}if(n!==r&&!t){var o=[gr,V.length-1,n];er.push(o);z()}},exec:function(r,n,t){if(e.isArray(r)){return e.when.apply(e,e.map(r,function(e){return lr.exec(e,n)}))}var i=t||new e.Deferred;if(Er){Sr.push([r,n,i])}else{L(r,n,true).then(function(){i.resolve(lr)})}return i.promise()},autologin:function(e,r,n){lr.trigger("terminal.autologin",[e,r,n]);return lr},login:function(r,n,t,i){_r.push([].slice.call(arguments));if(br){throw new Error(sprintf(jr.notWhileLogin,"login"))}if(!e.isFunction(r)){throw new Error(jr.loginIsNotAFunction)}if(lr.token(true)&&lr.login_name(true)){if(e.isFunction(t)){t()}return lr}var o=null;if(Tr.history){Kr.history().disable()}var a=lr.level();br=true;function s(r,o,s,l){if(o){while(lr.level()>a){lr.pop()}if(Tr.history){Kr.history().enable()}var f=lr.prefix_name(true)+"_";e.Storage.set(f+"token",o);e.Storage.set(f+"login",r);br=false;if(e.isFunction(t)){t()}}else{if(n){if(!s){lr.error(jr.wrongPasswordTryAgain)}lr.pop().set_mask(false)}else{br=false;if(!s){lr.error(jr.wrongPassword)}lr.pop().pop()}if(e.isFunction(i)){i()}}lr.off("terminal.autologin")}lr.on("terminal.autologin",function(e,r,n,t){s(r,n,t)});return lr.push(function(e){lr.set_mask(Tr.maskChar).push(function(n){try{r.call(lr,e,n,function(r,n){s(e,r,n)})}catch(t){v(t,"AUTH")}},{prompt:jr.password+": ",name:"password"})},{prompt:jr.login+": ",name:"login"})},settings:function(){return Tr},commands:function(){return Nr.top().interpreter},setInterpreter:function(){if(window.console&&console.warn){console.warn("This function is deprecated, use set_inte"+"rpreter insead!")}lr.set_interpreter.apply(lr,arguments)},set_interpreter:function(r,n){function t(){lr.pause();p(r,!!n,function(r){lr.resume();var n=Nr.top();e.extend(n,r);U(true)})}if(e.type(r)=="string"&&n){lr.login(g(r,n),true,t)}else{t()}},greetings:function(){j();return lr},paused:function(){return Er},pause:function(){kr();if(!Er&&Kr){Er=true;Kr.disable().hidden();if(e.isFunction(Tr.onPause)){Tr.onPause()}}return lr},resume:function(){if(Er&&Kr){Er=false;Kr.enable().visible();var r=Sr;Sr=[];(function n(){if(r.length){lr.exec.apply(lr,r.shift()).then(n)}else{lr.trigger("resume");var t=N.shift();if(t){t()}y();if(e.isFunction(Tr.onResume)){Tr.onResume()}}})()}return lr},cols:function(){return Tr.numChars?Tr.numChars:H(lr)},rows:function(){return Tr.numRows?Tr.numRows:Q(lr)},history:function(){return Kr.history()},history_state:function(e){if(e){lr.oneTime(1,function(){Tr.historyState=true;if(!V.length){lr.save_state()}else if(Z.length()>1){lr.save_state(null)}})}else{Tr.historyState=false}return lr},next:function(){if(Z.length()===1){return lr}else{var r=lr.offset().top;var n=lr.height();var t=lr.scrollTop();if(!P(lr)){lr.enable();e("html,body").animate({scrollTop:r-50},500);return lr}else{Z.front().disable();var i=Z.rotate().enable();var o=i.offset().top-50;e("html,body").animate({scrollTop:o},500);try{Tr.onTerminalChange(i)}catch(a){v(a,"onTerminalChange");throw a}return i}}},focus:function(e,r){if(Z.length()===1){if(e===false){try{if(!r&&Tr.onBlur(lr)!==false||r){lr.disable()}}catch(n){v(n,"onBlur");throw n}}else{try{if(!r&&Tr.onFocus(lr)!==false||r){lr.enable()}}catch(n){v(n,"onFocus");throw n}}}else{if(e===false){lr.next()}else{var t=Z.front();if(t!=lr){t.disable();if(!r){try{Tr.onTerminalChange(lr)}catch(n){v(n,"onTerminalChange");throw n}}}Z.set(lr);lr.enable()}}return lr},freeze:function(e){if(e){lr.disable();Ar=true}else{Ar=false;lr.enable()}},frozen:function(){return Ar},enable:function(){if(!Fr&&!Ar){if(dr===r){lr.resize()}if(Kr){Kr.enable();Fr=true}}return lr},disable:function(){if(Fr&&Kr&&!Ar){Fr=false;Kr.disable()}return lr},enabled:function(){return Fr},signature:function(){var e=lr.cols();var r=e<15?null:e<35?0:e<55?1:e<64?2:e<75?3:4;if(r!==null){return G[r].join("\n")+"\n"}else{return""}},version:function(){return e.terminal.version},cmd:function(){return Kr},get_command:function(){return Kr.get()},set_command:function(e){Kr.set(e);return lr},insert:function(e){if(typeof e==="string"){Kr.insert(e);return lr}else{throw"insert function argument is not a string"}},set_prompt:function(r){if(w("prompt",r)){if(e.isFunction(r)){Kr.prompt(function(e){r(e,lr)})}else{Kr.prompt(r)}Nr.top().prompt=r}return lr},get_prompt:function(){return Nr.top().prompt},set_mask:function(e){Kr.mask(e===true?Tr.maskChar:e);return lr},get_output:function(r){if(r){return pr}else{return e.map(pr,function(r){return e.isFunction(r[0])?r[0]():r[0]}).join("\n")}},resize:function(r,n){if(!lr.is(":visible")){lr.stopTime("resize");lr.oneTime(500,"resize",function(){lr.resize(r,n)})}else{if(r&&n){lr.width(r);lr.height(n)}r=lr.width();n=lr.height();var t=lr.cols();var i=lr.rows();if(t!==dr||i!==vr){dr=t;vr=i;T();var o=Nr.top();if(e.isFunction(o.resize)){o.resize(lr)}else if(e.isFunction(Tr.onResize)){Tr.onResize(lr)}Cr=n;xr=r;y()}}return lr},flush:function(){try{var r;e.each(_,function(n,t){if(t===b){r=e("<div></div>")}else if(e.isFunction(t)){r.appendTo(mr);try{t(r)}catch(i){v(i,"USER:echo(finalize)")}}else{e("<div/>").html(t).appendTo(r).width("100%")}});if(Tr.outputLimit>=0){var n=Tr.outputLimit===0?lr.rows():Tr.outputLimit;var t=mr.find("div div");if(t.length>n){var i=pr.length-n+1;var o=t.slice(0,i);var a=o.parent();o.remove();a.each(function(){var r=e(this);if(r.is(":empty")){r.remove()}})}}y();_=[]}catch(s){alert("[Flush] "+d(s)+"\n"+s.stack)}return lr},update:function(e,r){if(e<0){e=pr.length+e}if(!pr[e]){lr.error("Invalid line number "+e)}else{pr[e][0]=r;T()}return lr},echo:function(r,n){r=r||"";e.when(r).then(function(r){try{_=[];var t=e.extend({flush:true,raw:Tr.raw,finalize:e.noop,keepWords:false},n||{});S(r,t);pr.push([r,e.extend(t,{exec:false})]);if(t.flush){lr.flush()}vr=Q(lr);Rr()}catch(i){alert("[Terminal.echo] "+d(i)+"\n"+i.stack)}});return lr},error:function(r,n){var t=e.terminal.escape_brackets(r).replace(/\\$/,"&#92;").replace(E,"]$1[[;;;error]");return lr.echo("[[;;;error]"+t+"]",n)},exception:function(r,n){var t=d(r);if(n){t="&#91;"+n+"&#93;: "+t}if(t){lr.error(t,{finalize:function(e){e.addClass("exception message")}})}if(typeof r.fileName==="string"){lr.pause();e.get(r.fileName,function(e){lr.resume();var n=r.lineNumber-1;var t=e.split("\n")[n];if(t){lr.error("["+r.lineNumber+"]: "+t)}})}if(r.stack){lr.echo(r.stack.split(/\n/g).map(function(e){return"[[;;;error]"+e.replace(E,function(e){return"]"+e+"[[;;;error]"})+"]"}).join("\n"),{finalize:function(e){e.addClass("exception stack-trace")}})}},scroll:function(e){var r;e=Math.round(e);if(fr.prop){if(e>fr.prop("scrollTop")&&e>0){fr.prop("scrollTop",0)}r=fr.prop("scrollTop");fr.scrollTop(r+e)}else{if(e>fr.attr("scrollTop")&&e>0){fr.attr("scrollTop",0)}r=fr.attr("scrollTop");fr.scrollTop(r+e)}return lr},logout:function(e){if(e){var n=_r.pop();lr.set_token(r,true);lr.login.apply(lr,n)}else{while(Nr.size()>0){if(lr.pop()){break}}}return lr},token:function(r){return e.Storage.get(lr.prefix_name(r)+"_token")},set_token:function(r,n){var t=lr.prefix_name(n)+"_token";if(typeof r=="undefined"){e.Storage.remove(t,r)}else{e.Storage.set(t,r)}return lr},get_token:function(r){return e.Storage.get(lr.prefix_name(r)+"_token")},login_name:function(r){return e.Storage.get(lr.prefix_name(r)+"_login")},name:function(){return Nr.top().name},prefix_name:function(e){var r=(Tr.name?Tr.name+"_":"")+gr;if(e&&Nr.size()>1){var n=Nr.map(function(e){return e.name}).slice(1).join("_");if(n){r+="_"+n}}return r},read:function(r,n){var t=new e.Deferred;lr.push(function(r){lr.pop();if(e.isFunction(n)){n(r)}t.resolve(r)},{prompt:r});return t.promise()},push:function(n,t){t=t||{};if(!t.name&&cr){t.name=cr.name}if(t.prompt===r){t.prompt=t.name+" "}var i=Nr.top();if(i){i.mask=Kr.mask()}var o=Er;lr.pause();p(n,!!t.login,function(r){Nr.push(e.extend({},r,t));if(t.login){var i=e.type(t.login);if(i=="function"){lr.login(t.login,false,U,lr.pop)}else if(e.type(n)=="string"&&i=="string"||i=="boolean"){lr.login(g(n,t.login),false,U,lr.pop)}}else{U()}if(!o){lr.resume()}});return lr},pop:function(n){if(n!==r){F(n)}var t=lr.token(true);if(Nr.size()==1){if(Tr.login){q();if(e.isFunction(Tr.onExit)){try{Tr.onExit(lr)}catch(i){v(i,"onExit");throw i}}return true}else{lr.error(jr.canExitError)}}else{if(lr.token(true)){J()}var o=Nr.pop();U();if(e.isFunction(o.onExit)){try{o.onExit(lr)}catch(i){v(i,"onExit");throw i}}lr.set_mask(Nr.top().mask)}return lr},option:function(r,n){if(typeof n=="undefined"){if(typeof r=="string"){return Tr[r]}else if(typeof r=="object"){e.each(r,function(e,r){Tr[e]=r})}}else{Tr[r]=n}return lr},level:function(){return Nr.size()},reset:function(){lr.clear();while(Nr.size()>1){Nr.pop()}ir();return lr},purge:function(){var r=lr.prefix_name()+"_";var n=e.Storage.get(r+"interpreters");e.each(e.parseJSON(n),function(r,n){e.Storage.remove(n+"_commands");e.Storage.remove(n+"_token");e.Storage.remove(n+"_login")});Kr.purge();e.Storage.remove(r+"interpreters");return lr},destroy:function(){Kr.destroy().remove();mr.remove();e(document).unbind(".terminal");e(window).unbind(".terminal");lr.unbind("click mousewheel");lr.removeData("terminal").removeClass("terminal");if(Tr.width){lr.css("width","")}if(Tr.height){lr.css("height","")}e(window).off("blur",Lr).off("focus",Pr);Z.remove(gr);return lr}},function(e,r){return function(){try{return r.apply(lr,[].slice.apply(arguments))}catch(n){if(e!=="exec"&&e!=="resume"){v(n,"TERMINAL")}throw n}}}));var Rr=function(){var e=B(lr);return function(){if(e!==B(lr)){lr.resize();e=B(lr)}}}();if(Tr.width){lr.width(Tr.width)}if(Tr.height){lr.height(Tr.height)}var $r=navigator.userAgent.toLowerCase();if(!$r.match(/(webkit)[ \/]([\w.]+)/)&&lr[0].tagName.toLowerCase()=="body"){fr=e("html")}else{fr=lr}e(document).bind("ajaxSend.terminal",function(e,r,n){X.push(r)});mr=e("<div>").addClass("terminal-output").appendTo(lr);lr.addClass("terminal");if(Tr.login&&e.isFunction(Tr.onBeforeLogin)){try{Tr.onBeforeLogin(lr)}catch(zr){v(zr,"onBeforeLogin");throw zr}}var Ir=Tr.login;var Or;if(typeof n=="string"){Or=n}else if(n instanceof Array&&typeof n[0]=="string"){Or=n[0]}if(Or&&(typeof Tr.login==="string"||Tr.login)){Tr.login=g(Or,Tr.login)}Z.append(lr);var Nr;var Kr;var Dr;function Pr(){if(Dr){lr.focus()}}function Lr(){Dr=Fr;lr.disable()}p(n,!!Tr.login,function(n){if(Tr.completion&&typeof Tr.completion!="boolean"){n.completion=Tr.completion}Nr=new m(e.extend({name:Tr.name,prompt:Tr.prompt,keypress:Tr.keypress,keydown:Tr.keydown,resize:Tr.onResize,greetings:Tr.greetings,mousewheel:Tr.mousewheel},n));Kr=e("<div/>").appendTo(lr).cmd({prompt:Tr.prompt,history:Tr.history,historyFilter:Tr.historyFilter,historySize:Tr.historySize,width:"100%",enabled:Fr&&!k,keydown:sr,keypress:function(r){var n,t,i=Nr.top();if(e.isFunction(i.keypress)){return i.keypress(r,lr)}else if(e.isFunction(Tr.keypress)){return Tr.keypress(r,lr)}},onCommandChange:function(r){if(e.isFunction(Tr.onCommandChange)){try{Tr.onCommandChange(r,lr)}catch(n){v(n,"onCommandChange");throw n}}y()},commands:L});if(Fr&&lr.is(":visible")&&!k){lr.focus(r,true)}else{lr.disable()}lr.oneTime(100,function(){function r(r){var n=e(r.target);if(!n.closest(".terminal").length&&lr.enabled()&&Tr.onBlur(lr)!==false){lr.disable()}}e(document).bind("click.terminal",r).bind("contextmenu.terminal",r)});if(!k){var t=e(window).on("focus",Pr).on("blur",Lr)}else{}lr.click(function(e){if(!lr.enabled()){lr.focus()}else if(k){lr.focus(true,true)}Kr.enable()}).delegate(".exception a","click",function(r){var n=e(this).attr("href");if(n.match(/:[0-9]+$/)){r.preventDefault();s(n)}});if(!navigator.platform.match(/linux/i)){lr.mousedown(function(e){if(e.which==2){var r=W();lr.insert(r)}})}if(lr.is(":visible")){dr=lr.cols();Kr.resize(dr);vr=Q(lr)}if(Tr.login){lr.login(Tr.login,true,ir)}else{ir()}lr.oneTime(100,function(){t.bind("resize.terminal",function(){if(lr.is(":visible")){var e=lr.width();var r=lr.height();if(Cr!==r||xr!==e){lr.resize()}}})});function i(r){var n=Z.get()[r[0]];if(n&&gr==n.id()){if(r[2]){try{if(Er){var t=e.Deferred();N.push(function(){return n.exec(r[2]).then(function(e,i){n.save_state(r[2],true,r[1]);t.resolve()})});return t.promise()}else{return n.exec(r[2]).then(function(e,t){n.save_state(r[2],true,r[1])})}}catch(i){var o=e.terminal.escape_brackets(command);var a="Error while exec with command "+o;n.error(a).exception(i)}}}}if(Tr.execHash){if(location.hash){try{var o=location.hash.replace(/^#/,"");er=e.parseJSON(decodeURIComponent(o));var a=0;(function c(){var e=er[a++];if(e){i(e).then(c)}else{rr=true}})()}catch(l){}}else{rr=true}}else{rr=true}if(e.event.special.mousewheel){var f=false;e(document).bind("keydown.terminal",function(e){if(e.shiftKey){f=true}}).bind("keyup.terminal",function(e){if(e.shiftKey||e.which==16){f=false}});lr.mousewheel(function(r,n){if(!f){var t=Nr.top();if(e.isFunction(t.mousewheel)){var i=t.mousewheel(r,n,lr);if(i===false){return}}else if(e.isFunction(Tr.mousewheel)){Tr.mousewheel(r,n,lr)}if(n>0){lr.scroll(-40)}else{lr.scroll(40)}}})}});lr.data("terminal",lr);return lr}})(jQuery);