Last active
August 29, 2015 13:57
-
-
Save bawNg/9873327 to your computer and use it in GitHub Desktop.
Simple embedded REPL development console for sinatra/coffeescript/haml/stylus web applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready -> | |
highlight_json = (json) -> | |
output = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') | |
output = output.replace /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, (match) -> | |
type = 'number' | |
if /^"/.test(match) | |
if /:$/.test(match) | |
type = 'key' | |
else | |
type = 'string' | |
else if /true|false/.test(match) | |
type = 'boolean' | |
else if /null/.test(match) | |
type = 'null' | |
color = switch type | |
when 'key' then '#C4BEFF' | |
when 'string' then '#86F570' | |
when 'number' then '#7CF55B' | |
when 'boolean' then '#009fff' | |
when 'null' then 'lightblue' | |
'[[;' + color + ';#0]' + match + ']' | |
output | |
$term = $('<div class="td"/>') | |
$('body').append $('<div class="tilda"/>').html $term | |
focus = false | |
$term.terminal ((command, term) -> | |
return '' if command == '' | |
$.ajax | |
type: 'POST' | |
url: '/debug/exec' | |
data: { q: command } | |
dataType: 'json' | |
success: (response) -> | |
if response.error | |
$backtrace = $('<pre class="backtrace"/>') | |
$backtrace.text("Exception: #{response.error}\n#{response.backtrace}") | |
term.echo($backtrace[0].outerHTML, raw: true) | |
else | |
term.echo(response.out) if response.out.length | |
json = JSON.stringify(response.ret, undefined, 2) | |
highlighted_json = highlight_json(json) | |
term.echo(highlighted_json) | |
return | |
), | |
greetings: (send_greeting) -> | |
sent_at = now() | |
$.ajax type: 'POST', url: '/debug/exec', q: 1, dataType: 'json', success: -> | |
send_greeting "Connection established. Latency: #{Math.round((now() - sent_at) / 2.0 * 1000)} ms" | |
name: 'debug_console' | |
height: 900 | |
prompt: '>> ' | |
enabled: false | |
keydown: (e) -> | |
if e.keyCode == 192 # tilda | |
$term.slideToggle('fast') | |
$term.focus(focus = !focus) | |
false | |
completion: (terminal, input, callback) -> | |
$.ajax | |
type: 'POST' | |
url: '/debug/methods' | |
data: { q: input } | |
dataType: 'json' | |
success: callback | |
$(document.documentElement).keypress (e) -> | |
return unless e.charCode == 96 # tilda | |
$term.slideToggle('fast') | |
$term.focus(focus = !focus) | |
if focus | |
$term.enable() | |
else | |
$term.disable() | |
false | |
$term.hide() | |
$term.disable() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tilda .terminal | |
background-color: rgba(0, 0, 0, 0.97) | |
.cmd | |
background-color: rgba(0, 0, 0, 0.3) | |
.backtrace | |
margin-top: 5px | |
max-height: 200px | |
width: 800px | |
color: red | |
padding-top: 5px | |
background: transparent | |
border-color: #808080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(c){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),e=0,h=0,f=0;a=c.event.fix(b);a.type="mousewheel";if(b.wheelDelta)e=b.wheelDelta/120;if(b.detail)e=-b.detail/3;f=e;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){f=0;h=-1*e}if(b.wheelDeltaY!==undefined)f=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,e,h,f);return(c.event.dispatch||c.event.handle).apply(this,i)}var d=["DOMMouseScroll","mousewheel"];if(c.event.fixHooks)for(var j=d.length;j;)c.event.fixHooks[d[--j]]= | |
c.event.mouseHooks;c.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=d.length;a;)this.addEventListener(d[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=d.length;a;)this.removeEventListener(d[--a],g,false);else this.onmousewheel=null}};c.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**@license | |
* __ _____ ________ __ | |
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / | |
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / | |
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ | |
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ | |
* \/ /____/ version 0.8.7 | |
* http://terminal.jcubic.pl | |
* | |
* Licensed under GNU LGPL Version 3 license | |
* Copyright (c) 2011-2013 Jakub Jankiewicz <http://jcubic.pl> | |
* | |
* Includes: | |
* | |
* Storage plugin Distributed under the MIT License | |
* Copyright (c) 2010 Dave Schindler | |
* | |
* jQuery Timers licenced with the WTFPL | |
* <http://jquery.offput.ca/every/> | |
* | |
* Cross-Browser Split 1.1.1 | |
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com> | |
* Available under the MIT License | |
* | |
* sprintf.js | |
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro> | |
* licensed under 3 clause BSD license | |
* | |
* Date: Sat, 22 Mar 2014 13:32:26 +0000 | |
* | |
*/(function(e){function r(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,t){for(var n=[];t>0;n[--t]=e);return n.join("")}var t=function(){return t.cache.hasOwnProperty(arguments[0])||(t.cache[arguments[0]]=t.parse(arguments[0])),t.format.call(null,t.cache[arguments[0]],arguments)};t.format=function(e,n){var s=1,o=e.length,u="",a,f=[],l,c,h,p,d,v;for(l=0;l<o;l++){u=r(e[l]);if(u==="string")f.push(e[l]);else if(u==="array"){h=e[l];if(h[2]){a=n[s];for(c=0;c<h[2].length;c++){if(!a.hasOwnProperty(h[2][c]))throw t('[sprintf] property "%s" does not exist',h[2][c]);a=a[h[2][c]]}}else h[1]?a=n[h[1]]:a=n[s++];if(/[^s]/.test(h[8])&&r(a)!="number")throw t("[sprintf] expecting number but found %s",r(a));switch(h[8]){case"b":a=a.toString(2);break;case"c":a=String.fromCharCode(a);break;case"d":a=parseInt(a,10);break;case"e":a=h[7]?a.toExponential(h[7]):a.toExponential();break;case"f":a=h[7]?parseFloat(a).toFixed(h[7]):parseFloat(a);break;case"o":a=a.toString(8);break;case"s":a=(a=String(a))&&h[7]?a.substring(0,h[7]):a;break;case"u":a>>>=0;break;case"x":a=a.toString(16);break;case"X":a=a.toString(16).toUpperCase()}a=/[def]/.test(h[8])&&h[3]&&a>=0?"+"+a:a,d=h[4]?h[4]=="0"?"0":h[4].charAt(1):" ",v=h[6]-String(a).length,p=h[6]?i(d,v):"",f.push(h[5]?a+p:p+a)}}return f.join("")},t.cache={},t.parse=function(e){var t=e,n=[],r=[],i=0;while(t){if((n=/^[^\x25]+/.exec(t))!==null)r.push(n[0]);else if((n=/^\x25{2}/.exec(t))!==null)r.push("%");else{if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))===null)throw"[sprintf] huh?";if(n[2]){i|=1;var s=[],o=n[2],u=[];if((u=/^([a-z_][a-z_\d]*)/i.exec(o))===null)throw"[sprintf] huh?";s.push(u[1]);while((o=o.substring(u[0].length))!=="")if((u=/^\.([a-z_][a-z_\d]*)/i.exec(o))!==null)s.push(u[1]);else{if((u=/^\[(\d+)\]/.exec(o))===null)throw"[sprintf] huh?";s.push(u[1])}n[2]=s}else i|=2;if(i===3)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";r.push(n)}t=t.substring(n[0].length)}return r};var n=function(e,n,r){return r=n.slice(0),r.splice(0,0,e),t.apply(null,r)};e.sprintf=t,e.vsprintf=n})(typeof exports!="undefined"?exports:window),function(e,t){"use strict";function r(e,t){var n;if(typeof e=="string"&&typeof t=="string")return localStorage[e]=t,!0;if(typeof e=="object"&&typeof t=="undefined"){for(n in e)e.hasOwnProperty(n)&&(localStorage[n]=e[n]);return!0}return!1}function i(e,t){var n,r,i;n=new Date,n.setTime(n.getTime()+31536e6),r="; expires="+n.toGMTString();if(typeof e=="string"&&typeof t=="string")return document.cookie=e+"="+t+r+"; path=/",!0;if(typeof e=="object"&&typeof t=="undefined"){for(i in e)e.hasOwnProperty(i)&&(document.cookie=i+"="+e[i]+r+"; path=/");return!0}return!1}function s(e){return localStorage[e]}function o(e){var t,n,r,i;t=e+"=",n=document.cookie.split(";");for(r=0;r<n.length;r++){i=n[r];while(i.charAt(0)===" ")i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function u(e){return delete localStorage[e]}function a(e){return i(e,"",-1)}function f(e,t){var n=[],r=e.length;if(r<t)return[e];for(var i=0;i<r;i+=t)n.push(e.substring(i,i+t));return n}function l(t){var n=t?[t]:[],r=0;e.extend(this,{get:function(){return n},rotate:function(){return n.length===1?n[0]:(r===n.length-1?r=0:++r,n[r])},length:function(){return n.length},set:function(e){for(var t=n.length;t--;)if(n[t]===e){r=t;return}this.append(e)},front:function(){return n[r]},append:function(e){n.push(e)}})}function c(t){var n=t?[t]:[];e.extend(this,{map:function(t){return e.map(n,t)},size:function(){return n.length},pop:function(){if(n.length===0)return null;var e=n[n.length-1];return n=n.slice(0,n.length-1),e},push:function(e){return n=n.concat([e]),e},top:function(){return n.length>0?n[n.length-1]:null}})}function h(t,n){var r=!0,i="";typeof t=="string"&&t!==""&&(i=t+"_"),i+="commands";var s=e.Storage.get(i);s=s?e.parseJSON(s):[];var o=s.length-1;e.extend(this,{append:function(t){r&&s[s.length-1]!==t&&(s.push(t),n&&s.length>n&&(s=s.slice(-n)),o=s.length-1,e.Storage.set(i,e.json_stringify(s)))},data:function(){return s},reset:function(){o=s.length-1},last:function(){return s[length-1]},end:function(){return o===s.length-1},position:function(){return o},current:function(){return s[o]},next:function(){o<s.length-1&&++o;if(o!==-1)return s[o]},previous:function(){var e=o;o>0&&--o;if(e!==-1)return s[o]},clear:function(){s=[],this.purge()},enabled:function(){return r},enable:function(){r=!0},purge:function(){e.Storage.remove(i)},disable:function(){r=!1}})}function p(t){return e("<div>"+e.terminal.strip(t)+"</div>").text().length}function d(e){return e.length-p(e)}function v(){var e=!1,n="animation",r="",i="Webkit Moz O ms Khtml".split(" "),s="",o=document.createElement("div");o.style.animationName&&(e=!0);if(e===!1)for(var u=0;u<i.length;u++)if(o.style[i[u]+"AnimationName"]!==t){s=i[u],n=s+"Animation",r="-"+s.toLowerCase()+"-",e=!0;break}return e}function m(e,t){var n=e.replace(/^\s+|\s+$/g,"").split(/(\s+)/),r=e.replace(/^[^\s]+\s*/,"");return{name:n[0],args:t(r),rest:r}}function A(t){var n=e(window).scrollTop(),r=n+e(window).height(),i=e(t).offset().top,s=i+e(t).height();return s>=n&&i<=r}function O(){var t=e('<div class="terminal"><div class="cmd"><span> </span></div></div>').appendTo("body"),n=t.find("span"),r={width:n.width(),height:n.outerHeight()};return t.remove(),r}function M(e){var t=O().width,n=Math.floor(e.width()/t);if(P(e)){var r=20,i=e.innerWidth()-e.width();n-=Math.ceil((r-i/2)/(t-1))}return n}function _(e){return Math.floor(e.height()/O().height)}function D(){if(window.getSelection||document.getSelection){var e=(window.getSelection||document.getSelection)();return e.text?e.text:e.toString()}if(document.selection)return document.selection.createRange().text}function P(e){return e.get(0).scrollHeight>e.innerHeight()}e.omap=function(t,n){var r={};return e.each(t,function(e,i){r[e]=n.call(t,e,i)}),r};var n=typeof window.localStorage!="undefined";e.extend({Storage:{set:n?r:i,get:n?s:o,remove:n?u:a}}),jQuery.fn.extend({everyTime:function(e,t,n,r,i){return this.each(function(){jQuery.timer.add(this,e,t,n,r,i)})},oneTime:function(e,t,n){return this.each(function(){jQuery.timer.add(this,e,t,n,1)})},stopTime:function(e,t){return this.each(function(){jQuery.timer.remove(this,e,t)})}}),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===t||e===null)return null;var n=this.regex.exec(jQuery.trim(e.toString()));if(n[2]){var r=parseInt(n[1],10),i=this.powers[n[2]]||1;return r*i}return e},add:function(e,t,n,r,i,s){var o=0;jQuery.isFunction(n)&&(i||(i=r),r=n,n=t),t=jQuery.timer.timeParse(t);if(typeof t!="number"||isNaN(t)||t<=0)return;i&&i.constructor!==Number&&(s=!!i,i=0),i=i||0,s=s||!1,e.$timers||(e.$timers={}),e.$timers[n]||(e.$timers[n]={}),r.$timerID=r.$timerID||this.guid++;var u=function(){if(s&&u.inProgress)return;u.inProgress=!0,(++o>i&&i!==0||r.call(e,o)===!1)&&jQuery.timer.remove(e,n,r),u.inProgress=!1};u.$timerID=r.$timerID,e.$timers[n][r.$timerID]||(e.$timers[n][r.$timerID]=window.setInterval(u,t)),this.global[n]||(this.global[n]=[]),this.global[n].push(e)},remove:function(e,t,n){var r=e.$timers,i;if(r){if(!t)for(var s in r)r.hasOwnProperty(s)&&this.remove(e,s,n);else if(r[t]){if(n)n.$timerID&&(window.clearInterval(r[t][n.$timerID]),delete r[t][n.$timerID]);else for(var o in r[t])r[t].hasOwnProperty(o)&&(window.clearInterval(r[t][o]),delete r[t][o]);for(i in r[t])if(r[t].hasOwnProperty(i))break;i||(i=null,delete r[t])}for(i in r)if(r.hasOwnProperty(i))break;i||(e.$timers=null)}}}}),/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())&&jQuery(window).one("unload",function(){var e=jQuery.timer.global;for(var t in e)if(e.hasOwnProperty(t)){var n=e[t],r=n.length;while(--r)jQuery.timer.remove(n[r],t)}}),function(e){if(!String.prototype.split.toString().match(/\[native/))return;var t=String.prototype.split,n=/()??/.exec("")[1]===e,r;return r=function(r,i,s){if(Object.prototype.toString.call(i)!=="[object RegExp]")return t.call(r,i,s);var o=[],u=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.extended?"x":"")+(i.sticky?"y":""),a=0,f,l,c,h;i=new RegExp(i.source,u+"g"),r+="",n||(f=new RegExp("^"+i.source+"$(?!\\s)",u)),s=s===e?-1>>>0:s>>>0;while(l=i.exec(r)){c=l.index+l[0].length;if(c>a){o.push(r.slice(a,l.index)),!n&&l.length>1&&l[0].replace(f,function(){for(var t=1;t<arguments.length-2;t++)arguments[t]===e&&(l[t]=e)}),l.length>1&&l.index<r.length&&Array.prototype.push.apply(o,l.slice(1)),h=l[0].length,a=c;if(o.length>=s)break}i.lastIndex===l.index&&i.lastIndex++}return a===r.length?(h||!i.test(""))&&o.push(""):o.push(r.slice(a)),o.length>s?o.slice(0,s):o},String.prototype.split=function(e,t){return r(this,e,t)},r}(),e.json_stringify=function(n,r){var i="",s;r=r===t?1:r;var o=typeof n;switch(o){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 u=n.length;for(s=0;s<u-1;++s)i+=e.json_stringify(n[s],r+1);i+=e.json_stringify(n[u-1],r+1)+"]"}else{i+="{";for(var a in n)n.hasOwnProperty(a)&&(i+='"'+a+'":'+e.json_stringify(n[a],r+1));i+="}"}break;case"string":var f=n,l={"\\\\":"\\\\",'"':'\\"',"/":"\\/","\\n":"\\n","\\r":"\\r","\\t":"\\t"};for(s in l)l.hasOwnProperty(s)&&(f=f.replace(new RegExp(s,"g"),l[s]));i+='"'+f+'"';break;case"number":i+=String(n)}return i+=r>1?",":"",r===1&&(i=i.replace(/,([\]}])/g,"$1")),i.replace(/([\[{]),/g,"$1")},e.fn.cmd=function(n){function L(e){C.toggleClass("inverted")}function A(){E="(reverse-i-search)`"+l+"': ",F()}function O(){E=d,a=!1,c=null,l=""}function M(e){var t=N.data(),n,i,s=t.length;e&&c>0&&(s-=c);if(l.length>0)for(var o=l.length;o>0;o--){i=l.substring(0,o).replace(/([.*+{}\[\]?])/g,"\\$1"),n=new RegExp(i);for(var u=s;u--;)if(n.test(t[u])){c=t.length-u,w=0,r.set(t[u],!0),B(),l.length!==o&&(l=l.substring(0,o),A());return}}l=""}function _(){var e=r.width(),t=C.innerWidth();o=Math.floor(e/t)}function P(e,t){var n="";for(var r=t;r--;)n+=e;return n}function H(e){var t=e.substring(0,o-u),n=e.substring(o-u);return[t].concat(f(n,o))}function I(){s.focus(),r.oneTime(1,function(){r.insert(s.val()),s.blur().val("")})}function R(e){var i,s,o;if(typeof n.keydown=="function"){i=n.keydown(e);if(i!==t)return i}if(S){e.which!==38&&(e.which!==80||!e.ctrlKey)&&(q=!0);if(!a||e.which!==35&&e.which!==36&&e.which!==37&&e.which!==38&&e.which!==39&&e.which!==40&&e.which!==13&&e.which!==27){if(e.altKey)return e.which===68?(r.set(g.slice(0,w)+g.slice(w).replace(/[^ ]+ |[^ ]+$/,""),!0),!1):!0;if(e.keyCode===13)if(e.shiftKey)r.insert("\n");else{N&&g&&!m&&(typeof n.historyFilter=="function"&&n.historyFilter(g)||!n.historyFilter)&&N.append(g);var u=g;N.reset(),r.set(""),n.commands&&n.commands(u),typeof E=="function"&&F()}else if(e.which===8)a?(l=l.slice(0,-1),A()):g!==""&&w>0&&(g=g.slice(0,w-1)+g.slice(w,g.length),--w,B());else if(e.which===67&&e.ctrlKey&&e.shiftKey)y=D();else if(e.which===86&&e.ctrlKey&&e.shiftKey)y!==""&&r.insert(y);else if(e.which===9&&!e.ctrlKey&&!e.altKey)r.insert(" ");else{if(e.which===46)return g!==""&&w<g.length&&(g=g.slice(0,w)+g.slice(w+1,g.length),B()),!0;if(N&&e.which===38||e.which===80&&e.ctrlKey)q?(j=g,r.set(N.current())):r.set(N.previous()),q=!1;else if(N&&e.which===40||e.which===78&&e.ctrlKey)r.set(N.end()?j:N.next());else if(e.which===37||e.which===66&&e.ctrlKey)if(e.ctrlKey&&e.which!==66){o=w-1,s=0,g[o]===" "&&--o;for(var f=o;f>0;--f){if(g[f]===" "&&g[f+1]!==" "){s=f+1;break}if(g[f]==="\n"&&g[f+1]!=="\n"){s=f;break}}r.position(s)}else w>0&&(--w,B());else if(e.which===82&&e.ctrlKey)a?M(!0):(d=E,A(),j=g,g="",B(),a=!0);else if(e.which==71&&e.ctrlKey)a&&(E=d,F(),g=j,B(),a=!1,l="");else if(e.which===39||e.which===70&&e.ctrlKey)if(e.ctrlKey&&e.which!==70){g[w]===" "&&++w;var c=/\S[\n\s]{2,}|[\n\s]+\S?/,h=g.slice(w).match(c);!h||h[0].match(/^\s+$/)?w=g.length:h[0][0]!==" "?w+=h.index+1:(w+=h.index+h[0].length-1,h[0][h[0].length-1]!==" "&&--w),B()}else w<g.length&&(++w,B());else{if(e.which===123)return!0;if(e.which===36)r.position(0);else if(e.which===35)r.position(g.length);else{if(e.shiftKey&&e.which==45)return I(),!0;if(!e.ctrlKey&&!e.metaKey)return!0;if(e.which===192)return!0;if(e.metaKey){if(e.which===82)return!0;if(e.which===76)return!0}if(e.shiftKey){if(e.which===84)return!0}else{if(e.which===81){if(g!==""&&w!==0){var p=g.slice(0,w),v=g.slice(w+1),x=p.match(/([^ ]+ *$)/);w=p.length-x[0].length,b=p.slice(w),g=p.slice(0,w)+v,B()}return!1}if(e.which===72)return g!==""&&w>0&&(g=g.slice(0,--w),w<g.length-1&&(g+=g.slice(w)),B()),!1;if(e.which===65)r.position(0);else if(e.which===69)r.position(g.length);else{if(e.which===88||e.which===67||e.which===84)return!0;if(e.which===89)b!==""&&r.insert(b);else{if(e.which===86)return I(),!0;if(e.which===75)w===0?(b=g,r.set("")):w!==g.length&&(b=g.slice(w),r.set(g.slice(0,w)));else if(e.which===85)g!==""&&w!==0&&(b=g.slice(0,w),r.set(g.slice(w,g.length)),r.position(0));else if(e.which===17)return!1}}}}}}}else O(),F(),e.which===27&&(g=""),B(),R.call(this,e);return!1}}var r=this,i=r.data("cmd");if(i)return i;r.addClass("cmd"),r.append('<span class="prompt"></span><span></span><span class="cursor"> </span><span></span>');var s=e("<textarea/>").addClass("clipboard").appendTo(r);n.width&&r.width(n.width);var o,u,a=!1,l="",c=null,d,m=n.mask||!1,g="",y="",b="",w=0,E,S=n.enabled,x=n.historySize||60,T,N,C=r.find(".cursor"),k;v()?k=function(e){e?C.addClass("blink"):C.removeClass("blink")}:k=function(e){e&&!S?(C.addClass("inverted"),r.everyTime(500,"blink",L)):S&&(r.stopTime("blink",L),C.removeClass("inverted"))};var B=function(t){function i(t,i){var s=t.length;if(i===s)n.html(e.terminal.encode(t,!0)),C.html(" "),r.html("");else if(i===0)n.html(""),C.html(e.terminal.encode(t.slice(0,1),!0)),r.html(e.terminal.encode(t.slice(1),!0));else{var o=e.terminal.encode(t.slice(0,i),!0);n.html(o);var u=t.slice(i,i+1);C.html(u===" "?" ":e.terminal.encode(u,!0)),i===t.length-1?r.html(""):r.html(e.terminal.encode(t.slice(i+1),!0))}}function s(t){return"<div>"+e.terminal.encode(t,!0)+"</div>"}function a(t){var n=r;e.each(t,function(t,r){n=e(s(r)).insertAfter(n).addClass("clear")})}function l(t){e.each(t,function(e,t){n.before(s(t))})}var n=C.prev(),r=C.next(),c=0;return function(){var c=m?g.replace(/./g,"*"):g,h,p;t.find("div").remove(),n.html("");if(c.length>o-u-1||c.match(/\n/)){var d,v=c.match(/\t/g),y=v?v.length*3:0;v&&(c=c.replace(/\t/g,"\0\0\0\0"));if(c.match(/\n/)){var b=c.split("\n");p=o-u-1;for(h=0;h<b.length-1;++h)b[h]+=" ";b[0].length>p?(d=[b[0].substring(0,p)],d=d.concat(f(b[0].substring(p),o))):d=[b[0]];for(h=1;h<b.length;++h)b[h].length>o?d=d.concat(f(b[h],o)):d.push(b[h])}else d=H(c);v&&(d=e.map(d,function(e){return e.replace(/\x00\x00\x00\x00/g," ")})),p=d[0].length;if(p!==0||d.length!==1)if(w<p)i(d[0],w),a(d.slice(1));else if(w===p)n.before(s(d[0])),i(d[1],0),a(d.slice(2));else{var E=d.length,S=0;if(w<p)i(d[0],w),a(d.slice(1));else if(w===p)n.before(s(d[0])),i(d[1],0),a(d.slice(2));else{var x=d.slice(-1)[0],T=c.length-w,N=x.length,k=0;if(T<=N)l(d.slice(0,-1)),k=N===T?0:N-T,i(x,k+y);else if(E===3)n.before("<div>"+e.terminal.encode(d[0],!0)+"</div>"),i(d[1],w-p-1),r.after('<div class="clear">'+e.terminal.encode(d[2],!0)+"</div>");else{var L,A;k=w;for(h=0;h<d.length;++h){var O=d[h].length;if(!(k>O))break;k-=O}A=d[h],L=h,k===A.length&&(k=0,A=d[++L]),i(A,k),l(d.slice(0,L)),a(d.slice(L+1))}}}}else c===""?(n.html(""),C.html(" "),r.html("")):i(c,w)}}(r),j,F=function(){function n(n){u=p(n),t.html(e.terminal.format(e.terminal.encode(n)))}var t=r.find(".prompt");return function(){switch(typeof E){case"string":n(E);break;case"function":E(n)}}}(),q=!0,U=[];e.extend(r,{name:function(e){if(e!==t){T=e;var n=N&&N.enabled()||!N;return N=new h(e,x),n||N.disable(),r}return T},purge:function(){return N.clear(),r},history:function(){return N},set:function(e,i){return e!==t&&(g=e,i||(w=g.length),B(),typeof n.onCommandChange=="function"&&n.onCommandChange(g)),r},insert:function(e,t){return w===g.length?g+=e:w===0?g=e+g:g=g.slice(0,w)+e+g.slice(w),t||(w+=e.length),B(),typeof n.onCommandChange=="function"&&n.onCommandChange(g),r},get:function(){return g},commands:function(e){return e?(n.commands=e,r):e},destroy:function(){return e(document.documentElement||window).unbind(".cmd"),r.stopTime("blink",L),r.find(".cursor").next().remove().end().prev().remove().end().remove(),r.find(".prompt, .clipboard").remove(),r.removeClass("cmd").removeData("cmd"),r},prompt:function(e){if(e===t)return E;if(typeof e!="string"&&typeof e!="function")throw"prompt must be a function or string";return E=e,F(),B(),r},kill_text:function(){return b},position:function(e){return typeof e=="number"?(w=e<0?0:e>g.length?g.length:e,B(),r):w},visible:function(){var e=r.visible;return function(){e.apply(r,[]),B(),F()}}(),show:function(){var e=r.show;return function(){e.apply(r,[]),B(),F()}}(),resize:function(e){return e?o=e:_(),B(),r},enable:function(){return S=!0,k(!0),r},isenabled:function(){return S},disable:function(){return S=!1,k(!1),r},mask:function(e){return typeof e=="boolean"?(m=e,B(),r):m}}),r.name(n.name||n.prompt||""),E=n.prompt||"> ",F(),(n.enabled===t||n.enabled===!0)&&r.enable();var z;return e(document.documentElement||window).bind("keypress.cmd",function(i){var s;if(i.ctrlKey&&i.which===99)return!0;!a&&typeof n.keypress=="function"&&(s=n.keypress(i));if(s!==t&&!s)return s;if(S){if(e.inArray(i.which,[38,13,0,8])>-1&&i.keyCode!==123&&(i.which!==38||!i.shiftKey))return!1;if(!i.ctrlKey&&(!i.altKey||i.which!==100)||i.altKey)return a?(l+=String.fromCharCode(i.which),M(),A()):r.insert(String.fromCharCode(i.which)),!1}}).bind("keydown.cmd",R),r.data("cmd",r),r};var g=["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"],y=/(\[\[[gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?)/i,b=/\[\[([gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi,w=/\[\[([gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi,E=/^\[\[([gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]$/gi,S=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i,x=/\bhttps?:\/\/(?:(?!&[^;]+;)[^\s"'<>)])+\b/g,T=/((([^<>('")[\]\\.,;:\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,N=/('[^']*'|"(\\"|[^"])*"|\/(\\\/|[^\/])+\/[gimy]*|(\\ |[^ ])+|[\w-]+)/g,C=/(\[\[[gbiuso]*;[^;]*;[^\]]*\])/i,k=/\[\[[gbiuso]*;[^;]*;[^\]]*\]?$/i;e.terminal={valid_color:function(t){return t.match(S)||e.inArray(t.toLowerCase(),g)!==-1},escape_regex:function(e){var t=/([\^\$\[\]\(\)\+\*\.\|])/g;return e.replace(t,"\\$1")},have_formatting:function(e){return e.match(w)},is_formatting:function(e){return e.match(E)},format_split:function(e){return e.split(y)},split_equal:function(e,t){var n=!1,r=!1,i=0,s="",o=[],u=e.replace(w,function(e,t,n){var r=t.match(/;/g).length;return r==2?r=";;":r==3?r=";":r="","[["+t+r+n.replace(/\\\]/g,"]").replace(/\n/g,"\\n")+"]"+n+"]"}).split(/\n/g);for(var a=0,f=u.length;a<f;++a){if(u[a]===""){o.push("");continue}var l=u[a],c=0,h=0;for(var p=0,d=l.length;p<d;++p){if(l[p]==="["&&l[p+1]==="[")n=!0;else if(n&&l[p]==="]")r?(n=!1,r=!1):r=!0;else if(n&&r||!n){if(l[p]==="&"){var v=l.substring(p).match(/^(&[^;]+;)/);if(!v)throw"Unclosed html entity in line "+(a+1)+" at char "+(p+1);p+=v[1].length-2,p===d-1&&o.push(m+v[1]);continue}l[p]==="]"&&l[p-1]==="\\"?--h:++h}if(h===t||p===d-1){var m=l.substring(c,p+1);s&&(m=s+m,m.match("]")&&(s="")),c=p+1,h=0;var g=m.match(w);if(g){var y=g[g.length-1];if(y[y.length-1]!=="]")s=y.match(C)[1],m+="]";else if(m.match(k)){var b=m.length,E=b-y[y.length-1].length;m=m.replace(k,""),s=y.match(C)[1]}}o.push(m)}}}return o},encode:function(e,t){return t?e=e.replace(/&(?![^=]+=)/g,"&"):e=e.replace(/&(?!#[0-9]+;|[a-zA-Z]+;|[^= "]+=[^=])/g,"&"),e.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/\t/g," ")},format:function(t,n){var r=e.extend({},{linksNoReferrer:!1},n||{});if(typeof t=="string"){var i=e.terminal.format_split(t);return i&&i.length>1&&(t=e.map(i,function(t){return t===""?t:t.substring(0,1)==="["?t.replace(b,function(t,n,r,i,s,o,u){if(u==="")return"";u=u.replace(/\\]/g,"]");var a="";n.indexOf("b")!==-1&&(a+="font-weight:bold;");var f=[];n.indexOf("u")!==-1&&f.push("underline"),n.indexOf("s")!==-1&&f.push("line-through"),n.indexOf("o")!==-1&&f.push("overline"),f.length&&(a+="text-decoration:"+f.join(" ")+";"),n.indexOf("i")!==-1&&(a+="font-style:italic;"),e.terminal.valid_color(r)&&(a+="color:"+r+";",n.indexOf("g")!==-1&&(a+="text-shadow:0 0 5px "+r+";")),e.terminal.valid_color(i)&&(a+="background-color:"+i);var l;o===""?l=u:l=o.replace(/]/g,"]");var c='<span style="'+a+'"'+(s!==""?' class="'+s+'"':"")+' data-text="'+l.replace('"',""e;")+'">'+u+"</span>";return c}):"<span>"+t+"</span>"}).join("")),e.map(t.split(/(<\/?span[^>]*>)/g),function(e){return e.match(/span/)?e:e.replace(x,function(e){var t=e.match(/\.$/);return e=e.replace(/\.$/,""),'<a target="_blank" '+(r.linksNoReferer?' rel="noreferrer" ':"")+'href="'+e+'">'+e+"</a>"+(t?".":"")}).replace(T,'<a href="mailto:$1">$1</a>')}).join("").replace(/<span><br\/?><\/span>/g,"<br/>")}return""},escape_brackets:function(e){return e.replace(/\[/g,"[").replace(/\]/g,"]")},strip:function(e){return e.replace(b,"$6")},active:function(){return U.front()},overtyping:function(e){return e.replace(/((?:_\x08.|.\x08_)+)/g,function(e,t){return"[[u;;]"+e.replace(/_x08|\x08_|_\u0008|\u0008_/g,"")+"]"}).replace(/((?:.\x08.)+)/g,function(e,t){return"[[b;#fff;]"+e.replace(/(.)(?:\x08|\u0008)(.)/g,function(e,t,n){return n})+"]"})},ansi_colors:{normal:{black:"#000",red:"#A00",green:"#008400",yellow:"#A50",blue:"#00A",magenta:"#A0A",cyan:"#0AA",white:"#AAA"},faited:{black:"#000",red:"#640000",green:"#006100",yellow:"#737300",blue:"#000087",magenta:"#650065",cyan:"#008787",white:"#818181"},bold:{black:"#000",red:"#F55",green:"#44D544",yellow:"#FF5",blue:"#55F",magenta:"#F5F",cyan:"#5FF",white:"#FFF"},palette:["#000000","#AA0000","#00AA00","#AA5500","#0000AA","#AA00AA","#00AAAA","#AAAAAA","#555555","#FF5555","#55FF55","#FFFF55","#5555FF","#FF55FF","#55FFFF","#FFFFFF","#000000","#00005F","#000087","#0000AF","#0000D7","#0000FF","#005F00","#005F5F","#005F87","#005FAF","#005FD7","#005FFF","#008700","#00875F","#008787","#0087AF","#0087D7","#00AF00","#00AF5F","#00AF87","#00AFAF","#00AFD7","#00AFFF","#00D700","#00D75F","#00D787","#00D7AF","#00D7D7","#00D7FF","#00FF00","#00FF5F","#00FF87","#00FFAF","#00FFD7","#00FFFF","#5F0000","#5F005F","#5F0087","#5F00AF","#5F00D7","#5F00FF","#5F5F00","#5F5F5F","#5F5F87","#5F5FAF","#5F5FD7","#5F5FFF","#5F8700","#5F875F","#5F8787","#5F87AF","#5F87D7","#5F87FF","#5FAF00","#5FAF5F","#5FAF87","#5FAFAF","#5FAFD7","#5FAFFF","#5FD700","#5FD75F","#5FD787","#5FD7AF","#5FD7D7","#5FD7FF","#5FFF00","#5FFF5F","#5FFF87","#5FFFAF","#5FFFD7","#5FFFFF","#870000","#87005F","#870087","#8700AF","#8700D7","#8700FF","#875F00","#875F5F","#875F87","#875FAF","#875FD7","#875FFF","#878700","#87875F","#878787","#8787AF","#8787D7","#8787FF","#87AF00","#87AF5F","#87AF87","#87AFAF","#87AFD7","#87AFFF","#87D700","#87D75F","#87D787","#87D7AF","#87D7D7","#87D7FF","#87FF00","#87FF5F","#87FF87","#87FFAF","#87FFD7","#87FFFF","#AF0000","#AF005F","#AF0087","#AF00AF","#AF00D7","#AF00FF","#AF5F00","#AF5F5F","#AF5F87","#AF5FAF","#AF5FD7","#AF5FFF","#AF8700","#AF875F","#AF8787","#AF87AF","#AF87D7","#AF87FF","#AFAF00","#AFAF5F","#AFAF87","#AFAFAF","#AFAFD7","#AFAFFF","#AFD700","#AFD75F","#AFD787","#AFD7AF","#AFD7D7","#AFD7FF","#AFFF00","#AFFF5F","#AFFF87","#AFFFAF","#AFFFD7","#AFFFFF","#D70000","#D7005F","#D70087","#D700AF","#D700D7","#D700FF","#D75F00","#D75F5F","#D75F87","#D75FAF","#D75FD7","#D75FFF","#D78700","#D7875F","#D78787","#D787AF","#D787D7","#D787FF","#D7AF00","#D7AF5F","#D7AF87","#D7AFAF","#D7AFD7","#D7AFFF","#D7D700","#D7D75F","#D7D787","#D7D7AF","#D7D7D7","#D7D7FF","#D7FF00","#D7FF5F","#D7FF87","#D7FFAF","#D7FFD7","#D7FFFF","#FF0000","#FF005F","#FF0087","#FF00AF","#FF00D7","#FF00FF","#FF5F00","#FF5F5F","#FF5F87","#FF5FAF","#FF5FD7","#FF5FFF","#FF8700","#FF875F","#FF8787","#FF87AF","#FF87D7","#FF87FF","#FFAF00","#FFAF5F","#FFAF87","#FFAFAF","#FFAFD7","#FFAFFF","#FFD700","#FFD75F","#FFD787","#FFD7AF","#FFD7D7","#FFD7FF","#FFFF00","#FFFF5F","#FFFF87","#FFFFAF","#FFFFD7","#FFFFFF","#080808","#121212","#1C1C1C","#262626","#303030","#3A3A3A","#444444","#4E4E4E","#585858","#626262","#6C6C6C","#767676","#808080","#8A8A8A","#949494","#9E9E9E","#A8A8A8","#B2B2B2","#BCBCBC","#C6C6C6","#D0D0D0","#DADADA","#E4E4E4","#EEEEEE"]},from_ansi:function(){function r(r){var i=r.split(";"),s,o=!1,u=!1,a=!1,f=[],l="",c="",h=!1,p=!1,d=!1,v=e.terminal.ansi_colors.palette;for(var m in i){s=parseInt(i[m],10);switch(s){case 1:f.push("b"),a=!0,o=!1;break;case 4:f.push("u");break;case 3:f.push("i");break;case 5:d=!0;break;case 38:h=!0;break;case 48:p=!0;break;case 2:o=!0,a=!1;break;case 7:u=!0;break;default:h&&d&&v[s-1]?l=v[s-1]:t[s]&&(l=t[s]),p&&d&&v[s-1]?c=v[s-1]:n[s]&&(c=n[s])}s!==5&&(d=!1)}if(u)if(l&&c){var g=c;c=l,l=g}else l="black",c="white";var y,b;return a?y=b=e.terminal.ansi_colors.bold:o?y=b=e.terminal.ansi_colors.faited:y=b=e.terminal.ansi_colors.normal,[f.join(""),h?l:y[l],p?c:b[c]]}var t={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",39:"white"},n={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",49:"black"};return function(e){var t=e.split(/(\x1B\[[0-9;]*[A-Za-z])/g);if(t.length==1)return e;var n=[];t.length>3&&t.slice(0,3).join("")=="[0m"&&(t=t.slice(3));var i=!1,s,o,u,a,f;for(var l=0;l<t.length;++l){f=t[l].match(/^\x1B\[([0-9;]*)([A-Za-z])$/);if(f)switch(f[2]){case"m":if(f[1]==="")continue;f[1]!=="0"&&(a=r(f[1])),i?(n.push("]"),f[1]=="0"?(i=!1,o=u=""):(a[1]=a[1]||o,a[2]=a[2]||u,n.push("[["+a.join(";")+"]"),a[1]&&(o=a[1]),a[2]&&(u=a[2]))):f[1]!="0"&&(i=!0,n.push("[["+a.join(";")+"]"),a[1]&&(o=a[1]),a[2]&&(u=a[2]))}else n.push(t[l])}return i&&n.push("]"),n.join("")}}(),parseArguments:function(t){return e.map(t.match(N)||[],function(e){if(e[0]==="'"&&e[e.length-1]==="'")return e.replace(/^'|'$/g,"");if(e[0]==='"'&&e[e.length-1]==='"')return e=e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1"),e.replace(/\\\\|\\t|\\n/g,function(e){return e[1]==="t"?" ":e[1]==="n"?"\n":"\\"}).replace(/\\x([0-9a-f]+)/gi,function(e,t){return String.fromCharCode(parseInt(t,16))}).replace(/\\0([0-7]+)/g,function(e,t){return String.fromCharCode(parseInt(t,8))});if(e.match(/^\/(\\\/|[^\/])+\/[gimy]*$/)){var t=e.match(/^\/([^\/]+)\/([^\/]*)$/);return new RegExp(t[1],t[2])}return e.match(/^-?[0-9]+$/)?parseInt(e,10):e.match(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/)?parseFloat(e):e.replace(/\\ /g," ")})},splitArguments:function(t){return e.map(t.match(N)||[],function(e){return e[0]==="'"&&e[e.length-1]==="'"?e.replace(/^'|'$/g,""):e[0]==='"'&&e[e.length-1]==='"'?e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1"):e[0]==="/"&&e[e.length-1]=="/"?e:e.replace(/\\ /g," ")})},parseCommand:function(t){return m(t,e.terminal.parseArguments)},splitCommand:function(t){return m(t,e.terminal.splitArguments)},test:function(){function i(e,n){t.echo(n+" ["+(e?"[[b;#44D544;]PASS]":"[[b;#FF5555;]FAIL]")+"]")}var t=e.terminal.active();if(!t){t=e("body").terminal(e.noop).css("margin",0);var n=t.outerHeight()-t.height(),r=e(window);r.resize(function(){t.css("height",e(window).height()-20)}).resize()}t.echo("Testing...");var s='name "foo bar" baz /^asd [x]/ str\\ str 10 1e10',o=e.terminal.splitCommand(s);i(o.name==="name"&&o.args[0]==="foo bar"&&o.args[1]==="baz"&&o.args[2]==="/^asd [x]/"&&o.args[3]==="str str"&&o.args[4]==="10"&&o.args[5]==="1e10","$.terminal.splitCommand"),o=e.terminal.parseCommand(s),i(o.name==="name"&&o.args[0]==="foo bar"&&o.args[1]==="baz"&&e.type(o.args[2])==="regexp"&&o.args[2].source==="^asd [x]"&&o.args[3]==="str str"&&o.args[4]===10&&o.args[5]===1e10,"$.terminal.parseCommand"),s="[2;31;46mFoo[1;3;4;32;45mBar[0m[7mBaz",i(e.terminal.from_ansi(s)==="[[;#640000;#008787]Foo][[biu;#44D544;#F5F]Bar][[;#000;#AAA]Baz]","$.terminal.from_ansi"),s="[[biugs;#fff;#000]Foo][[i;;;foo]Bar][[ous;;]Baz]",t.echo("$.terminal.format"),i(e.terminal.format(s)==='<span style="font-weight:bold;text-decoration:underline line-through;font-style:italic;color:#fff;text-shadow:0 0 5px #fff;background-color:#000" data-text="Foo">Foo</span><span style="font-style:italic;" class="foo" data-text="Bar">Bar</span><span style="text-decoration:underline line-through overline;" data-text="Baz">Baz</span>'," formatting"),s="http://terminal.jcubic.pl/examples.php https://www.google.com/?q=jquery%20terminal",i(e.terminal.format(s)==='<a target="_blank" href="http://terminal.jcubic.pl/examples.php">http://terminal.jcubic.pl/examples.php</a> <a target="_blank" href="https://www.google.com/?q=jquery%20terminal">https://www.google.com/?q=jquery%20terminal</a>'," urls"),s="[email protected] [email protected]",i(e.terminal.format(s)==='<a href="mailto:[email protected]">[email protected]</a> <a href="mailto:[email protected]">[email protected]</a>'," emails"),s="-_-[[biugs;#fff;#000]Foo]-_-[[i;;;foo]Bar]-_-[[ous;;]Baz]-_-",i(e.terminal.strip(s)==="-_-Foo-_-Bar-_-Baz-_-","$.terminal.strip"),s="[[bui;#fff;]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sed dolor nisl, in suscipit justo. Donec a enim et est porttitor semper at vitae augue. Proin at nulla at dui mattis mattis. Nam a volutpat ante. Aliquam consequat dui eu sem convallis ullamcorper. Nulla suscipit, massa vitae suscipit ornare, tellus] est [[b;;#f00]consequat nunc, quis blandit elit odio eu arcu. Nam a urna nec nisl varius sodales. Mauris iaculis tincidunt orci id commodo. Aliquam] non magna quis [[i;;]tortor malesuada aliquam] eget ut lacus. Nam ut vestibulum est. Praesent volutpat tellus in eros dapibus elementum. Nam laoreet risus non nulla mollis ac luctus [[ub;#fff;]felis dapibus. Pellentesque mattis elementum augue non sollicitudin. Nullam lobortis fermentum elit ac mollis. Nam ac varius risus. Cras faucibus euismod nulla, ac auctor diam rutrum sit amet. Nulla vel odio erat], ac mattis enim." | |
,t.echo("$.terminal.split_equal");var u=[10,40,60,400];for(var a=u.length;a--;){var f=e.terminal.split_equal(s,u[a]),l=!0;for(var c=0;c<f.length;++c)if(e.terminal.strip(f[c]).length>u[a]){l=!1;break}i(l," split "+u[a])}}},e.fn.visible=function(){return this.css("visibility","visible")},e.fn.hidden=function(){return this.css("visibility","hidden")};var L={};e.jrpc=function(t,n,r,i,s){L[t]=L[t]||0;var o=e.json_stringify({jsonrpc:"2.0",method:n,params:r,id:++L[t]});return e.ajax({url:t,data:o,success:function(t,n,r){var o=r.getResponseHeader("Content-Type");if(!o.match(/application\/json/)){if(!console||!console.warn)throw new Error("WARN: Response Content-Type is not application/json");console.warn("Response Content-Type is not application/json")}var u;try{u=e.parseJSON(t)}catch(a){if(!s)throw new Error("Invalid JSON");s(r,"Invalid JSON",a);return}i(u,n,r)},error:s,contentType:"application/json",dataType:"text",async:!0,cache:!1,type:"POST"})};var H="0.8.7",B=!H.match(/^\{\{/),j="Copyright (c) 2011-2013 Jakub Jankiewicz <http://jcubic.pl>",F=B?" version "+H:" ",I=new RegExp(" {"+F.length+"}$"),q=[["jQuery Terminal","(c) 2011-2013 jcubic"],["jQuery Terminal Emulator"+(B?" v. "+H:""),j.replace(/ *<.*>/,"")],["jQuery Terminal Emulator"+(B?F:""),j.replace(/^Copyright /,"")],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/ /_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(I," ")+F,j],[" __ _____ ________ __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ \\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // / /__","\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\__\\_\\___/"," \\/ /____/ ".replace(I,"")+F,j]];e.terminal.defaults={prompt:"> ",history:!0,exit:!0,clear:!0,enabled:!0,historySize:60,checkArity:!0,exceptionHandler:null,cancelableAjax:!0,processArguments:!0,linksNoReferrer:!1,login:null,outputLimit:-1,onAjaxError:null,onRPCError:null,completion:!1,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' expect %s got %s!",commandNotFound:"Command '%s' Not Found!",oneRPCWithIgnore:"You can use only one rpc with ignoreSystemDescribe",oneInterpreterFunction:"You can't use more then one function (rpc with ignoreSystemDescribe is count as one)",loginFunctionMissing:"You don't have login function",noTokenError:"Access denied (no token)",serverResponse:"Server reponse is",wrongGreetings:"Wrong value of greetings parameter",notWhileLogin:"You can't call that function while in login",loginIsNotAFunction:"Authenticate must be a function",canExitError:"You can't exit from main interpeter",invalidCompletion:"Invalid completion",login:"login",password:"password"}};var R=[],U=new l;e.fn.terminal=function(n,r){function i(t){return typeof ut.processArguments=="function"?m(t,ut.processArguments):ut.processArguments?e.terminal.parseCommand(t):e.terminal.splitCommand(t)}function s(t){typeof t=="string"?z.echo(t):t instanceof Array?z.echo(e.map(t,function(t){return e.json_stringify(t)}).join(" ")):typeof t=="object"?z.echo(e.json_stringify(t)):z.echo(t)}function o(e){typeof ut.onRPCError=="function"?ut.onRPCError.call(z,e):z.error("[RPC] "+e.message)}function u(t){var n=function(n,r){z.pause(),e.jrpc(t,n,r,function(e){e.error?o(e.error):typeof ut.processRPCResponse=="function"?ut.processRPCResponse.call(z,e.result):s(e.result),z.resume()},f)};return function(e,t){if(e==="")return;e=i(e);if(!ut.login||e.name==="help")n(e.name,e.args);else{var r=t.token();r?n(e.name,[r].concat(e.args)):t.error("[AUTH] "+at.noTokenError)}}}function a(n,r,s){return function(o,u){if(o==="")return;var f=i(o),l=n[f.name],c=e.type(l);if(c==="function"){if(!r||l.length===f.args.length)return l.apply(z,f.args);z.error("[Arity] "+sprintf(at.wrongArity,f.name,l.length,f.args.length))}else if(c==="object"||c==="string"){var h=[];c==="object"&&(h=Object.keys(l),l=a(l,r)),u.push(l,{prompt:f.name+"> ",name:f.name,completion:c==="object"?function(e,t,n){n(h)}:t})}else e.type(s)==="function"?s(o,z):e.type(ut.onCommandNotFound)==="function"?ut.onCommandNotFound(o,z):u.error(sprintf(at.commandNotFound,f.name))}}function f(e,t,n){z.resume(),typeof ut.onAjaxError=="function"?ut.onAjaxError.call(z,e,t,n):t!=="abort"&&z.error("[AJAX] "+t+" - "+at.serverResponse+": \n"+e.responseText)}function l(t,n){e.jrpc(t,"system.describe",[],function(r){var i=[];if(r.procs){var u={};e.each(r.procs,function(n,r){u[r.name]=function(){var n=Array.prototype.slice.call(arguments);ut.checkArity&&r.params&&r.params.length!==n.length?z.error("[Arity] "+sprintf(at.wrongArity,r.name,r.params.length,n.length)):(z.pause(),e.jrpc(t,r.name,n,function(e){e.error?o(e.error):s(e.result),z.resume()},f))}}),n(u)}else n(null)},function(){n(null)})}function h(t,n){n=n||e.noop;var r=e.type(t),i={},s,o=0,f;if(r==="array"){var c={};(function h(t,n){if(t.length){var r=t[0],i=t.slice(1),s=e.type(r);s==="string"?(o++,z.pause(),ut.ignoreSystemDescribe?(o===1?f=u(r):z.error(at.oneRPCWithIgnore),h(i,n)):l(r,function(t){t&&e.extend(c,t),z.resume(),h(i,n)})):s==="function"?f?z.error(at.oneInterpreterFunction):f=r:s==="object"&&(e.extend(c,r),h(i,n))}else n()})(t,function(){s=Object.keys(c),i.interpreter=a(c,!1,f),i.completion=function(e,t,n){n(s)},n(i)})}else if(r==="string")ut.ignoreSystemDescribe?n({interpreter:u(t),completion:ut.completion}):(z.pause(),l(t,function(e){e?(i.interpreter=a(e,!1),i.completion=function(e,t,n){n(s)}):(i.interpreter=u(t),i.completion=ut.completion),z.resume(),n(i)}));else if(r==="object")s=Object.keys(t),i.interpreter=a(t,ut.checkArity),i.completion=function(e,t,n){n(s)},n(i);else{if(r==="undefined")t=e.noop;else if(r!=="function")throw r+" is invalid interpreter value";n({interpreter:t,completion:ut.completion})}}function p(t,n){var r=e.type(n)==="boolean"?"login":n;return function(n,i,s,o){z.pause(),e.jrpc(t,r,[n,i],function(e){z.resume(),!e.error&&e.result?s(e.result):s(null)},f)}}function d(e){return typeof e=="string"?e:typeof e.fileName=="string"?e.fileName+": "+e.message:e.message}function v(e,t){typeof ut.exceptionHandler=="function"?ut.exceptionHandler.call(z,e):z.exception(e,t)}function g(){var e=W.prop?W.prop("scrollHeight"):W.attr("scrollHeight");W.scrollTop(e)}function y(e,t){try{if(typeof t=="function")t(function(){});else if(typeof t!="string"){var n=e+" must be string or function";throw n}}catch(r){return v(r,e.toUpperCase()),!1}return!0}function E(t,n){try{var r=e.extend({raw:!1,finalize:e.noop},n||{});t=e.type(t)==="function"?t():t,t=e.type(t)==="string"?t:String(t);var i,s;r.raw||(t=e.terminal.encode(t)),t=e.terminal.overtyping(t),t=e.terminal.from_ansi(t),b.push(w);if(!r.raw&&(t.length>Y||t.match(/\n/))){var o=e.terminal.split_equal(t,Y);for(i=0,s=o.length;i<s;++i)o[i]===""||o[i]==="\r"?b.push(" "):r.raw?b.push(o[i]):b.push(e.terminal.format(o[i],{linksNoReferer:ut.linksNoReferer}))}else r.raw||(t=e.terminal.format(t,{linksNoReferer:ut.linksNoReferer})),b.push(t);b.push(r.finalize)}catch(u){b=[],alert("[Internal Exception(draw_line)]:"+d(u)+"\n"+u.stack)}}function S(){dt.resize(Y);var t=Q.empty().detach(),n;if(ut.outputLimit>=0){var r=ut.outputLimit===0?z.rows():ut.outputLimit;n=K.slice(K.length-r-1)}else n=K;e.each(n,function(e,t){E.apply(null,t)}),dt.before(t),z.flush()}function x(){if(ut.greetings===t)z.echo(z.signature);else if(ut.greetings){var e=typeof ut.greetings;e==="string"?z.echo(ut.greetings):e==="function"?ut.greetings.call(z,z.echo):z.error(at.wrongGreetings)}}function T(t){t=e.terminal.escape_brackets(e.terminal.encode(t,!0));var n=dt.prompt();dt.mask()&&(t=t.replace(/./g,"*")),typeof n=="function"?n(function(e){z.echo(e+t)}):z.echo(n+t)}function N(n,r,i){try{F()||(X=e.terminal.splitCommand(n).name,(i&&typeof ut.historyFilter=="function"&&ut.historyFilter(n)||!ut.historyFilter)&&dt.history().append(n));var s=pt.top();if(n==="exit"&&ut.exit){var o=pt.size();z.token();if(o==1&&z.token()||o>1)r||T(n),z.pop()}else{r||T(n);var u=K.length-1;if(n==="clear"&&ut.clear)z.clear();else{var a=s.interpreter(n,z);a!==t&&(u===K.length-1?(K.pop(),a!==!1&&z.echo(a)):a===!1?K=K.slice(0,u).concat(K.slice(u+1)):K=K.slice(0,u).concat([a]).concat(K.slice(u+1)),z.resize())}}}catch(f){throw v(f,"USER"),z.resume(),f}}function C(){if(typeof ut.onBeforeLogout=="function")try{if(ut.onBeforeLogout(z)===!1)return}catch(e){throw v(e,"onBeforeLogout"),e}k();if(typeof ut.onAfterLogout=="function")try{ut.onAfterLogout(z)}catch(e){throw v(e,"onAfterlogout"),e}z.login(ut.login,!0,B)}function k(){var t=z.prefix_name(!0)+"_";e.Storage.remove(t+"token"),e.Storage.remove(t+"login")}function L(t){var n=z.prefix_name()+"_interpreters",r=e.Storage.get(n);r?r=e.parseJSON(r):r=[],e.inArray(t,r)==-1&&(r.push(t),e.Storage.set(n,e.json_stringify(r)))}function O(e){var t=pt.top(),n=z.prefix_name(!0);F()||L(n),dt.name(n),typeof t.prompt=="function"?dt.prompt(function(e){t.prompt(e,z)}):dt.prompt(t.prompt),dt.set(""),!e&&typeof t.onStart=="function"&&t.onStart(z)}function B(){O(),x();var t=!1;if(typeof ut.onInit=="function"){rt=function(){t=!0};try{ut.onInit(z)}catch(n){throw v(n,"OnInit"),n}finally{rt=e.noop,t||z.resume()}}}function j(t,n,r){var i=dt.get().substring(0,dt.position());if(i!==t)return;var s=new RegExp("^"+e.terminal.escape_regex(n)),o=[];for(var u=r.length;u--;)s.test(r[u])&&o.push(r[u]);if(o.length===1)z.insert(o[0].replace(s,"")+" ");else if(o.length>1)if(J>=2)T(t),z.echo(o.join(" ")),J=0;else{var a=!1,f,l;e:for(l=n.length;l<o[0].length;++l){for(u=1;u<o.length;++u)if(o[0].charAt(l)!==o[u].charAt(l))break e;a=!0}a&&z.insert(o[0].slice(0,l).replace(s,""))}}function F(){return nt||dt.mask()}function I(n){var r,i,s=pt.top();if(e.type(s.keydown)==="function"){r=s.keydown(n,z);if(r!==t)return r}var o;ut.completion&&e.type(ut.completion)!="boolean"&&!s.completion?o=ut.completion:o=s.completion,z.oneTime(10,function(){ct()});if(e.type(ut.keydown)==="function"){r=ut.keydown(n,z);if(r!==t)return r}if(!z.paused()){n.which!==9&&(J=0);if(n.which===68&&n.ctrlKey)return nt||(dt.get()===""?pt.size()>1||ut.login!==t?z.pop(""):(z.resume(),z.echo("")):z.set_command("")),!1;if(n.which===76&&n.ctrlKey)z.clear();else{if(o&&n.which===9){++J;var u=dt.get().substring(0,dt.position()),a=u.split(" "),f;if(a.length==1)f=a[0];else{f=a[a.length-1];for(i=a.length-1;i>0;i--){if(a[i-1][a[i-1].length-1]!="\\")break;f=a[i-1]+" "+f}}switch(e.type(o)){case"function":o(z,f,function(e){j(u,f,e)});break;case"array":j(u,f,o);break;default:throw new Error(e.terminal.defaults.strings.invalidCompletion)}return!1}if(n.which===86&&n.ctrlKey){z.oneTime(1,function(){g()});return}if(n.which===9&&n.ctrlKey){if(U.length()>1)return z.focus(!1),!1}else n.which===34?z.scroll(z.height()):n.which===33?z.scroll(-z.height()):z.attr({scrollTop:z.attr("scrollHeight")})}}else if(n.which===68&&n.ctrlKey){if(R.length){for(i=R.length;i--;){var l=R[i];if(4!==l.readyState)try{l.abort()}catch(c){z.error(a.ajaxAbortError)}}R=[],z.resume()}return!1}}var b=[],w=1,z=this;if(this.length>1)return this.each(function(){e.fn.terminal.call(e(this),n,e.extend({name:z.selector},r))});if(z.data("terminal"))return z.data("terminal");if(z.length===0)throw'Sorry, but terminal said that "'+z.selector+'" is not valid selector!';var W,X,V=!1,J=0,K=[],Q,G=U.length(),Y,Z,et=[],tt,nt=!1,rt=e.noop,it,st,ot=[],ut=e.extend({},e.terminal.defaults,{name:z.selector},r||{}),at=e.terminal.defaults.strings,ft=ut.enabled,lt=!1;e.extend(z,e.omap({clear:function(){Q.html(""),dt.set(""),K=[];try{ut.onClear(z)}catch(e){throw v(e,"onClear"),e}return z.attr({scrollTop:0}),z},export_view:function(){if(nt)throw new Exception(at.notWhileLogin);return{prompt:z.get_prompt(),command:z.get_command(),position:dt.position(),lines:K.slice(0)}},import_view:function(e){if(nt)throw new Exception(at.notWhileLogin);return z.set_prompt(e.prompt),z.set_command(e.command),dt.position(e.position),K=e.lines,S(),z},exec:function(e,t){return lt?ot.push([e,t]):N(e,t,!0),z},login:function(t,n,r,i){if(nt)throw new Error(at.notWhileLogin);if(typeof t!="function")throw new Error(at.loginIsNotAFunction);if(z.token(!0)&&z.login_name(!0))return typeof r=="function"&&r(),z;var s=null;return ut.history&&dt.history().disable(),nt=!0,z.push(function(s){z.set_mask(!0).push(function(o){try{t.call(z,s,o,function(t,o){if(t){z.pop().pop(),ut.history&&dt.history().enable();var u=z.prefix_name(!0)+"_";e.Storage.set(u+"token",t),e.Storage.set(u+"login",s),nt=!1,typeof r=="function"&&r()}else n?(o||z.error(at.wrongPasswordTryAgain),z.pop().set_mask(!1)):(nt=!1,o||z.error(at.wrongPassword),z.pop().pop()),typeof i=="function"&&i()})}catch(u){v(u,"USER(authentication)")}},{prompt:at.password+": "})},{prompt:at.login+": "})},settings:ut,commands:function(){return pt.top().interpreter},setInterpreter:function(t,n){function r(){z.pause(),h(t,function(t){z.resume();var n=pt.top();e.extend(n,t),O(!0)})}e.type(t)=="string"&&n?z.login(p(t,n),!0,r):r()},greetings:function(){return x(),z},paused:function(){return lt},pause:function(){return rt(),!lt&&dt&&(lt=!0,z.disable(),dt.hidden()),z},resume:function(){if(lt&&dt){lt=!1,z.enable(),dt.visible();var e=ot;ot=[];while(e.length)z.exec.apply(z,e.shift());g()}return z},cols:function(){return Y},rows:function(){return Z},history:function(){return dt.history()},next:function(){if(U.length()===1)return z;var t=z.offset().top,n=z.height(),r=z.scrollTop();if(!A(z))return z.enable(),e("html,body").animate({scrollTop:t-50},500),z;U.front().disable();var i=U.rotate().enable(),s=i.offset().top-50;e("html,body").animate({scrollTop:s},500);try{ut.onTerminalChange(i)}catch(o){throw v(o,"onTerminalChange"),o}return i},focus:function(e,t){return z.oneTime(1,function(){if(U.length()===1)if(e===!1)try{!t&&ut.onBlur(z)!==!1&&z.disable()}catch(n){throw v(n,"onBlur"),n}else try{!t&&ut.onFocus(z)!==!1&&z.enable()}catch(n){throw v(n,"onFocus"),n}else if(e===!1)z.next();else{var r=U.front();if(r!=z){r.disable();if(!t)try{ut.onTerminalChange(z)}catch(n){throw v(n,"onTerminalChange"),n}}U.set(z),z.enable()}}),z},enable:function(){return Y===t&&z.resize(),dt&&(dt.enable(),ft=!0),z},disable:function(){return dt&&(ft=!1,dt.disable()),z},enabled:function(){return ft},signature:function(){var e=z.cols(),t=e<15?null:e<35?0:e<55?1:e<64?2:e<75?3:4;return t!==null?q[t].join("\n")+"\n":""},version:function(){return H},cmd:function(){return dt},get_command:function(){return dt.get()},set_command:function(e){return dt.set(e),z},insert:function(e){if(typeof e=="string")return dt.insert(e),z;throw"insert function argument is not a string"},set_prompt:function(e){return y("prompt",e)&&(typeof e=="function"?dt.prompt(function(t){e(t,z)}):dt.prompt(e),pt.top().prompt=e),z},get_prompt:function(){return pt.top().prompt},set_mask:function(e){return dt.mask(e),z},get_output:function(t){return t?K:e.map(K,function(e){return typeof e[0]=="function"?e[0]():e[0]}).join("\n")},resize:function(e,t){e&&t&&(z.width(e),z.height(t)),e=z.width(),t=z.height();var n=M(z),r=_(z);if(n!==Y||r!==Z){Y=n,Z=r,S(),typeof ut.onResize=="function"&&(st!==t||it!==e)&&ut.onResize(z);if(st!==t||it!==e)st=t,it=e}return z},flush:function(){try{var t;e.each(b,function(n,r){if(r===w)t=e("<div></div>");else if(typeof r=="function"){t.appendTo(Q);try{r(t)}catch(i){v(i,"USER:echo(finalize)")}}else e("<div/>").html(r).appendTo(t).width("100%")});if(ut.outputLimit>=0){var n=ut.outputLimit===0?z.rows():ut.outputLimit,r=Q.find("div div");if(r.length>n){var i=r.slice(0,K.length-n+1),s=i.parent();i.remove(),s.each(function(){var t=e(this);t.is(":empty")&&t.remove()})}}g(),b=[]}catch(o){alert("[Flush] "+d(o)+"\n"+o.stack)}return z},echo:function(t,n){try{t=t||"";var r=e.extend({flush:!0,raw:!1,finalize:e.noop},n||{});b=[],E(t,r),K.push([t,r]),r.flush&&z.flush(),ct()}catch(i){alert("[Terminal.echo] "+d(i)+"\n"+i.stack)}return z},error:function(t,n){return z.echo("[[;#f00;]"+e.terminal.escape_brackets(t).replace(/\\$/,"\")+"]",n)},exception:function(t,n){var r=d(t);n&&(r="["+n+"]: "+r),r&&z.error(r,{finalize:function(e){e.addClass("exception message")}}),typeof t.fileName=="string"&&(z.pause(),e.get(t.fileName,function(e){z.resume();var n=t.lineNumber-1,r=e.split("\n")[n];r&&z.error("["+t.lineNumber+"]: "+r)})),t.stack&&z.error(t.stack,{finalize:function(e){e.addClass("exception stack-trace")}})},scroll:function(e){var t;return e=Math.round(e),W.prop?(e>W.prop("scrollTop")&&e>0&&W.prop("scrollTop",0),t=W.prop("scrollTop"),W.scrollTop(t+e)):(e>W.attr("scrollTop")&&e>0&&W.attr("scrollTop",0),t=W.attr("scrollTop"),W.scrollTop(t+e)),z},logout:ut.login?function(){while(pt.size()>1)z.pop();return z.pop()}:function(){z.error(at.loginFunctionMissing)},token:ut.login?function(t){return e.Storage.get(z.prefix_name(t)+"_token")}:e.noop,login_name:ut.login?function(t){return e.Storage.get(z.prefix_name(t)+"_login")}:e.noop,name:function(){return pt.top().name},prefix_name:function(e){var t=(ut.name?ut.name+"_":"")+G;return e&&pt.size()>1&&(t+="_"+pt.map(function(e){return e.name}).slice(1).join("_")),t},push:function(t,n){n=n||{},n.name=n.name||X,n.prompt=n.prompt||n.name+" ";var r=pt.top();return r&&(r.mask=dt.mask()),h(t,function(r){pt.push(e.extend({},r,n));if(n.login){var i=e.type(n.login);i=="function"?z.login(n.login,!1,O,z.pop):(e.type(t)=="string"&&i=="string"||i=="boolean")&&z.login(p(t,n.login),!1,O,z.pop)}else O()}),z},pop:function(n){n!==t&&T(n);var r=z.token(!0);if(pt.size()==1)if(ut.login){C();if(e.type(ut.onExit)==="function")try{ut.onExit(z)}catch(i){throw v(i,"onExit"),i}}else z.error(at.canExitError);else{r&&k();var s=pt.pop();O();if(e.type(s.onExit)==="function")try{s.onExit(z)}catch(i){throw v(i,"onExit"),i}z.set_mask(pt.top().mask)}return z},level:function(){return pt.size()},reset:function(){z.clear();while(pt.size()>1)pt.pop();return B(),z},purge:function(){var t=z.prefix_name()+"_",n=e.Storage.get(t+"interpreters");return e.each(e.parseJSON(n),function(t,n){e.Storage.remove(n+"_commands"),e.Storage.remove(n+"_token"),e.Storage.remove(n+"_login")}),dt.purge(),e.Storage.remove(t+"interpreters"),z},destroy:function(){return dt.destroy().remove(),Q.remove(),e(document).unbind(".terminal"),e(window).unbind(".terminal"),z.unbind("click, mousewheel"),z.removeData("terminal").removeClass("terminal"),ut.width&&z.css("width",""),ut.height&&z.css("height",""),z}},function(e,t){return function(){try{return t.apply(this,Array.prototype.slice.apply(arguments))}catch(n){throw e!=="exec"&&e!=="resume"&&v(n,"TERMINAL"),n}}}));var ct=function(){var e=P(z);return function(){e!==P(z)&&(z.resize(),e=P(z))}}();ut.width&&z.width(ut.width),ut.height&&z.height(ut.height),!navigator.userAgent.toLowerCase().match(/(webkit)[ \/]([\w.]+)/)&&z[0].tagName.toLowerCase()=="body"?W=e("html"):W=z,e(document).bind("ajaxSend.terminal",function(e,t,n){R.push(t)}),Q=e("<div>").addClass("terminal-output").appendTo(z),z.addClass("terminal");if("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)z.click(function(){z.find("textarea").focus()}),z.find("textarea").focus();if(ut.login&&typeof ut.onBeforeLogin=="function")try{ut.onBeforeLogin(z)}catch(ht){throw v(ht,"onBeforeLogin"),ht}typeof n=="string"&&(typeof ut.login=="string"||ut.login)&&(ut.login=p(n,ut.login)),U.append(z);var pt,dt;return h(n,function(n){pt=new c(e.extend({name:ut.name,prompt:ut.prompt,greetings:ut.greetings},n)),dt=e("<div/>").appendTo(z).cmd({prompt:ut.prompt,history:ut.history,historyFilter:ut.historyFilter,historySize:ut.historySize,width:"100%",keydown:I,keypress:ut.keypress?function(e){return ut.keypress(e,z)}:null,onCommandChange:function(t){if(e.type(ut.onCommandChange)==="function")try{ut.onCommandChange(t,z)}catch(n){throw v(n,"onCommandChange"),n}g()},commands:N}),ft?z.focus(t,!0):z.disable(),e(document).bind("click.terminal",function(t){!e(t.target).closest(".terminal").hasClass("terminal")&&ut.onBlur(z)!==!1&&z.disable()}),z.click(function(e){z.enabled()||z.focus()}).mousedown(function(e){e.which==2&&z.insert(D())}),ut.login?z.login(ut.login,!0,B):B(),z.is(":visible")&&(Y=M(z),dt.resize(Y),Z=_(z)),z.oneTime(100,function(){e(window).bind("resize.terminal",function(){if(z.is(":visible")){var e=z.width(),t=z.height();(st!==t||it!==e)&&z.resize()}})});if(e.event.special.mousewheel){var r=!1;e(document).bind("keydown.terminal",function(e){e.shiftKey&&(r=!0)}).bind("keyup.terminal",function(e){if(e.shiftKey||e.which==16)r=!1}),z.mousewheel(function(e,t){r||(t>0?z.scroll(-40):z.scroll(40))})}}),z.data("terminal",z),z}}(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This css file is part of jquery terminal | |
* | |
* Licensed under GNU LGPL Version 3 license | |
* Copyright (c) 2011-2013 Jakub Jankiewicz <http://jcubic.pl> | |
* | |
*/ | |
.terminal .terminal-output .format, .cmd .format, | |
.cmd .prompt, .cmd .prompt div, .terminal .terminal-output div div{ | |
display: inline-block; | |
} | |
.cmd .clipboard { | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
opacity: 0.01; | |
filter: alpha(opacity = 0.01); | |
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.01); | |
width: 2px; | |
} | |
.cmd > .clipboard { | |
position: fixed; | |
} | |
.terminal { | |
padding: 10px; | |
position: relative; | |
overflow: hidden; | |
} | |
.cmd { | |
padding: 0; | |
margin: 0; | |
height: 1.3em; | |
/*margin-top: 3px; */ | |
} | |
.cmd .cursor.blink { | |
-webkit-animation: blink 1s infinite steps(1, start); | |
-moz-animation: blink 1s infinite steps(1, start); | |
-ms-animation: blink 1s infinite steps(1, start); | |
animation: blink 1s infinite steps(1, start); | |
} | |
@keyframes blink { | |
0%, 100% { | |
background-color: #000; | |
color: #aaa; | |
} | |
50% { | |
background-color: #bbb; /* not #aaa because it's seem there is Google Chrome bug */ | |
color: #000; | |
} | |
} | |
@-webkit-keyframes blink { | |
0%, 100% { | |
background-color: #000; | |
color: #aaa; | |
} | |
50% { | |
background-color: #bbb; | |
color: #000; | |
} | |
} | |
@-ms-keyframes blink { | |
0%, 100% { | |
background-color: #000; | |
color: #aaa; | |
} | |
50% { | |
background-color: #bbb; | |
color: #000; | |
} | |
} | |
@-moz-keyframes blink { | |
0%, 100% { | |
background-color: #000; | |
color: #aaa; | |
} | |
50% { | |
background-color: #bbb; | |
color: #000; | |
} | |
} | |
.terminal .terminal-output div div, .cmd .prompt { | |
display: block; | |
line-height: 14px; | |
height: auto; | |
} | |
.cmd .prompt { | |
float: left; | |
} | |
.terminal, .cmd { | |
font-family: FreeMono, monospace; | |
color: #aaa; | |
background-color: #000; | |
font-size: 12px; | |
line-height: 14px; | |
} | |
.terminal-output > div { | |
/*padding-top: 3px;*/ | |
min-height: 14px; | |
} | |
.terminal .terminal-output div span { | |
display: inline-block; | |
} | |
.cmd span { | |
float: left; | |
/*display: inline-block; */ | |
} | |
.terminal .inverted, .cmd .inverted, .cmd .cursor.blink { | |
background-color: #aaa; | |
color: #000; | |
} | |
.terminal .terminal-output div div::-moz-selection, | |
.terminal .terminal-output div span::-moz-selection, | |
.terminal .terminal-output div div a::-moz-selection { | |
background-color: #aaa; | |
color: #000; | |
} | |
.terminal .terminal-output div div::selection, | |
.terminal .terminal-output div div a::selection, | |
.terminal .terminal-output div span::selection, | |
.cmd > span::selection, | |
.cmd .prompt span::selection { | |
background-color: #aaa; | |
color: #000; | |
} | |
.terminal .terminal-output div.error, .terminal .terminal-output div.error div { | |
color: red; | |
} | |
.tilda { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
z-index: 1100; | |
} | |
.clear { | |
clear: both; | |
} | |
.terminal a { | |
color: #0F60FF; | |
} | |
.terminal a:hover { | |
color: red; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! | |
%html | |
%head | |
/ Head contents goes here | |
- if logged_in? && user.developer? | |
%link(href="/stylesheets/jquery.terminal.css" rel="stylesheet")/ | |
%script(src="/javascripts/jquery.mousewheel-min.js" type="text/javascript") | |
%script(src="/javascripts/jquery.terminal-min.js" type="text/javascript") | |
%script(src="/javascripts/console.js" type="text/javascript") | |
#debug-console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post '/console/methods' do | |
halt 404 unless user.developer? | |
content_type 'text/javascript' | |
begin | |
if /\b(?<object_name>[A-Z]\S+)\.(?<more>\S+)?/ =~ params[:q] | |
matching = eval("#{object_name}.public_methods") rescue [] | |
matching = matching.grep /^#{more ? Regexp.escape(more) : '[^_]'}/ | |
matching.map {|method_name| "#{object_name}.#{method_name}" }.sort.to_json | |
else | |
Object.constants.grep(/^#{Regexp.escape(params[:q])}/).sort.to_json | |
end | |
rescue | |
'[]' | |
end | |
end | |
post '/console/exec' do | |
halt 404 unless user.developer? | |
content_type 'text/javascript' | |
real_stdout = $stdout | |
begin | |
$stdout = StringIO.new | |
return_value = eval(params[:q]) | |
{ out: $stdout.string.chomp, ret: return_value }.to_json | |
rescue Exception => ex | |
{ error: ex.to_s, backtrace: ex.backtrace.join("\n") }.to_json | |
ensure | |
$stdout = real_stdout | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment