Web edits
[beagleboard.org.git] / static / jquery.terminal.js
blob8ad51b676a571d7af24b8bdb48e8589ce853ed45
1 /*
3  |       __ _____                     ________                              __
4  |      / // _  /__ __ _____ ___ __ _/__  ___/__ ___ ______ __ __  __ ___  / /
5  |  __ / // // // // // _  // _// // / / // _  // _//     // //  \/ // _ \/ /
6  | /  / // // // // // ___// / / // / / // ___// / / / / // // /\  // // / /__
7  | \___//____ \\___//____//_/ _\_  / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
8  |           \/              /____/                              version 0.4.12
9  http://terminal.jcubic.pl
11  Licensed under GNU LGPL Version 3 license
12  Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>
14  Includes:
16  Storage plugin Distributed under the MIT License
17  Copyright (c) 2010 Dave Schindler
19  LiveQuery plugin Dual MIT and GPL
20  Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
22  jQuery Timers licenced with the WTFPL
23  <http://jquery.offput.ca/every/>
25  Date: Wed, 04 Apr 2012 16:30:49 +0000
27 Array.prototype.has=function(g){for(var z=this.length;z--;)if(this[z]==g)return true;return false};function get_stack(g){return g?[g.toString().match(/.*\n.*\n/)].concat(get_stack(g.caller)):[]}
28 (function(g,z){function ea(a,d){var e;if(typeof a==="string"&&typeof d==="string"){localStorage[a]=d;return true}else if(typeof a==="object"&&typeof d==="undefined"){for(e in a)if(a.hasOwnProperty(e))localStorage[e]=a[e];return true}return false}function $(a,d){var e,i;e=new Date;e.setTime(e.getTime()+31536E6);e="; expires="+e.toGMTString();if(typeof a==="string"&&typeof d==="string"){document.cookie=a+"="+d+e+"; path=/";return true}else if(typeof a==="object"&&typeof d==="undefined"){for(i in a)if(a.hasOwnProperty(i))document.cookie=
29 i+"="+a[i]+e+"; path=/";return true}return false}function fa(a){return localStorage[a]}function ga(a){var d,e,i;a+="=";d=document.cookie.split(";");for(e=0;e<d.length;e++){for(i=d[e];i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(a)===0)return i.substring(a.length,i.length)}return null}function ha(a){return delete localStorage[a]}function ia(a){return $(a,"",-1)}function X(a,d){var e=[],i=a.length;if(i<d)return[a];for(var h=0;h<i;h+=d)e.push(a.substring(h,h+d));return e}function F(a){if(typeof a==
30 "string"){a=a.replace(/&(?!#[0-9]+;|[a-zA-Z]+;)/g,"&amp;");a=a.replace(/</g,"&lt;").replace(/>/g,"&gt;");a=a.replace(/\n/g,"<br/>");a=a.replace(/ /g,"&nbsp;");a=a.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");var d=a.split(ja);if(d.length>1)a=g.map(d,function(e){return e===""?e:e[0]=="["?e.replace(Y,function(i,h,t,v,C){if(C==="")return"<span>&nbsp;</span>";i="";if(h.indexOf("b")!=-1)i+="font-weight:bold;";var L="text-decoration:";if(h.indexOf("u")!=-1)L+="underline ";if(h.indexOf("s")!=-1)L+="line-through";
31 if(h.indexOf("s")!=-1||h.indexOf("u")!=-1)i+=L+";";if(h.indexOf("i")!=-1)i+="font-style:italic; ";if(t.match(aa))i+="color:"+t+";";if(v.match(aa))i+="background-color:"+v;return a='<span style="'+i+'">'+C+"</span>"}):"<span>"+e+"</span>"}).join("");return a}else return""}function ba(a){var d=a instanceof Array?a:a?[a]:[],e=0;g.extend(this,{left:function(){if(e===0)e=d.length-1;else--e;return d[e]},right:function(){if(e==d.length-1)e=0;else++e;return d[e]},current:function(){return d[e]},data:function(){return d},
32 length:function(){return d.length},reset:function(){e=0},append:function(i){d.push(i);this.reset()}})}function ka(a){var d=a?[a]:[];g.extend(this,{size:function(){return d.length},pop:function(){if(d.length===0)return null;else{var e=d[d.length-1];d=d.slice(0,d.length-1);return e}},push:function(e){d=d.concat([e]);return e},top:function(){return d.length>0?d[d.length-1]:null}})}function la(a){var d=true;if(typeof a==="string"&&a!=="")a+="_";var e=g.Storage.get(a+"commands"),i=new ba(e?eval("("+e+
33 ")"):[""]);g.extend(this,{append:function(h){if(d&&i.current()!=h){i.append(h);g.Storage.set(a+"commands",g.json_stringify(i.data()))}},data:function(){return i.data()},next:function(){return i.right()},last:function(){i.reset()},previous:function(){return i.left()},clear:function(){i=new ba;g.Storage.remove(a+"commands")},enable:function(){d=true},disable:function(){d=false}})}g.extend(g.fn,{livequery:function(a,d,e){var i=this,h;if(g.isFunction(a)){e=d;d=a;a=z}g.each(g.livequery.queries,function(t,
34 v){if(i.selector==v.selector&&i.context==v.context&&a==v.type&&(!d||d.$lqguid==v.fn.$lqguid)&&(!e||e.$lqguid==v.fn2.$lqguid))return(h=v)&&false});h=h||new g.livequery(this.selector,this.context,a,d,e);h.stopped=false;h.run();return this},expire:function(a,d,e){var i=this;if(g.isFunction(a)){e=d;d=a;a=z}g.each(g.livequery.queries,function(h,t){if(i.selector==t.selector&&i.context==t.context&&(!a||a==t.type)&&(!d||d.$lqguid==t.fn.$lqguid)&&(!e||e.$lqguid==t.fn2.$lqguid)&&!this.stopped)g.livequery.stop(t.id)});
35 return this}});g.livequery=function(a,d,e,i,h){this.selector=a;this.context=d||document;this.type=e;this.fn=i;this.fn2=h;this.elements=[];this.stopped=false;this.id=g.livequery.queries.push(this)-1;i.$lqguid=i.$lqguid||g.livequery.guid++;if(h)h.$lqguid=h.$lqguid||g.livequery.guid++;return this};g.livequery.prototype={stop:function(){var a=this;if(this.type)this.elements.unbind(this.type,this.fn);else this.fn2&&this.elements.each(function(d,e){a.fn2.apply(e)});this.elements=[];this.stopped=true},run:function(){if(!this.stopped){var a=
36 this,d=this.elements,e=g(this.selector,this.context),i=e.not(d);this.elements=e;if(this.type){i.bind(this.type,this.fn);d.length>0&&g.each(d,function(h,t){g.inArray(t,e)<0&&g.event.remove(t,a.type,a.fn)})}else{i.each(function(){a.fn.apply(this)});this.fn2&&d.length>0&&g.each(d,function(h,t){g.inArray(t,e)<0&&a.fn2.apply(t)})}}}};g.extend(g.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if(g.livequery.running&&g.livequery.queue.length)for(var a=g.livequery.queue.length;a--;)g.livequery.queries[g.livequery.queue.shift()].run()},
37 pause:function(){g.livequery.running=false},play:function(){g.livequery.running=true;g.livequery.run()},registerPlugin:function(){g.each(arguments,function(a,d){if(g.fn[d]){var e=g.fn[d];g.fn[d]=function(){var i=e.apply(this,arguments);g.livequery.run();return i}}})},run:function(a){if(a!=z)g.inArray(a,g.livequery.queue)<0&&g.livequery.queue.push(a);else g.each(g.livequery.queries,function(d){g.inArray(d,g.livequery.queue)<0&&g.livequery.queue.push(d)});g.livequery.timeout&&clearTimeout(g.livequery.timeout);
38 g.livequery.timeout=setTimeout(g.livequery.checkQueue,20)},stop:function(a){a!=z?g.livequery.queries[a].stop():g.each(g.livequery.queries,function(d){g.livequery.queries[d].stop()})}});g.livequery.registerPlugin("append","prepend","after","before","wrap","attr","removeAttr","addClass","removeClass","toggleClass","empty","remove");g(function(){g.livequery.play()});var ma=g.prototype.init;g.prototype.init=function(a,d){var e=ma.apply(this,arguments);if(a&&a.selector){e.context=a.context;e.selector=
39 a.selector}if(typeof a=="string"){e.context=d||document;e.selector=a}return e};g.prototype.init.prototype=g.prototype;var U=typeof window.localStorage!=="undefined";g.extend({Storage:{set:U?ea:$,get:U?fa:ga,remove:U?ha:ia}});jQuery.fn.extend({everyTime:function(a,d,e,i,h){return this.each(function(){jQuery.timer.add(this,a,d,e,i,h)})},oneTime:function(a,d,e){return this.each(function(){jQuery.timer.add(this,a,d,e,1)})},stopTime:function(a,d){return this.each(function(){jQuery.timer.remove(this,a,
40 d)})}});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(a){if(a==z||a===null)return null;var d=this.regex.exec(jQuery.trim(a.toString()));return d[2]?parseInt(d[1],10)*(this.powers[d[2]]||1):a},add:function(a,d,e,i,h,t){var v=0;if(jQuery.isFunction(e)){h||(h=i);i=e;e=d}d=jQuery.timer.timeParse(d);if(!(typeof d!="number"||isNaN(d)||d<=0)){if(h&&h.constructor!=Number){t=!!h;h=0}h=h||0;t=t||false;if(!a.$timers)a.$timers=
41 {};a.$timers[e]||(a.$timers[e]={});i.$timerID=i.$timerID||this.guid++;var C=function(){if(!(t&&this.inProgress)){this.inProgress=true;if(++v>h&&h!==0||i.call(a,v)===false)jQuery.timer.remove(a,e,i);this.inProgress=false}};C.$timerID=i.$timerID;a.$timers[e][i.$timerID]||(a.$timers[e][i.$timerID]=window.setInterval(C,d));this.global[e]||(this.global[e]=[]);this.global[e].push(a)}},remove:function(a,d,e){var i=a.$timers,h;if(i){if(d){if(i[d]){if(e){if(e.$timerID){window.clearInterval(i[d][e.$timerID]);
42 delete i[d][e.$timerID]}}else for(e in i[d]){window.clearInterval(i[d][e]);delete i[d][e]}for(h in i[d])break;if(!h){h=null;delete i[d]}}}else for(d in i)this.remove(a,d,e);for(h in i)break;if(!h)a.$timers=null}}}});if(jQuery.browser.msie)jQuery(window).one("unload",function(){var a=jQuery.timer.global,d;for(d in a)for(var e=a[d],i=e.length;--i;)jQuery.timer.remove(e[i],d)});var ja=/(\[\[[bius]*;[^;]*;[^\]]*\][^\]\[]*\])/g,Y=/\[\[([bius]*);([^;]*);([^\]]*)\]([^\]\[]*)\]/g,aa=/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})/;
43 g.json_stringify=function(a,d){var e="",i;d=d===z?1:d;switch(typeof a){case "function":e+=a;break;case "boolean":e+=a?"true":"false";break;case "object":if(a===null)e+="null";else if(a instanceof Array){e+="[";var h=a.length;for(i=0;i<h-1;++i)e+=g.json_stringify(a[i],d+1);e+=g.json_stringify(a[h-1],d+1)+"]"}else{e+="{";for(h in a)if(a.hasOwnProperty(h))e+='"'+h+'":'+g.json_stringify(a[h],d+1);e+="}"}break;case "string":h=a;var t={"\\\\":"\\\\",'"':'\\"',"/":"\\/","\\n":"\\n","\\r":"\\r","\\t":"\\t"};
44 for(i in t)if(t.hasOwnProperty(i))h=h.replace(RegExp(i,"g"),t[i]);e+='"'+h+'"';break;case "number":e+=String(a)}e+=d>1?",":"";if(d==1)e=e.replace(/,([\]}])/g,"$1");return e.replace(/([\[{]),/g,"$1")};g.fn.cmd=function(a){function d(){M.toggleClass("inverted")}function e(f){var q=f.substring(0,v-C-1);f=f.substring(v-C-1);return[q].concat(X(f,v))}function i(){t.focus();h.oneTime(1,function(){h.insert(t.val());t.blur().val("")})}var h=this;h.addClass("cmd");h.append('<span class="prompt"></span><span></span><span class="cursor">&nbsp;</span><span></span>');
45 var t=g("<textarea/>").addClass("clipboard").appendTo(h);a.width&&h.width(a.width);var v,C,L=a.mask||false,m="",n=0,I,J=a.enabled,V,G,M=h.find(".cursor"),c=function(f){function q(r,u){if(u==r.length){D.html(F(r));M.html("&nbsp;");H.html("")}else if(u===0){D.html("");M.html(F(r.slice(0,1)));H.html(F(r.slice(1)))}else{var o=F(r.slice(0,u));D.html(o);o=r.slice(u,u+1);M.html(o==" "?"&nbsp;":F(o));u==r.lenght-1?H.html(""):H.html(F(r.slice(u+1)))}}function K(r){return"<div>"+F(r)+"</div>"}function Q(r){var u=
46 H;g.each(r,function(o,y){u=g(K(y)).insertAfter(u).addClass("clear")})}function l(r){g.each(r,function(u,o){D.before(K(o))})}var D=M.prev(),H=M.next();return function(){var r=L?m.replace(/./g,"*"):m,u;f.find("div").remove();D.html("");if(r.length>v-C-1||r.match(/\n/)){var o,y=r.match(/\t/g),p=y?y.length*3:0;if(y)r=r.replace(/\t/g,"\u0000\u0000\u0000\u0000");if(r.match(/\n/)){var b=r.split("\n"),j=v-C-1;for(u=0;u<b.length-1;++u)b[u]+=" ";if(b[0].length>j){o=[b[0].substring(0,j)];o=o.concat(X(b[0].substring(j),
47 v))}else o=[b[0]];for(u=1;u<b.length;++u)if(b[u].length>v)o=o.concat(X(b[u],v));else o.push(b[u])}else o=e(r);if(y)o=g.map(o,function(k){return k.replace(/\x00\x00\x00\x00/g,"\t")});j=o[0].length;if(n<j){q(o[0],n);Q(o.slice(1))}else if(n==j){D.before(K(o[0]));q(o[1],0);Q(o.slice(2))}else{u=o.length;if(n<j){q(o[0],n);Q(o.slice(1))}else if(n==j){D.before(K(o[0]));q(o[1],0);Q(o.slice(2))}else{y=o.slice(-1)[0];b=r.length-n;r=0;if(b<=y.length){l(o.slice(0,-1));r=y.length==b?0:y.length-b;q(y,r+p)}else if(u==
48 3){D.before("<div>"+F(o[0])+"</div>");q(o[1],n-j-1);H.after('<div class="clear">'+F(o[2])+"</div>")}else{r=n;for(u=0;u<o.length;++u)if(r>o[u].length)r-=o[u].length;else break;p=o[u];j=u;if(r==p.length){r=0;p=o[++j]}q(p,r);l(o.slice(0,j));Q(o.slice(j+1))}}}}else if(r===""){D.html("");M.html("&nbsp;");H.html("")}else q(r,n)}}(h),N=function(){var f=h.find(".prompt");return function(){if(typeof I=="string"){C=I.replace(Y,"$4").length;f.html(F(I)+"&nbsp;")}else I(function(q){C=q.replace(Y,"$4").length;
49 f.html(F(q)+"&nbsp;")})}}();g.extend(h,{name:function(f){if(f!==z){V=f;G=new la(f)}else return V},history:function(){return G},set:function(f,q){if(f!==z){m=f;if(!q)n=m.length;c();if(typeof a.onCommandChange=="function")a.onCommandChange(m)}},insert:function(f,q){if(n==m.length)m+=f;else m=n===0?f+m:m.slice(0,n)+f+m.slice(n);q||(n+=f.length);c();if(typeof a.onCommandChange=="function")a.onCommandChange(m)},get:function(){return m},commands:function(f){if(f)a.commands=f;else return f},destroy:function(){g(document.documentElement).unbind(".commandline");
50 h.find(".prompt").remove()},prompt:function(f){if(f===z)return I;else{if(typeof f=="string"||typeof f=="function")I=f;else throw"prompt must be a function or string";N();c()}},position:function(f){if(typeof f=="number"){n=f<0?0:f>m.length?m.length:f;c()}else return n},show:function(){var f=h.show;return function(){f.apply(h,[]);c();N()}}(),resize:function(f){if(f)v=f;else{f=h.width();var q=M.innerWidth();v=Math.floor(f/q)}c()},enable:function(){if(!J){h.everyTime(500,"blink",d);J=true}},isenabled:function(){return J},
51 disable:function(){if(J){h.stopTime("blink",d);h.find(".cursor").removeClass("inverted");J=false}},mask:function(f){if(typeof f=="boolean"){L=f;c()}else return L}});h.name(a.name||"");I=a.prompt||">";N();if(a.enabled===z||a.enabled===true)h.enable();g(g.browser.msie?document.documentElement:window).keypress(function(f){var q;if(f.ctrlKey&&f.which==99)return true;if(a.keypress)q=a.keypress(f);if(q===z||q){if(J)if([38,32,13,0,8].has(f.which)&&f.keyCode!=123&&!(f.which==38&&f.shiftKey))return false;
52 else if(!f.ctrlKey&&!(f.altKey&&f.which==100)){h.insert(String.fromCharCode(f.which));return false}else f.altKey&&h.insert(String.fromCharCode(f.which))}else return q}).keydown(function(f){if(J){if(a.keydown&&a.keydown(f)===false)return false;var q;if(f.altKey){if(f.which==68){h.set(m.slice(0,n)+m.slice(n).replace(/[^ ]+ |[^ ]+$/,""),true);return false}return true}else if(f.keyCode==13){if(G&&m&&(a.historyFilter&&a.historyFilter(m)||!a.historyFilter))G.append(m);G.last();f=m;h.set("");a.commands&&
53 a.commands(f);typeof I=="function"&&N()}else if(f.which==32)h.insert(" ");else if(f.which==8){if(m!==""&&n>0){m=m.slice(0,n-1)+m.slice(n,m.length);--n;c()}}else if(f.which==9&&!(f.ctrlKey||f.altKey))h.insert("\t");else if(f.which==46){if(m!==""&&n<m.length){m=m.slice(0,n)+m.slice(n+1,m.length);c()}return true}else if(G&&f.which==38||f.which==80&&f.ctrlKey)h.set(G.previous());else if(G&&f.which==40||f.which==78&&f.ctrlKey)h.set(G.next());else if(f.which==37||f.which==66&&f.ctrlKey)if(f.ctrlKey&&f.which!=
54 66){q=n-1;f=0;for(m[q]==" "&&--q;q>0;--q)if(m[q]==" "&&m[q+1]!=" "){f=q+1;break}else if(m[q]=="\n"&&m[q+1]!="\n"){f=q;break}h.position(f)}else{if(n>0){--n;c()}}else if(f.which==39||f.which==70&&f.ctrlKey)if(f.ctrlKey&&f.which!=70){m[n]==" "&&++n;f=m.slice(n).match(/\S[\n\s]{2,}|[\n\s]+\S?/);if(!f||f[0].match(/^\s+$/))n=m.length;else if(f[0][0]!=" ")n+=f.index+1;else{n+=f.index+f[0].length-1;f[0][f[0].length-1]!=" "&&--n}c()}else{if(n<m.length){++n;c()}}else if(f.which==123)return true;else if(f.which==
55 36)h.position(0);else if(f.which==35)h.position(m.length);else if(f.ctrlKey||f.metaKey)if(f.shiftKey){if(f.which==84)return true}else if(f.which==65)h.position(0);else if(f.which==69)h.position(m.length);else if(f.which==88||f.which==67||f.which==87||f.which==84)return true;else if(f.which==86){i();return true}else if(f.which==75)if(n===0)h.set("");else n!=m.length&&h.set(m.slice(0,n));else if(f.which==85){h.set(m.slice(n,m.length));h.position(0)}else{if(f.which==17)return true}else return true;return false}});
56 return h};g.jrpc=function(a,d,e,i,h,t){d=g.json_stringify({jsonrpc:"2.0",method:e,params:i,id:d});return g.ajax({url:a,data:d,success:h,error:t,contentType:"application/json",dataType:"json",async:true,cache:false,type:"POST"})};U=/ {14}$/;var na=[["jQuery Terminal","(c) 2011 jcubic"],["JQuery Terminal Emulator v. 0.4.12","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>".replace(/ *<.*>/,"")],["JQuery Terminal Emulator version version 0.4.12","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"],
57 ["      _______                 ________                        __","     / / _  /_ ____________ _/__  ___/______________  _____  / /"," __ / / // / // / _  / _/ // / / / _  / _/     / /  \\/ / _ \\/ /","/  / / // / // / ___/ // // / / / ___/ // / / / / /\\  / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/ /_/ /_/  \\/\\__\\_\\___/","         \\/          /____/                                   ".replace(U,"")+"version 0.4.12","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"],
58 ["      __ _____                     ________                              __","     / // _  /__ __ _____ ___ __ _/__  ___/__ ___ ______ __ __  __ ___  / /"," __ / // // // // // _  // _// // / / // _  // _//     // //  \\/ // _ \\/ /","/  / // // // // // ___// / / // / / // ___// / / / / // // /\\  // // / /__","\\___//____ \\\\___//____//_/ _\\_  / /_//____//_/ /_/ /_//_//_/ /_/ \\__\\_\\___/","          \\/              /____/                                          ".replace(U,"")+"version 0.4.12",
59 "Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"]],oa=[],O=new function(a){var d=a?[a]:[],e=0;g.extend(this,{rotate:function(){if(d.length==1)return d[0];else{if(e==d.length-1)e=0;else++e;return d[e]}},length:function(){return d.length},set:function(i){for(var h=d.length;h--;)if(d[h]===i){e=h;return}this.append(i)},front:function(){return d[e]},append:function(i){d.push(i)}})};g.fn.terminal=function(a,d){function e(){return c.get(0).scrollHeight>c.innerHeight()}function i(){var b=c.find(".cursor").width(),
60 j=Math.floor(c.width()/b);if(e()){var k=c.innerWidth()-c.width();j-=Math.ceil((20-k/2)/(b-1))}return j}function h(b,j){c.error("&#91;"+j+"&#93;: "+(typeof b=="string"?b:b.fileName+": "+b.message));c.pause();typeof b.fileName=="string"&&g.get(b.fileName,function(k){c.resume();var w=b.lineNumber-1;(k=k.split("\n")[w])&&c.error("&#91;"+b.lineNumber+"&#93;: "+k)})}function t(b,j){try{if(typeof j=="function")j(function(){});else if(typeof j!="string")throw b+" must be string or function";}catch(k){h(k,
61 b.toUpperCase());return false}return true}function v(){var b=c.prop?c.prop("scrollHeight"):c.attr("scrollHeight");c.scrollTop(b)}function C(b){b=typeof b=="string"?b:String(b);var j,k,w;if(b.length>K){j=K;k=b.split(/\n/g);w=/(\[\[[bius]*;[^;]*;[^\]]*\][^\]\[]*\]?)/g;var s=/(\[\[[bius]*;[^;]*;[^\]]*\])/,A=/\[\[[bius]*;?[^;]*;?[^\]]*\]?$/,x=false,E=false,B="";b=[];for(var T=0,pa=k.length;T<pa;++T){if(B!=="")if(k[T]===""){b.push(B+"]");continue}else{k[T]=B+k[T];B=""}else if(k[T]===""){b.push("");continue}for(var W=
62 k[T],ca=0,Z=0,R=0,da=W.length;R<da;++R){if(W[R]=="["&&W[R+1]=="[")x=true;else if(x&&W[R]=="]")if(E)E=x=false;else E=true;else if(x&&E||!x)++Z;if(Z==j||R==da-1){var P=W.substring(ca,R+1);if(B){P=B+P;if(P.match("]"))B=""}ca=R+1;Z=0;var S=P.match(w);if(S){S=S[S.length-1];if(S[S.length-1]!="]"){B=S.match(s)[1];P+="]"}else if(P.match(A)){P=P.replace(A,"");B=S.match(s)[1]}}b.push(P)}}}j=g("<div></div>");k=0;for(w=b.length;k<w;++k)b[k]===""||b[k]=="\r"?j.append("<div>&nbsp;</div>"):g("<div/>").html(F(b[k])).appendTo(j)}else j=
63 g("<div/>").html(F(b));f.append(j);j.width("100%");v();return j}function L(b,j){var k=1,w=function(s,A){j.pause();g.jrpc(b,k++,s,A,function(x){if(x.error)j.error("&#91;RPC&#93; "+x.error.message);else if(typeof x.result=="string")j.echo(x.result);else if(x.result instanceof Array)j.echo(x.result.join(" "));else if(typeof x.result=="object"){var E="",B;for(B in x.result)if(x.result.hasOwnProperty(B))E+=B+": "+x.result[B]+"\n";j.echo(E)}j.resume()},function(x,E){j.error("&#91;AJAX&#93; "+E+" - Server reponse is: \n"+
64 x.responseText);j.resume()})};return function(s,A){if(s!==""){var x,E;if(s.match(/[^ ]* /)){s=s.split(/ +/);x=s[0];E=s.slice(1)}else{x=s;E=[]}if(!l.login||x=="help")w(x,E);else{var B=A.token();B?w(x,[B].concat(E)):A.error("&#91;AUTH&#93; Access denied (no token)")}}}}function m(b){var j=p.prompt();if(p.mask())b=b.replace(/./g,"*");typeof j=="function"?j(function(k){c.echo(k+" "+b)}):c.echo(j+" "+b)}function n(b){try{var j=y.top();if(b=="exit"&&l.exit)if(y.size()==1)l.login?J():c.echo("You can exit from main interpeter");
65 else c.pop("exit");else{m(b);b=="clear"&&l.clear?c.clear():j.eval(b,c)}}catch(k){h(k,"USER");c.resume();throw k;}}function I(){var b=null;p.prompt("login:");l.history&&p.history().disable();p.commands(function(j){try{m(j);if(b){p.mask(false);c.pause();if(typeof l.login!="function")throw"Value of login property must be a function";l.login(b,j,function(w){if(w){var s=l.name;s=s?"_"+s:"";g.Storage.set("token"+s,w);g.Storage.set("login"+s,b);p.commands(n);G()}else{c.error("Wrong password try again");
66 p.prompt("login:");b=null}c.resume();l.history&&p.history().enable()})}else{b=j;p.prompt("password:");p.mask(true)}}catch(k){h(k,"LOGIN",c);throw k;}})}function J(){var b=l.name;b=b?"_"+b:"";g.Storage.remove("token"+b,null);g.Storage.remove("login"+b,null);l.history&&p.history().disable();I()}function V(){var b=y.top(),j="";if(b.name!==z&&b.name!=="")j+=b.name+"_";j+=q;p.name(j);p.prompt(b.prompt);l.history&&p.history().enable();p.set("");if(typeof b.onStart=="function")b.onStart(c)}function G(){V();
67 if(d.greetings===z)c.echo(c.signature);else d.greetings&&c.echo(d.greetings);if(typeof l.onInit=="function")l.onInit(c)}function M(b){c.oneTime(5,function(){if(r!=e()){c.resize();r=e()}});if(!c.paused()){if(l.keydown&&l.keydown(b,c)===false)return false;if(b.which!=9)H=0;if(b.which==68&&b.ctrlKey){if(l.exit)if(p.get()==="")if(y.size()>1||l.login!==z)c.pop("");else{c.resume();c.echo("")}else c.set_command("");b.preventDefault()}else if(l.tabcompletion&&b.which==9){++H;b=p.get();if(!b.match(" ")){for(var j=
68 RegExp("^"+b),k=y.top().command_list,w=[],s=k.length;s--;)j.test(k[s])&&w.push(k[s]);if(w.length==1)c.set_command(w[0]);else if(w.length>1)if(H>=2){m(b);c.echo(w.join("\t"));H=0}}return false}else if(b.which==86&&b.ctrlKey){c.oneTime(1,function(){v()});return true}else if(b.which==9&&b.ctrlKey){O.length()>1&&c.focus(false);b.preventDefault()}else if(b.which==34)c.scroll(c.height());else b.which==33?c.scroll(-c.height()):c.attr({scrollTop:c.attr("scrollHeight")})}}var c=this,N=[],f,q=O.length(),K,
69 Q=[],l={name:"",prompt:">",history:true,exit:true,clear:true,enabled:true,login:null,tabcompletion:false,onInit:null,onExit:null,keypress:null,keydown:null};if(d){d.width&&c.width(d.width);d.height&&c.height(d.height);g.extend(l,d)}var D=!l.enabled;if(c.length===0)throw'Sorry, but terminal said that "'+c.selector+'" is not valid selector!';c.ajaxSend(function(b,j){oa.push(j)});if(c.data("terminal"))return c.data("terminal");f=g("<div>").addClass("terminal-output").appendTo(c);c.addClass("terminal").append("<div/>");
70 g.extend(c,{clear:function(){f.html("");p.set("");N=[];c.attr({scrollTop:0});return c},paused:function(){return D},pause:function(){if(p){c.disable();p.hide()}return c},resume:function(){if(p){c.enable();p.show();v()}return c},cols:function(){return K},rows:function(){return N.length},history:function(){return p.history()},next:function(){if(O.length()==1)return c;else{var b=c.offset().top;c.height();c.scrollTop();var j=c,k=g(window).scrollTop(),w=k+g(window).height(),s=g(j).offset().top;if(s+g(j).height()>=
71 k&&s<=w){O.front().disable();b=O.rotate().enable();j=b.offset().top-50;g("html,body").animate({scrollTop:j},500);return b}else{c.enable();g("html,body").animate({scrollTop:b-50},500);return c}}},focus:function(b){c.oneTime(1,function(){if(O.length()==1)b===false?c.disable():c.enable();else if(b===false)c.next();else{O.front().disable();O.set(c);c.enable()}});return c},enable:function(){K===z&&c.resize();if(D)if(p){p.enable();D=false}return c},disable:function(){if(p){D=true;p.disable()}return c},
72 enabled:function(){return D},signature:function(){var b=c.cols();b=b<15?null:b<35?0:b<55?1:b<64?2:b<75?3:4;return b!==null?na[b].join("\n")+"\n":""},version:function(){return"0.4.12"},get_command:function(){return p.get()},insert:function(b){p.insert(b);return c},set_prompt:function(b){t("prompt",b)&&p.prompt(b);return c},get_prompt:function(){return p.prompt()},set_command:function(b){p.set(b);return c},set_mask:function(b){p.mask(b);return c},get_output:function(){return g.map(N,function(b,j){return typeof j==
73 "function"?j():j}).get().join("\n")},resize:function(b,j){if(b&&j){c.width(b);c.height(j)}K=i();p.resize(K);var k=f.detach();f.html("");g.each(N,function(w,s){C(typeof s=="function"?s():s)});c.prepend(k);v();return c},echo:function(b){N.push(b);return C(typeof b=="function"?b():b)},error:function(b){c.echo("[[;#f00;]"+b.replace(/\[/g,"&#91;").replace(/\]/g,"&#93;")+"]")},scroll:function(b){var j;if(c.prop){b>c.prop("scrollTop")&&b>0&&c.prop("scrollTop",0);j=c.prop("scrollTop");c.prop("scrollTop",
74 j+b)}else{b>c.attr("scrollTop")&&b>0&&c.attr("scrollTop",0);j=c.attr("scrollTop");c.attr("scrollTop",j+b)}return c},logout:l.login?function(){for(;y.size()>1;)y.pop();J();return c}:function(){throw"You don't have login function";},token:l.login?function(){var b=l.name;return g.Storage.get("token"+(b?"_"+b:""))}:null,login_name:l.login?function(){var b=l.name;return g.Storage.get("login"+(b?"_"+b:""))}:null,name:function(){return l.name},push:function(b,j){if(!j.prompt||t("prompt",j.prompt)){if(typeof b==
75 "string")b=L(j.eval,c);y.push(g.extend({eval:b},j));V()}return c},pop:function(b){b!==z&&m(b);if(y.top().name===l.name){if(l.login){J();if(typeof l.onExit=="function")l.onExit(c)}}else{b=y.pop();V();if(typeof b.onExit=="function")b.onExit(c)}return c}});var H=0,r=e(),u;if(l.login&&typeof l.onBeforeLogin=="function")l.onBeforeLogin(c);if(a.constructor==String){u=a;a=L(a,c)}else if(a.constructor==Array)throw"You can't use array as eval";else if(typeof a=="object"){for(var o in a)Q.push(o);a=function b(j){return function(k){if(k!==
76 ""){k=k.split(/ +/);var w=k[0],s=k.slice(1);k=j[w];var A=typeof k;if(A=="function")k.apply(c,s);else if(A=="object"||A=="string"){s=[];if(A=="object"){for(var x in k)s.push(x);k=b(k)}c.push(k,{prompt:w+">",name:w,command_list:s})}else c.error("Command '"+w+"' Not Found")}}}(a)}else if(typeof a!="function")throw'Unknow object "'+String(a)+'" passed as eval';if(u&&(typeof l.login=="string"||l.login))l.login=function(b){var j=1;return function(k,w,s){c.pause();g.jrpc(u,j++,b,[k,w],function(A){c.resume();
77 !A.error&&A.result?s(A.result):s(null)},function(A,x){c.resume();c.error("&#91;AJAX&#92; Response: "+x+"\n"+A.responseText)})}}(typeof l.login=="boolean"?"login":l.login);if(t("prompt",l.prompt)){var y=new ka({name:l.name,eval:a,prompt:l.prompt,command_list:Q,greetings:l.greetings}),p=c.find(".terminal-output").next().cmd({prompt:l.prompt,history:l.history,width:"100%",keydown:M,keypress:l.keypress?function(b){return l.keypress(b,c)}:null,onCommandChange:function(b){if(typeof l.onCommandChange=="function")l.onCommandChange(b,
78 c);v()},commands:n});c.livequery(function(){c.resize()});O.append(c);l.enabled===true?c.focus():c.disable();g(window).resize(c.resize);c.click(function(){c.focus()});c.token&&!c.token()&&c.login_name&&!c.login_name()?I():G();typeof g.fn.init.prototype.mousewheel==="function"&&c.mousewheel(function(b,j){j>0?c.scroll(-40):c.scroll(40);return false},true)}c.data("terminal",c);return c}})(jQuery);