Skip to content

Instantly share code, notes, and snippets.

@csabahenk
Last active April 2, 2018 22:02
Show Gist options
  • Save csabahenk/04900385377cf8a8ac1321a3c8136e60 to your computer and use it in GitHub Desktop.
Save csabahenk/04900385377cf8a8ac1321a3c8136e60 to your computer and use it in GitHub Desktop.
Tibetanalpha
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Tibetanalpha</title>
<link rel="shortcut icon" href="favicon.ico"/>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> -->
<!-- <script src="js/jquery.mousewheel-min.js"></script> -->
<script src="jquery.terminal-1.14.0.min.js"></script>
<!-- <script src="js/debug.js"></script> -->
<link href="jquery.terminal-1.14.0.min.css" rel="stylesheet"/>
<script src="keyPolyfill.js"></script>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>-->
<!--<script src="jgestures.min.js"></script>-->
<!--<script src="touch-scroll.min.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<style>
/* FULL SCREEN FIXES */
/*
.terminal {
font-family: 'Droid Sans Mono';
}
*/
.terminal a.ui-slider-handle:focus { outline: none; }
body { margin: 0; padding: 0; }
/* html { background-color: #000; }*/
.clear { clear: both; }
html, body { height: 100%; }
/* This works only in Safari and Google Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {
.terminal, .terminal .terminal-output, .terminal .terminal-output div,
.terminal .terminal-output div div, .cmd, .terminal .cmd span, .terminal .cmd div {
font-weight: bold;
}
}
textarea { position: absolute; clip: rect(0,0,0,0); }
</style>
<style>
/* overrides for larger font size */
.terminal, .cmd {
font-size: 22px;
line-height: 24px;
}
.terminal, .cmd, .terminal .terminal-output > div > div, .cmd .prompt {
font-size: calc(var(--size, 1) * 12px);
line-height: calc(var(--size, 1) * 14px);
font-size: calc(var(--size, 1) * 22px);
line-height: calc(var(--size, 1) * 24px);
}
.terminal .terminal-output > div > div {
min-height: calc(var(--size, 1) * 14px);
min-height: calc(var(--size, 1) * 24px);
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="tibetanalpha"></div>
</body>
<script>
var helpMsg = ["A Tibetan alphabet learning tool.",
"You are shown a Tibetan letter.",
"Enter the Wylie transliteration of it.",
"Trailing 'a' and case does not matter.",
"So for '\u0f42', 'ga', 'Ga', 'g' are all accepted.",
"Special actions:",
"- '?' gives up on the current letter.",
"- 'show' shows the alphabet."].join("\n");
//var tibetanAlpha = [["ཀ","ཁ","ག","ང"],["ཅ","ཆ","ཇ","ཉ"],["ཏ","ཐ","ད","ན"],["པ","ཕ","བ","མ"],["ཙ","ཚ","ཛ","ཝ"],["ཞ","ཟ","འ","ཡ"],["ར","ལ","ཤ","ས"],["ཧ","ཨ"]];
var tibetanAlpha = ['\u0f40', '\u0f41', '\u0f42', '\u0f44', '\u0f45', '\u0f46', '\u0f47', '\u0f49', '\u0f4f', '\u0f50', '\u0f51', '\u0f53', '\u0f54', '\u0f55', '\u0f56', '\u0f58', '\u0f59', '\u0f5a', '\u0f5b', '\u0f5d', '\u0f5e', '\u0f5f', '\u0f60', '\u0f61', '\u0f62', '\u0f63', '\u0f64', '\u0f66', '\u0f67', '\u0f68'];
var tibetanWylie = ["k","kh","g","ng","c","ch","j","ny","t","th","d","n","p","ph","b","m","ts","tsh","dz","w","zh","z","'","y","r","l","sh","s","h",""];
var checkMark = "[[;green;]\u2713]";
var crossMark = "[[;red;]\u2716]";
var visited = [];
var passes = [];
var misses = [];
var tibetanMap = {};
tibetanAlpha.forEach(function(t,i) {
visited.push(false);
passes.push(false);
misses.push(false);
tibetanMap[t] = tibetanWylie[i];
});
var remaining = tibetanAlpha.length;
var current;
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function tibetanPrompt() {
return (remaining+1) + ". " + tibetanAlpha[current] + ' ? ';
}
function nextLetter(term) {
if (remaining == 0) {
remaining--;
return;
}
nextLetter_in();
term.set_prompt(tibetanPrompt());
}
function nextLetter_in() {
var i = getRandomInt(remaining);
var k,l;
for (k=0, l=0;; k++) {
if (!visited[k]) {
if (l == i) {
visited[k] = true;
break;
}
l++;
}
}
current = k;
remaining--;
}
nextLetter_in();
// jQuery(function($) {
keyboardeventKeyPolyfill.polyfill();
term = $('#tibetanalpha').terminal(function(command, term) {
//count += 1;
//this.echo(count);
if (remaining == -1) {
term.set_prompt("");
location.reload();
return;
}
command = command.trim().toLowerCase();
switch (command) {
case "help":
this.echo(helpMsg);
break;
case "show":
//var term = this;
for (var i=0;;i++) {
var a = tibetanAlpha.slice(i*4,(i+1)*4);
if (a.length == 0)
break;
term.echo(a.map(function(t) { return t + ": " + tibetanMap[t] + "a"}).join(", "));
};
break;
case "":
term.echo("Type 'help' for help.");
break;
case "?":
term.echo(tibetanWylie[current] + "a");
misses[current] = false;
passes[current] = true;
nextLetter(term);
break;
default:
// Discard trailing 'a'
if (command.slice(-1) == "a")
command = command.slice(0,-1);
for (var found=false, i=0;i<tibetanAlpha.length;i++){
found = (tibetanWylie[i] == command);
if (found)
break;
}
if (!found) {
term.echo("No such letter, was it a typo?");
break;
}
if (i == current) {
term.echo(checkMark);
nextLetter(term);
break;
}
term.echo(crossMark);
misses[current] = true;
term.set_prompt('? ');
}
if (remaining == -1) {
var misscnt = misses.filter(function(x) { return x;}).length;
var passcnt = passes.filter(function(x) { return x;}).length;
if (misscnt + passcnt == 0) {
term.echo("Congrats, faultless execution!");
} else {
term.echo("Hits: " + (tibetanAlpha.length - misscnt - passcnt) + "/" + tibetanAlpha.length);
[["Misses",misses,misscnt],
["Passes",passes,passcnt]].forEach(function(p) {
var label = p[0];
var arr = p[1];
var cnt = p[2];
if (cnt == 0)
return;
term.echo(label + ": " + arr.map(
function(b,i) { return b && i; }
).filter(
function(i) { return !(i === false); }
).map(function(i) {
return tibetanAlpha[i] + ": " + tibetanWylie[i] + "a";
}).join(", "));
});
}
term.set_prompt("Hit enter to start again.");
}
}, {
greetings: ['\u0f56\u0f40\u0fb2\u0f0b\u0f64\u0f72\u0f66\u0f0b\u0f56\u0f51\u0f7a\u0f0b\u0f63\u0f7a\u0f42\u0f66', "Type 'help' for help!", ""].join("\n"),
prompt: tibetanPrompt(),
name: 'tibetanalpha',
/*
keydown: function(e, term) {
term.echo('keydown: ' + e.which);
},
keypress: function(e, term) {
term.echo('keypress: ' + e.which);
},
*/
onInit: function(term) {
/*
$('textarea').focus(function() {
$(window).scrollTop(10);
var keyboard_shown = $(window).scrollTop() > 0;
$(window).scrollTop(0);
term.echo(keyboard_shown?'keyboard ':'nokeyboard');
}).focus();*/
//term.touchScroll();
}
}).css({
overflow: 'auto'
});
$(window).resize(function() {
term.css('height', $(window).height());
term.resize();
}).resize();
// https://github.com/tkahn/SmoothTouchScroll
//});
</script>
</html>
/*!
* __ _____ ________ __
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
* \/ /____/ version 1.14.0
* http://terminal.jcubic.pl
*
* This file is part of jQuery Terminal.
*
* Copyright (c) 2011-2018 Jakub Jankiewicz <http://jcubic.pl>
* Released under the MIT license
*
* Date: Sat, 24 Mar 2018 16:04:13 +0000
*/.cmd .format,.cmd .prompt,.cmd .prompt div,.terminal .terminal-output .format,.terminal .terminal-output div div{display:inline-block}.cmd,.terminal h1,.terminal h2,.terminal h3,.terminal h4,.terminal h5,.terminal h6,.terminal pre{margin:0}.terminal h1,.terminal h2,.terminal h3,.terminal h4,.terminal h5,.terminal h6{line-height:1.2em}.cmd .clipboard{position:absolute;left:-16px;top:0;width:20px;height:16px;background:transparent;border:none;color:transparent;outline:none;padding:0;resize:none;z-index:1000;overflow:hidden;white-space:pre;text-indent:-9999em}.terminal audio,.terminal canvas,.terminal img,.terminal object,.terminal value{cursor:default}.terminal .error{color:red}.terminal{position:relative;overflow-y:auto}.cmd,.terminal{contain:content}body.terminal{height:100%;min-height:100vh;margin:0}.terminal>div{overflow:hidden}.terminal>.font .resizer,.terminal>.resizer{position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;z-index:-1;visibility:hidden;height:100%;border:none;padding:0;width:100%}.cmd{padding:0;position:relative;float:left;padding-bottom:3px}.terminal a[tabindex="1000"],.terminal a[tabindex="1000"]:active,.terminal a[tabindex="1000"]:focus{outline:none}.cmd .inverted,.terminal .inverted{background-color:#aaa;color:#000}.cmd .cursor{border-bottom:3px solid transparent;margin-bottom:-3px;background-clip:content-box}.cmd .cursor.blink{-webkit-animation:terminal-blink 1s infinite step-start;animation:terminal-blink 1s infinite step-start;border-left:1px solid transparent;margin-left:-1px}.bar.cmd .inverted,.bar.terminal .inverted{border-left-color:#aaa}.cmd .prompt,.terminal .terminal-output div div{display:block;line-height:14px;height:auto}.terminal .terminal-output>div:not(.raw) div{white-space:nowrap}.cmd .prompt>span{float:left}.cmd,.terminal{font-family:monospace;color:#aaa;background-color:#000;font-size:12px;line-height:14px;box-sizing:border-box;cursor:text}.cmd div{clear:both}.cmd .prompt+div{clear:right}.terminal-output>div>div{min-height:14px}terminal .terminal-output>div{margin-top:-1px}.terminal-output>div.raw>div *{overflow-wrap:break-word;word-wrap:break-word}.terminal .font{position:absolute;font-size:inherit;width:1em;height:1em;top:-100%;left:0;margin-bottom:1px}.terminal .terminal-output div span{display:inline-block}.cmd>span:not(.prompt){float:left}.cmd .prompt span.line{display:block;float:none}.terminal table{border-collapse:collapse}.terminal td{border:1px solid #aaa}.cmd .prompt span::-moz-selection,.cmd>div::-moz-selection,.cmd>div span::-moz-selection,.cmd>span::-moz-selection,.cmd>span span::-moz-selection,.cmd div::-moz-selection,.terminal .terminal-output .raw div::-moz-selection,.terminal .terminal-output div div::-moz-selection,.terminal .terminal-output div div a::-moz-selection,.terminal .terminal-output div span::-moz-selection,.terminal h1::-moz-selection,.terminal h2::-moz-selection,.terminal h3::-moz-selection,.terminal h4::-moz-selection,.terminal h5::-moz-selection,.terminal h6::-moz-selection,.terminal pre::-moz-selection,.terminal td::-moz-selection{background-color:#aaa;color:#000}.cmd .prompt span::selection,.cmd>div::selection,.cmd>div span::selection,.cmd>span::selection,.cmd>span span::selection,.cmd div::selection,.terminal .terminal-output .raw div::selection,.terminal .terminal-output div div::selection,.terminal .terminal-output div div a::selection,.terminal .terminal-output div span::selection,.terminal h1::selection,.terminal h2::selection,.terminal h3::selection,.terminal h4::selection,.terminal h5::selection,.terminal h6::selection,.terminal pre::selection,.terminal td::selection{background-color:hsla(0,0%,67%,.99);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}.ui-dialog-content .terminal{width:100%;height:100%;box-sizing:border-box}.ui-dialog .ui-dialog-content.dterm{padding:0}.clear{clear:both}.terminal a{color:#0f60ff;color:var(--link-color,#0f60ff)}.terminal a:hover{background:#0f60ff;background:var(--link-color,#0f60ff);color:var(--background,#000);text-decoration:none}.terminal .terminal-fill{position:absolute;left:0;top:-100%;width:100%;height:100%;margin:1px 0 0;border:none;opacity:0;pointer-events:none;box-sizing:border-box}.terminal,.terminal .terminal-fill{padding:10px}@-webkit-keyframes terminal-blink{0%,to{background-color:#000;color:#aaa}50%{background-color:#bbb;color:#000}}@keyframes terminal-blink{0%,to{background-color:#000;color:#aaa}50%{background-color:#bbb;color:#000}}@-webkit-keyframes terminal-bar{0%,to{border-left-color:#aaa}50%{border-left-color:#000}}@keyframes terminal-bar{0%,to{border-left-color:#aaa}50%{border-left-color:#000}}@-webkit-keyframes terminal-underline{0%,to{border-bottom-color:#aaa;position:relative;line-height:12px;margin-top:1px;border-left:none;margin-left:0}50%{border-bottom-color:#000;position:relative;line-height:12px;margin-top:1px;border-left:none;margin-left:0}}@keyframes terminal-underline{0%,to{border-bottom-color:#aaa;position:relative;line-height:12px;margin-top:1px;border-left:none;margin-left:0}50%{border-bottom-color:#000;position:relative;line-height:12px;margin-top:1px;border-left:none;margin-left:0}}.underline-animation .cursor.blink{border-left:none;-webkit-animation-name:terminal-underline;animation-name:terminal-underline}.bar-animation .cursor.blink{-webkit-animation-name:terminal-bar;animation-name:terminal-bar}@supports (--css:variables){.cmd,.terminal{color:var(--color,#aaa);background-color:var(--background,#000)}.terminal .font{width:calc(var(--size, 1) * 1em);height:calc(var(--size, 1) * 1em)}.terminal span[style*="--length"]{width:calc(var(--length, 1) * var(--char-width, 7.23438) * 1px);display:inline-block}.cmd,.cmd .prompt,.terminal,.terminal .terminal-output>div>div{font-size:calc(var(--size, 1) * 12px);line-height:calc(var(--size, 1) * 14px)}.terminal .terminal-output>div>div{min-height:calc(var(--size, 1) * 14px)}.cmd .inverted,.terminal .inverted{background-color:var(--color,#aaa);color:var(--background,#000)}.cmd .cursor.blink{-webkit-animation:var(--animation,terminal-blink) 1s infinite step-start;animation:var(--animation,terminal-blink) 1s infinite step-start;color:var(--color,#aaa);background-color:var(--background,#000)}.cmd .prompt span::-moz-selection,.cmd>div::-moz-selection,.cmd>div span::-moz-selection,.cmd>span::-moz-selection,.cmd>span span::-moz-selection,.cmd div::-moz-selection,.terminal .terminal-output div div::-moz-selection,.terminal .terminal-output div div a::-moz-selection,.terminal .terminal-output div span::-moz-selection,.terminal h1::-moz-selection,.terminal h2::-moz-selection,.terminal h3::-moz-selection,.terminal h4::-moz-selection,.terminal h5::-moz-selection,.terminal h6::-moz-selection,.terminal pre::-moz-selection,.terminal td::-moz-selection{background-color:var(--color,#aaa);color:var(--background,#000)}.cmd .prompt span::selection,.cmd>div::selection,.cmd>div span::selection,.cmd>span::selection,.cmd>span span::selection,.cmd div::selection,.terminal .terminal-output div div::selection,.terminal .terminal-output div div a::selection,.terminal .terminal-output div span::selection,.terminal h1::selection,.terminal h2::selection,.terminal h3::selection,.terminal h4::selection,.terminal h5::selection,.terminal h6::selection,.terminal pre::selection,.terminal td::selection{background-color:var(--color,hsla(0,0%,67%,.99));color:var(--background,#000)}@-webkit-keyframes terminal-blink{0%,to{background-color:var(--background,#000);color:var(--color,#aaa)}50%{background-color:var(--color,#aaa);color:var(--background,#000)}}@keyframes terminal-blink{0%,to{background-color:var(--background,#000);color:var(--color,#aaa)}50%{background-color:var(--color,#aaa);color:var(--background,#000)}}@-webkit-keyframes terminal-bar{0%,to{border-left-color:var(--background,#000)}50%{border-left-color:var(--color,#aaa)}}@keyframes terminal-bar{0%,to{border-left-color:var(--background,#000)}50%{border-left-color:var(--color,#aaa)}}@-webkit-keyframes terminal-underline{0%,to{border-bottom-color:var(--color,#aaa);position:relative;line-height:calc(var(--size, 1) * 12px);margin-top:calc(var(--size, 1) * 1px);border-left:none;margin-left:0}50%{border-bottom-color:var(--background,#000);position:relative;line-height:calc(var(--size, 1) * 12px);margin-top:calc(var(--size, 1) * 1px);border-left:none;margin-left:0}}@keyframes terminal-underline{0%,to{border-bottom-color:var(--background,#000);position:relative;line-height:calc(var(--size, 1) * 12px);margin-top:calc(var(--size, 1) * 1px);border-left:none;margin-left:0}50%{border-bottom-color:var(--color,#aaa);position:relative;line-height:calc(var(--size, 1) * 12px);margin-top:calc(var(--size, 1) * 1px);border-left:none;margin-left:0}}}@supports (-ms-ime-align:auto){.cmd .prompt span::selection,.cmd>div::selection,.cmd>div span::selection,.cmd>span::selection,.cmd>span span::selection,.cmd div::selection,.terminal .terminal-output div div::selection,.terminal .terminal-output div div a::selection,.terminal .terminal-output div span::selection,.terminal h1::selection,.terminal h2::selection,.terminal h3::selection,.terminal h4::selection,.terminal h5::selection,.terminal h6::selection,.terminal pre::selection,.terminal td::selection{background-color:hsla(0,0%,67%,.99);color:#000}}
/**@license
* __ _____ ________ __
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
* \/ /____/ version 1.14.0
*
* This file is part of jQuery Terminal. http://terminal.jcubic.pl
*
* Copyright (c) 2010-2018 Jakub Jankiewicz <http://jcubic.pl/me>
* Released under the MIT license
*
* Contains:
*
* Storage plugin Distributed under the MIT License
* modified to work from Data URIs that block storage and cookies in Chrome
* Copyright (c) 2010 Dave Schindler
*
* jQuery Timers licenced with the WTFPL
* <http://jquery.offput.ca/timers/>
*
* Cross-Browser Split 1.1.1
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
* Available under the MIT License
*
* jQuery Caret
* Copyright (c) 2009, Gideon Sireling
* 3 clause BSD License
*
* sprintf.js
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 24 Mar 2018 16:04:12 +0000
*/
(function(e){var n=function(){if(!n.cache.hasOwnProperty(arguments[0])){n.cache[arguments[0]]=n.parse(arguments[0])}return n.format.call(null,n.cache[arguments[0]],arguments)};n.format=function(e,t){var o=1,a=e.length,s="",l,f=[],u,c,p,m,h,d;for(u=0;u<a;u++){s=r(e[u]);if(s==="string"){f.push(e[u])}else if(s==="array"){p=e[u];if(p[2]){l=t[o];for(c=0;c<p[2].length;c++){if(!l.hasOwnProperty(p[2][c])){throw n('[sprintf] property "%s" does not exist',p[2][c])}l=l[p[2][c]]}}else if(p[1]){l=t[p[1]]}else{l=t[o++]}if(/[^s]/.test(p[8])&&r(l)!=="number"){throw n("[sprintf] expecting number but found %s",r(l))}switch(p[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=p[7]?l.toExponential(p[7]):l.toExponential();break;case"f":l=p[7]?parseFloat(l).toFixed(p[7]):parseFloat(l);break;case"o":l=l.toString(8);break;case"s":l=(l=String(l))&&p[7]?l.substring(0,p[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(p[8])&&p[3]&&l>=0?" +"+l:l;h=p[4]?p[4]==="0"?"0":p[4].charAt(1):" ";d=p[6]-String(l).length;m=p[6]?i(h,d):"";f.push(p[5]?l+m:m+l)}}return f.join("")};n.cache={};n.parse=function(e){var n=e,t=[],r=[],i=0;while(n){if((t=/^[^\x25]+/.exec(n))!==null){r.push(t[0])}else if((t=/^\x25{2}/.exec(n))!==null){r.push("%")}else if((t=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(n))!==null){if(t[2]){i|=1;var o=[],a=t[2],s=[];if((s=/^([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1]);while((a=a.substring(s[0].length))!==""){if((s=/^\.([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1])}else if((s=/^\[(\d+)\]/.exec(a))!==null){o.push(s[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}t[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}r.push(t)}else{throw"[sprintf] huh?"}n=n.substring(t[0].length)}return r};var t=function(e,t,r){r=t.slice(0);r.splice(0,0,e);return n.apply(null,r)};function r(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,n){for(var t=[];n>0;t[--n]=e){}return t.join("")}e.sprintf=n;e.vsprintf=t})(typeof global!=="undefined"?global:window);(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else if(typeof module==="object"&&module.exports){module.exports=function(n,t){if(t===undefined){if(typeof window!=="undefined"){t=require("jquery")}else{t=require("jquery")(n)}}e(t);return t}}else{e(jQuery)}})(function(e,n){"use strict";function t(){var n=e.Callbacks();var t=false;this.resolve=function(){n.fire();t=true};this.add=function(e){if(t){e()}else{n.add(e)}}}e.omap=function(n,t){var r={};e.each(n,function(e,i){r[e]=t.call(n,e,i)});return r};e.fn.text_length=function(){return this.map(function(){return e(this).text().length}).get().reduce(function(e,n){return e+n},0)};var r={clone_object:function(n){var t={};if(typeof n==="object"){if(e.isArray(n)){return this.clone_array(n)}else if(n===null){return n}else{for(var r in n){if(e.isArray(n[r])){t[r]=this.clone_array(n[r])}else if(typeof n[r]==="object"){t[r]=this.clone_object(n[r])}else{t[r]=n[r]}}}}return t},clone_array:function(n){if(!e.isFunction(Array.prototype.map)){throw new Error("Your browser don't support ES5 array map "+"use es5-shim")}return n.slice(0).map(function(e){if(typeof e==="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var i=function(e){return r.clone_object(e)};var o=function(){try{var e="test",n=window.localStorage;n.setItem(e,"1");n.removeItem(e);return true}catch(e){return false}};var a=function(){try{document.cookie.split(";");return true}catch(e){return false}};var s=o();function l(e,n){var t;if(typeof e==="string"&&typeof n==="string"){h[e]=n;return true}else if(typeof e==="object"&&typeof n==="undefined"){for(t in e){if(e.hasOwnProperty(t)){h[t]=e[t]}}return true}return false}function f(e,n){var t,r,i;t=new Date;t.setTime(t.getTime()+31536e6);r="; expires="+t.toGMTString();if(typeof e==="string"&&typeof n==="string"){document.cookie=e+"="+n+r+"; path=/";return true}else if(typeof e==="object"&&typeof n==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+r+"; path=/"}}return true}return false}function u(e){return h[e]}function c(e){var n,t,r,i;n=e+"=";t=document.cookie.split(";");for(r=0;r<t.length;r++){i=t[r];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(n)===0){return i.substring(n.length,i.length)}}return null}function p(e){return delete h[e]}function m(e){return f(e,"",-1)}var h;if(!a()&&!s){h={};e.extend({Storage:{set:l,get:u,remove:p}})}else{if(s){h=window.localStorage}e.extend({Storage:{set:s?l:f,get:s?u:c,remove:s?p:m}})}var d=e;d.fn.extend({everyTime:function(e,n,t,r,i){return this.each(function(){d.timer.add(this,e,n,t,r,i)})},oneTime:function(e,n,t){return this.each(function(){d.timer.add(this,e,n,t,1)})},stopTime:function(e,n){return this.each(function(){d.timer.remove(this,e,n)})}});d.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1e3,das:1e4,hs:1e5,ks:1e6},timeParse:function(e){if(e===n||e===null){return null}var t=this.regex.exec(d.trim(e.toString()));if(t[2]){var r=parseInt(t[1],10);var i=this.powers[t[2]]||1;return r*i}else{return e}},add:function(e,n,t,r,i,o){var a=0;if(d.isFunction(t)){if(!i){i=r}r=t;t=n}n=d.timer.timeParse(n);if(typeof n!=="number"||isNaN(n)||n<=0){return}if(i&&i.constructor!==Number){o=!!i;i=0}i=i||0;o=o||false;if(!e.$timers){e.$timers={}}if(!e.$timers[t]){e.$timers[t]={}}r.$timerID=r.$timerID||this.guid++;var s=function(){if(o&&s.inProgress){return}s.inProgress=true;if(++a>i&&i!==0||r.call(e,a)===false){d.timer.remove(e,t,r)}s.inProgress=false};s.$timerID=r.$timerID;if(!e.$timers[t][r.$timerID]){e.$timers[t][r.$timerID]=window.setInterval(s,n)}if(!this.global[t]){this.global[t]=[]}this.global[t].push(e)},remove:function(e,n,t){var r=e.$timers,i;if(r){if(!n){for(var o in r){if(r.hasOwnProperty(o)){this.remove(e,o,t)}}}else if(r[n]){if(t){if(t.$timerID){window.clearInterval(r[n][t.$timerID]);delete r[n][t.$timerID]}}else{for(var a in r[n]){if(r[n].hasOwnProperty(a)){window.clearInterval(r[n][a]);delete r[n][a]}}}for(i in r[n]){if(r[n].hasOwnProperty(i)){break}}if(!i){i=null;delete r[n]}}for(i in r){if(r.hasOwnProperty(i)){break}}if(!i){e.$timers=null}}}}});if(/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())){e(window).one("unload",function(){var e=d.timer.global;for(var n in e){if(e.hasOwnProperty(n)){var t=e[n],r=t.length;while(--r){d.timer.remove(t[r],n)}}}})}(function(e){if(!String.prototype.split.toString().match(/\[native/)){return}var n=String.prototype.split,t=/()??/.exec("")[1]===e,r;r=function(r,i,o){if(Object.prototype.toString.call(i)!=="[object RegExp]"){return n.call(r,i,o)}var a=[],s=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.extended?"x":"")+(i.sticky?"y":""),l=0,f,u,c,p;i=new RegExp(i.source,s+"g");r+="";if(!t){f=new RegExp("^"+i.source+"$(?!\\s)",s)}o=o===e?-1>>>0:o>>>0;while(u=i.exec(r)){c=u.index+u[0].length;if(c>l){a.push(r.slice(l,u.index));if(!t&&u.length>1){u[0].replace(f,function(){for(var n=1;n<arguments.length-2;n++){if(arguments[n]===e){u[n]=e}}})}if(u.length>1&&u.index<r.length){Array.prototype.push.apply(a,u.slice(1))}p=u[0].length;l=c;if(a.length>=o){break}}if(i.lastIndex===u.index){i.lastIndex++}}if(l===r.length){if(p||!i.test("")){a.push("")}}else{a.push(r.slice(l))}return a.length>o?a.slice(0,o):a};String.prototype.split=function(e,n){return r(this,e,n)};return r})();e.fn.caret=function(e){var n=this[0];var t=n.contentEditable==="true";if(arguments.length===0){if(window.getSelection){if(t){n.focus();var r=window.getSelection().getRangeAt(0),i=r.cloneRange();i.selectNodeContents(n);i.setEnd(r.endContainer,r.endOffset);return i.toString().length}return n.selectionStart}if(document.selection){n.focus();if(t){var r=document.selection.createRange(),i=document.body.createTextRange();i.moveToElementText(n);i.setEndPoint("EndToEnd",r);return i.text.length}var e=0,o=n.createTextRange(),i=document.selection.createRange().duplicate(),a=i.getBookmark();o.moveToBookmark(a);while(o.moveStart("character",-1)!==0)e++;return e}return 0}if(e===-1)e=this[t?"text":"val"]().length;if(window.getSelection){if(t){n.focus();window.getSelection().collapse(n.firstChild,e)}else n.setSelectionRange(e,e)}else if(document.body.createTextRange){var o=document.body.createTextRange();o.moveToElementText(n);o.moveStart("character",e);o.collapse(true);o.select()}if(!t&&!this.is(":focus")){n.focus()}return e};e.fn.resizer=function(n){var t=arguments[0]==="unbind";if(!t&&!e.isFunction(n)){throw new Error('Invalid argument, it need to a function or string "unbind".')}if(t){n=e.isFunction(arguments[1])?arguments[1]:null}return this.each(function(){var r=e(this);var i;var o;if(t){o=r.data("callbacks");if(n&&o){o.remove(n);if(!o.has()){o=null}}else{o=null}if(!o){r.removeData("callbacks");if(window.ResizeObserver){var a=r.data("observer");if(a){a.unobserve(this);r.removeData("observer")}}else{i=r.find("> iframe");if(i.length){e(i[0].contentWindow).off("resize").remove();i.remove()}}}}else if(r.data("callbacks")){e(this).data("callbacks").add(n)}else{o=e.Callbacks();o.add(n);r.data("callbacks",o);var s;var l=true;if(window.ResizeObserver){s=new ResizeObserver(function(){if(!l){var e=r.data("callbacks");e.fire()}l=false});s.observe(this);r.data("observer",s)}else{i=e("<iframe/>").addClass("resizer").appendTo(this)[0];e(i.contentWindow).on("resize",function(){o.fire()})}}})};function g(e){e.attr({role:"presentation","aria-hidden":"true"})}var v=[];function y(e,n){var t=(e?e+": ":"")+w(n);if(v.indexOf(t)===-1){v.push(t);alert(t+(n.stack?"\n"+n.stack:""))}}function b(e,n){var t=n.offset().left;return n.outerWidth()<=e.clientX-t}function w(e){if(typeof e==="string"){return e}else if(typeof e.fileName==="string"){return e.fileName+": "+e.message}else{return e.message}}function _(){var n=[].slice.call(arguments);var t=0;e.extend(this,{get:function(){return n},index:function(){return t},rotate:function(e){if(!e){var r=n.filter(function(e){return typeof e!=="undefined"});if(!r.length){return}}if(n.length===1){return n[0]}else{if(t===n.length-1){t=0}else{++t}if(typeof n[t]!=="undefined"){return n[t]}else{return this.rotate(true)}}},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);t=n.length-1},front:function(){if(n.length){var e=t;var r=false;while(!n[e]){e++;if(e>n.length){if(r){break}e=0;r=true}}return n[e]}},map:function(e){return n.filter(Boolean).map(e)},forEach:function(e){n.filter(Boolean).forEach(e)},append:function(e){n.push(e)}})}function x(n){var t=n instanceof Array?n:n?[n]:[];e.extend(this,{data:function(){return t},map:function(n){return e.map(t,n)},size:function(){return t.length},pop:function(){if(t.length===0){return null}else{var e=t[t.length-1];t=t.slice(0,t.length-1);return e}},push:function(e){t=t.concat([e]);return e},top:function(){return t.length>0?t[t.length-1]:null},clone:function(){return new x(t.slice(0))}})}function k(n,t,r){var i=true;var o="";if(typeof n==="string"&&n!==""){o=n+"_"}o+="commands";var a;if(r){a=[]}else{a=e.Storage.get(o);a=a?JSON.parse(a):[]}var s=a.length-1;e.extend(this,{append:function(n){if(i){if(a[a.length-1]!==n){a.push(n);if(t&&a.length>t){a=a.slice(-t)}s=a.length-1;if(!r){e.Storage.set(o,JSON.stringify(a))}}}},set:function(n){if(n instanceof Array){a=n;if(!r){e.Storage.set(o,JSON.stringify(a))}}},data:function(){return a},reset:function(){s=a.length-1},last:function(){return a[a.length-1]},end:function(){return s===a.length-1},position:function(){return s},current:function(){return a[s]},next:function(){var e=s;if(s<a.length-1){++s}if(e!==s){return a[s]}},previous:function(){var e=s;if(s>0){--s}if(e!==s){return a[s]}},clear:function(){a=[];this.purge()},enabled:function(){return i},enable:function(){i=true},purge:function(){if(!r){e.Storage.remove(o)}},disable:function(){i=false}})}var T=0;e.cmd={defaults:{mask:false,caseSensitiveSearch:true,historySize:60,prompt:"> ",enabled:true,history:true,onPositionChange:e.noop}};e.fn.cmd=function(t){var r=e.extend({},e.cmd.defaults,t);var i=this;var o=i.data("cmd");if(o){return o}var a=T++;i.addClass("cmd");i.append('<span class="prompt"></span>');i.append('<div class="cursor-line">'+"<span></span>"+'<span class="cursor">&nbsp;</span>'+"<span></span>"+"</div>");g(i.find(".cursor-line"));var s=e("<textarea>").attr({autocapitalize:"off",spellcheck:"false",tabindex:1}).addClass("clipboard").appendTo(i).val(" ");if(r.width){i.width(r.width)}var l;var f;var u=i.find(".prompt");var c=false;var p="";var m=null;var h;var d="";var v;var b="";var w=0;var _;var x;var E=0;var C,R;var S=i.find(".cursor");var A;var F;var j=0;function L(n){var t=e(n.target);if(t.is("span")){return t.index()+t.parents("span").prevAll().text_length()+t.closest('[role="presentation"]').prevUntil(".prompt").text_length()}else if(t.is('div[role="presentation"]')){var r=t.index();var i=d.split(/\n/).slice(0,r);return i.reduce(function(e,n){return e+pe(n)},0)+(i.length-1)}}var O={SPACEBAR:" ",UP:"ARROWUP",DOWN:"ARROWDOWN",LEFT:"ARROWLEFT",RIGHT:"ARROWRIGHT",DEL:"DELETE",MULTIPLY:"*",DIVIDE:"/",SUBTRACT:"-",ADD:"+"};function z(e){if(e.key){var n=e.key.toUpperCase();if(O[n]){n=O[n]}if(n==="CONTROL"){return"CTRL"}else{var t=[];if(e.ctrlKey){t.push("CTRL")}if(e.metaKey&&n!=="META"){t.push("META")}if(e.shiftKey&&n!=="SHIFT"){t.push("SHIFT")}if(e.altKey&&n!=="ALT"){t.push("ALT")}if(t.length&&n===" "){n="SPACEBAR"}if(e.key){t.push(n)}return t.join("+")}}}var I;var P={"ALT+D":function(){i.set(d.slice(0,w)+d.slice(w).replace(/ *[^ ]+ *(?= )|[^ ]+$/,""),true);return false},ENTER:function(){if(R&&d&&!r.mask&&(e.isFunction(t.historyFilter)&&t.historyFilter(d))||t.historyFilter instanceof RegExp&&d.match(t.historyFilter)||!t.historyFilter){R.append(d)}var n=d;R.reset();je="";Re=true;i.set("");if(t.commands){t.commands(n)}if(e.isFunction(_)){ve()}s.val("");return false},"SHIFT+ENTER":function(){i.insert("\n");return true},BACKSPACE:function(){if(c){p=p.slice(0,-1);re()}else if(d!==""&&w>0){i["delete"](-1)}i.oneTime(1,function(){Re=true})},TAB:function(){i.insert("\t")},"CTRL+D":function(){i["delete"](1);return false},DELETE:function(){i["delete"](1);return true},ARROWUP:D,"CTRL+P":D,ARROWDOWN:H,"CTRL+N":H,ARROWLEFT:B,"CTRL+B":B,"CTRL+ARROWLEFT":function(){var e=w-1;var n=0;if(d[e]===" "){--e}for(var t=e;t>0;--t){if(d[t]===" "&&d[t+1]!==" "){n=t+1;break}else if(d[t]==="\n"&&d[t+1]!=="\n"){n=t;break}}i.position(n)},"CTRL+R":function(){if(c){oe(true)}else{h=_;re();v=d;i.set("");ge();c=true}return false},"CTRL+G":function(){if(c){_=h;ve();i.set(v);ge();c=false;p="";return false}},ARROWRIGHT:W,"CTRL+F":W,"CTRL+ARROWRIGHT":function(){if(d[w]===" "){++w}var e=/\S[\n\s]{2,}|[\n\s]+\S?/;var n=d.slice(w).match(e);if(!n||n[0].match(/^\s+$/)){i.position(d.length)}else if(n[0][0]!==" "){w+=n.index+1}else{w+=n.index+n[0].length-1;if(n[0][n[0].length-1]!==" "){--w}}ge()},F12:$,END:U,"CTRL+E":U,HOME:M,"CTRL+A":M,"SHIFT+INSERT":N,"CTRL+SHIFT+T":$,"CTRL+W":function(){if(d!==""&&w!==0){var e=d.slice(0,w).match(/([^ ]+ *$)/);if(e[0].length){b=i["delete"](-e[0].length);ne(i,b)}}return false},"CTRL+H":function(){if(d!==""&&w>0){i["delete"](-1)}return false},"CTRL+X":$,"CTRL+C":$,"CTRL+T":$,"CTRL+Y":function(){if(b!==""){i.insert(b)}},"CTRL+V":N,"META+V":N,"CTRL+K":function(){if(d.length-w){b=i["delete"](d.length-w);ne(i,b)}return false},"CTRL+U":function(){if(d!==""&&w!==0){b=i["delete"](-w);ne(i,b)}return false},"CTRL+TAB":function(){return false},"META+`":$,"META+R":$,"META+L":$};function $(){return true}function N(){s.val("");j=0;if(i.isenabled()&&!s.is(":focus")){s.trigger("focus",[true])}s.one("input",ye);return true}function D(){if(_e){v=d;i.set(R.current())}else{i.set(R.previous())}_e=false;return false}function H(){i.set(R.end()?v:R.next());return false}function B(){if(w>0){i.position(-1,true);ge()}}function W(){if(w<d.length){i.position(1,true)}return false}function M(){i.position(0)}function U(){i.position(d.length)}function Y(){var e=s.is(":focus");if(x){if(!e){}i.oneTime(10,function(){if(!s.is(":focus")&&x){s.trigger("focus",[true])}})}else if(e&&(Z||!x)){s.trigger("blur",[true])}}function V(e){if(!i.isenabled()){return}i.oneTime(10,function(){if(s.val()!==d&&!e){s.val(" "+d)}if(x){i.oneTime(10,function(){try{if(s.caret()!==w+1){s.caret(w+1)}}catch(e){}})}})}if(q&&!K){A=function(e){if(e){S.addClass("blink")}else{S.removeClass("blink")}};F=function(){var e=S.clone();e.insertBefore(S);S.remove();S=e}}else{var Q=false;A=function(e){if(e&&!Q){Q=true;S.addClass("inverted blink");i.everyTime(500,"blink",te)}else if(Q&&!e){Q=false;i.stopTime("blink",te);S.removeClass("inverted blink")}};F=function(){A(false);A(true)}}function te(){S.toggleClass("inverted")}function re(){_="(reverse-i-search)`"+p+"': ";ve()}function ie(){_=h;c=false;m=null;p=""}function oe(n){var t=R.data();var o,a;var s=t.length;if(n&&m>0){s-=m}if(p.length>0){for(var l=p.length;l>0;l--){a=e.terminal.escape_regex(p.substring(0,l));if(r.caseSensitiveSearch){o=new RegExp(a)}else{o=new RegExp(a,"i")}for(var f=s;f--;){if(o.test(t[f])){m=t.length-f;i.position(t[f].indexOf(a));i.set(t[f],true);ge();if(p.length!==l){p=p.substring(0,l);re()}return}}}}p=""}function ae(){var e=i.find(".prompt").text("&nbsp;");var n=i.width();var t=e[0].getBoundingClientRect().width;l=Math.floor(n/t);ve()}function le(n){function t(n){return e.terminal.split_equal(n,l)}function r(n){return n.filter(function(n){return!e.terminal.strip(n).match(/^ $/)})}var i=u.text();var o=new RegExp("^"+e.terminal.escape_regex(i));var a;if(n.match(/\n/)){var s=n.split("\n");var c=l-f-1;for(var p=0;p<s.length-1;++p){s[p]+=" "}if(J(s[0])>c){a=t(i+s[0]);a[0]=a[0].replace(o,"");a=r(a)}else{a=[s[0]]}for(p=1;p<s.length;++p){if(J(s[p])>l){var m=t(s[p]);if(p<s.length-1){m=r(m)}a=a.concat(m)}else{a.push(s[p])}}}else{a=t(i+n,l);a[0]=a[0].replace(o,"")}if(a.length>1&&a[a.length-1].length===l){a.push("")}return a}function fe(n){n=e.terminal.escape_formatting(n);try{return e.terminal.apply_formatters(n,r)}catch(e){y("[Formatting]",e)}}function ue(n){return e.terminal.format(e.terminal.encode(ce(n)))}function ce(n){function t(n){if(e.terminal.is_formatting(n)){if(n.match(/\]\\\]/)){n=n.replace(/\]\\\]/g,"]\\\\]")}}else{if(n.match(/\\$/)){n+="\\"}n="[[;;]"+n+"]"}return n}var r=pe(n);if(r===1){return t(n)}var i=[];for(var o=0;o<r;++o){var a=e.terminal.substring(n,o,o+1);i.push(t(a))}return i.join("")}function pe(n){return e.terminal.length(n)}function me(n,t,r){return e.terminal.substring(n,t,r)}function he(n){var t=e.terminal.defaults.formatters.filter(function(e){return e instanceof Array});if(n===0){return n}if(t.length){return t.reduce(function(e,n){var t=e[0];var r=e[1];return de(t,n[0],n[1],r)},[d,n])[1]}return n}function de(e,n,t,r){var i="";var o;var a=0;var s;var l=r;var f;n.lastIndex=0;while(o=n.exec(e)){var u=pe(me(e,0,n.lastIndex));f=u-pe(o[0]);if(a<f){i+=me(e,a,f)}a=u;s=t.replace(/\$(\$|\d)/g,function(e,n){if(n==="$"){return"$"}return o[n]});i+=s;if(f<r){if(u<r){l=Math.max(0,l+pe(s)-pe(o[0]))}else{l+=pe(s)-(r-f)}}}if(a<pe(e)){i+=me(e,a)}return[i,l]}var ge=function(){var t=S.prev();var o=S.next();var a=S.parent();function s(n,r){var i=pe(n);if(r===i){t.html(ue(n));S.html("&nbsp;");o.html("")}else if(r===0){t.html("");S.html(ue(me(n,0,1)));o.html(ue(me(n,1)))}else{var a=e.terminal.substring(n,0,r);t.html(ue(a));var s=me(n,r,r+1);S.html(ue(s));if(r===i-1){o.html("")}else{o.html(ue(me(n,r+1)))}}}function u(e){return'<div role="presentation" aria-hidden="true">'+ue(e)+"</div>"}function c(n){var t=a;e.each(n,function(n,r){t=e(u(r)).insertAfter(t)})}function p(n){e.each(n,function(e,n){a.before(u(n))})}return function(){var m;switch(typeof r.mask){case"boolean":m=r.mask?d.replace(/./g,"*"):d;break;case"string":m=d.replace(/./g,r.mask);break}var h=E;m=fe(X(m.replace(/&/g,"&amp;")));var g;i.find("div:not(.cursor-line,.clipboard-wrapper)").remove();t.html("");if(J(G(m))>l-f-1||m.match(/\n/)){var v=m.match(/\t/g);var y=v?v.length*3:0;if(v){m=m.replace(/\t/g,"\0\0\0\0")}var b=le(m);if(v){b=e.map(b,function(e){return e.replace(/\x00\x00\x00\x00/g,"\t")})}var w=pe(b[0]);if(w===0&&b.length===1){}else if(h<w){s(b[0],h);c(b.slice(1))}else if(h===w){a.before(u(b[0]));s(b[1]||"",0);if(b.length>1){c(b.slice(2))}}else if(h<w){s(b[0],h);c(b.slice(1))}else if(h===w){a.before(u(b[0]));s(b[1],0);c(b.slice(2))}else{var _=b.slice(-1)[0];var x=pe(m);var k=x-h-y;var T=pe(_);var C=0;if(k===-1){k=0}if(k<=T){p(b.slice(0,-1));if(T===k){C=0}else{C=T-k}s(_,C)}else{var R;var A;C=h;for(g=0;g<b.length;++g){var F=e.terminal.length(b[g]);if(C>F){C-=F}else{break}}A=b[g];R=g;if(C===pe(A)){C=0;A=b[++R];if(A===n){var j=e.terminal.defaults.strings.redrawError;throw new Error(j)}}s(A,C);p(b.slice(0,R));c(b.slice(R+1))}}}else if(m===""){t.html("");S.html("&nbsp;");o.html("")}else{s(m,h)}}}();var ve=function(){function n(n){var t=e.terminal.split_equal(e.terminal.encode(n),l);var r=e.terminal.format(t[t.length-1]);var i=t.slice(0,-1).map(function(n){return'<span class="line">'+e.terminal.format(n)+"</span>"}).concat([r]).join("\n");if(u.html()!==i){u.html(i);f=J(e("<span>"+r+"</span>").text())}}return function(){switch(typeof _){case"string":n(_);break;case"function":_(n);break}}}();function ye(){if(j++>0){return}if(i.isenabled()){i.oneTime(100,function(){i.insert(s.val());s.val(d);V()})}}function be(){if(e.isFunction(t.onCommandChange)){t.onCommandChange(d)}}function we(e){return e.replace(/[\r\n]{2}/g,"\n")}e.extend(i,{name:function(e){if(e!==n){C=e;var t=R&&R.enabled()||!R;R=new k(e,r.historySize,r.history==="memory");if(!t){R.disable()}return i}else{return C}},purge:function(){R.clear();return i},history:function(){return R},delete:function(e,n){var t;if(e===0){return i}else if(e<0){if(w>0){t=d.slice(0,w).slice(e);d=d.slice(0,w+e)+d.slice(w,d.length);if(!n){i.position(w+e)}be()}}else if(d!==""&&w<d.length){t=d.slice(w).slice(0,e);d=d.slice(0,w)+d.slice(w+e,d.length);be()}ge();V();return t},set:function(e,t,r){if(e!==n){d=we(e);if(!t){i.position(d.length)}ge();V();if(!r){be()}}return i},keymap:function(n,t){function r(e,n){return function(t){return n(t,P[e])}}if(typeof n==="undefined"){return I}else if(typeof n==="string"){if(typeof t==="undefined"){if(I[n]){return I[n]}else if(P[n]){return P[n]}}else{I[n]=r(n,t)}}else{I=e.extend({},I?I:P,e.omap(n||{},r));return i}},insert:function(e,n){e=we(e);if(w===d.length){d+=e}else if(w===0){d=e+d}else{d=d.slice(0,w)+e+d.slice(w)}if(!n){i.position(e.length,true)}else{V()}ge();be();V();return i},get:function(){return d},commands:function(e){if(e){r.commands=e;return i}else{return e}},destroy:function(){Oe.unbind("keypress.cmd",ze);Oe.unbind("keydown.cmd",Le);Oe.unbind("input.cmd",$e);i.stopTime("blink",te);i.find(".cursor").next().remove().end().prev().remove().end().remove();i.find(".prompt, .clipboard").remove();i.removeClass("cmd").removeData("cmd").off(".cmd");return i},prompt:function(e){if(e===n){return _}else{if(typeof e==="string"||typeof e==="function"){_=e}else{throw new Error("prompt must be a function or string")}ve();ge();return i}},kill_text:function(){return b},position:function(n,t){if(typeof n==="number"){if(t){w+=n}else if(n<0){w=0}else if(n>d.length){w=d.length}else{w=n}E=he(w);if(e.isFunction(r.onPositionChange)){r.onPositionChange(w)}ge();V(true);return i}else{return w}},display_position:function(t,r){if(t===n){return E}else{var o=fe(d);var a=e.terminal.length(o);var s=e.terminal.length(d);if(a===s){return i.position(t)}else{var l;if(r){l=E+t}else if(t>a){l=a}else{l=t}if(l===a){i.position(e.terminal.length(d))}else{for(var f=0;f<s;++f){if(l===he(f)){i.position(f)}}}}return i}},visible:function(){var e=i.visible;return function(){e.apply(i,[]);ge();ve()}}(),show:function(){var e=i.show;return function(){e.apply(i,[]);ge();ve()}}(),resize:function(e){if(e){l=e}else{ae()}ge();ve();return i},enable:function(){if(!x){x=true;i.addClass("enabled");try{s.caret(w)}catch(e){}A(true);ve()}Y();return i},isenabled:function(){return x},disable:function(e){x=false;i.removeClass("enabled");A(false);if(!e){Y()}return i},mask:function(e){if(typeof e==="undefined"){return r.mask}else{r.mask=e;ge();return i}}});i.name(r.name||r.prompt||"");if(typeof r.prompt==="string"){_=r.prompt}else{_="> "}ve();if(r.enabled===true){i.enable()}if(!r.history){R.disable()}var _e=true;var xe=false;var ke=false;var Te=false;var Ee=false;var Ce=false;var Re=true;var Se=false;var Ae=false;var Fe;var je="";function Le(t){Pe('keydown "'+t.key+'" '+t.fake+" "+t.which);Ae=(t.key||"").toLowerCase()==="process"||t.which===0;var o;ke=Ee&&Te;try{if(!t.fake){Te=t.key&&t.key.length===1&&!t.ctrlKey;Ce=String(t.key).toLowerCase()==="unidentified";Se=t.key.toUpperCase()==="BACKSPACE"||t.which===8}}catch(e){}if(t.key==="Unidentified"){Re=true;return}if(!t.fake){Ee=true;Re=false}s.off("input",ye);var a=z(t);if(e.isFunction(r.keydown)){o=r.keydown(t);if(o!==n){if(!o){Fe=true}return o}}if(x){F();Fe=["CTRL+V","META+V"].indexOf(a)!==-1;if(t.which!==38&&!(t.which===80&&t.ctrlKey)){_e=true}if(c&&(t.which===35||t.which===36||t.which===37||t.which===38||t.which===39||t.which===40||t.which===13||t.which===27)){ie();ve();if(t.which===27){i.set("")}ge();Le.call(this,t)}else if(e.isFunction(I[a])){o=I[a](t);if(o===true){return}if(o!==n){return o}}else if(t.altKey){return}else{xe=false;return}}}var Oe=e(document.documentElement||window);i.keymap(r.keymap||{});function ze(t){Pe('keypress "'+t.key+'" '+t.fake);var o;if(!t.fake){Ee=false}if((t.ctrlKey||t.metaKey)&&!t.altKey){return}if(xe){return}if(e.isFunction(r.keypress)){o=r.keypress(t);if(o!==n){if(!o){Fe=true}return o}}if(x){if(t.fake){return}var a;if(se()||t.fake){a=t.key;var s=a.toUpperCase();if(O[s]){a=O[s]}}if(!a||Ce){a=String.fromCharCode(t.which)}if(e.inArray(t.which,[13,0,8])>-1){if(t.keyCode===123){return}return false}else if(a&&(!t.ctrlKey||t.ctrlKey&&t.ctrlKey)&&(!(t.altKey&&t.which===100)||t.altKey)&&!ke){if(c){p+=a;oe();re()}else if(a.length===1){i.insert(a)}}}}function Ie(n,t,r){var i=e.Event(n);i.which=r;i.key=t;i.fake=true;Oe.trigger(i)}function Pe(e){if(false){console.log(e)}}function $e(){Pe("input "+Re+" || "+Ae+" (("+Ee+" || "+ke+") && !"+Fe+" && ("+Te+" || "+Ce+") && !"+Se+")");var e=s.val();if((Re||Ae||(Ee||ke)&&!Fe&&(Te||Ce)&&!Se)&&e!==d){var n=w;if(Re){var t=je;Se=t.substring(0,t.length-1).length===e.length}if(c){p=e;oe();re()}else{var r=e.substring(w);if(r.length===1||Se){if(Re){var o;if(Se){o=8}else{o=r.toUpperCase().charCodeAt(0)}Ie("keydown",Se?"Backspace":r,o)}if(Ee&&!Se){Ie("keypress",r,r.charCodeAt(0))}}if(Se){je=d;return}if(Fe){Fe=false;return}i.set(e)}if(Se){i.position(n-1)}else{i.position(n+Math.abs(e.length-je.length))}}je=d;Fe=false;Re=true}Oe.bind("keypress.cmd",ze).bind("keydown.cmd",Le).bind("input.cmd",$e);(function(){var n=false;var t=0;i.on("mousedown.cmd",function(){n=true}).on("mouseup.cmd",function(o){if(o.originalEvent.button===0&&ee()===""){var s="click_"+a;if(++t===1){var l=n;if(x){i.oneTime(r.clickTimeout,s,function(){var n=e(o.target);if(!n.is(".prompt")&&l){if(x){if(n.is(".cmd")){i.position(d.length)}else{i.display_position(L(o))}}}t=0})}else{t=0}}else{i.stopTime(s);t=0}}n=false})})();i.data("cmd",i);if(!("KeyboardEvent"in window&&"key"in window.KeyboardEvent.prototype)){setTimeout(function(){throw new Error("key event property not supported try https://github."+"com/inexorabletash/polyfill/blob/master/keyboard.js")},0)}return i};var E=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i;var C=/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i;var R=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*[^\\](\\\\)*\\\][^\]]*|[^\]]*|[^[]*\[[^\]]*)\]?)/i;var S=/\[\[([!gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^[]*\[[^\]]*)\]?/gi;var A=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^[]*\[[^\]]*)\]?/gi;var F=/\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^[]*\[[^\]]*)\]/gi;var j=/^\[\[([!gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^[]*\[[^\]]*)\]$/gi;var L=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;var O=/(\bhttps?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\][)])+)/gi;var z=/\b(?![^\s[\]]*])(https?:\/\/(?:(?:(?!&[^;]+;)|(?=&amp;))[^\s"'<>\][)])+)/gi;var I=/((([^<>('")[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})))/g;var P=/((?:"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'|\/[^\/\\]*(?:\\[\S\s][^\/\\]*)*\/[gimy]*(?=\s|$)|(?:\\\s|\S))+)(?=\s|$)/gi;var $=/(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var N=/^(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;var D=/\[\[[!gbiuso]*;[^;]*;[^\]]*\]?$/i;var H=/(\[\[(?:[^\]]|\\\])+\]\])/;var B=/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/;var W=/^\/((?:\\\/|[^/]|\[[^\]]*\/[^\]]*\])+)\/([gimy]*)$/;var M=/^(?=((?:[^"']+|"[^"\\]*(?:\\[^][^"\\]*)*"|'[^'\\]*(?:\\[^][^'\\]*)*')*))\1./;var q=function(){var e=false,t="Webkit Moz O ms Khtml".split(" "),r=document.createElement("div");if(r.style.animationName){e=true}if(e===false){for(var i=0;i<t.length;i++){var o=t[i]+"AnimationName";if(r.style[o]!==n){e=true;break}}}r=null;return e}();var U=function(){var e=window.navigator.userAgent;if(e.match(/MSIE|Trident/)&&!e.match(/IEMobile/)){return false}var n=document.createElement("div");n.style.width="1ch";return n.style.width==="1ch"}();var K=navigator.userAgent.toLowerCase().indexOf("android")!==-1;var J=function(){if(typeof wcwidth==="undefined"){return function(e){return e.length}}else{return wcwidth}}();function Y(n){if(!n.match(/&/)){return n}return e("<span>"+X(n)+"</span>").text()}function G(n){return Y(e.terminal.strip(n))}function X(e){if(!e.match(/[<>]/)){return e}return e.replace(/>/g,"&gt;").replace(/</g,"&lt;")}function V(e){if(typeof wcwidth!=="undefined"){var n=Y(e);var t=J(n);if(t!==n.length){if(U){return"width: "+t+"ch"}else{return"--length: "+t}}}return""}function Q(e){if(typeof wcwidth!=="undefined"){var n=Y(e);if(n.length===1){return e}var t=n.split("").map(function(e){return{len:J(e),chr:e}}).reduce(function(e,n){var t=e[e.length-1];if(t){if(t.len!==n.len){return e.concat([{sum:n.len,len:n.len,str:n.chr}])}else{e.pop();return e.concat([{sum:t.sum+n.len,len:t.len,str:t.str+n.chr}])}}return[{sum:n.len,str:n.chr,len:n.len}]},[]);return t.map(function(e){if(e.len===1){return e.str}var n="";if(U){n="width: "+e.sum+"ch"}else{n="--length: "+e.sum}return'<span style="'+n+'">'+e.str+"</span>"}).join("")}return e}var Z=function(e){var n=false;if(E.test(e)||C.test(e.substr(0,4))){n=true}return n}(navigator.userAgent||navigator.vendor||window.opera);var ee=function(){if(window.getSelection||document.getSelection){return function(){var e=(window.getSelection||document.getSelection)();if(e.text){return e.text}else{return e.toString()}}}else if(document.selection&&document.selection.type!=="Control"){return function(){return document.selection.createRange().text}}return function(){return""}}();function ne(n,t){var r=e("<div>"+t.replace(/\n/,"<br/>")+"<div>");r.appendTo("body");oe(r[0]);try{document.execCommand("copy")}catch(e){}r.remove()}var te=function(){var e=document.createElement("textarea");var n="selectionStart"in e;e=null;if(n){return function(e){var n=e.selectionEnd-e.selectionStart;return e.value.substr(e.selectionStart,n)}}else if(document.selection){return function(){var e=document.selection.createRange();return e.text()}}else{return function(){return""}}}();function re(e){e.selectionStart=e.selectionEnd=0}var ie=function(){if(window.getSelection){var n=window.getSelection();if(n.setBaseAndExtent){return function(e,n){var t=window.getSelection();t.setBaseAndExtent(e,0,n,1)}}else{return function(e,n){var t=window.getSelection();var r=document.createRange();r.setStart(e,0);r.setEnd(n,n.childNodes.length);t.removeAllRanges();t.addRange(r)}}}else{return e.noop}}();function oe(e){if(window.getSelection){var n=window.getSelection();if(n.setBaseAndExtent){n.setBaseAndExtent(e,0,e,1)}else if(document.createRange){var t=document.createRange();t.selectNodeContents(e);n.removeAllRanges();n.addRange(t)}}}function ae(n,t){var r=n.match(P)||[];if(r.length){var i=r.shift();var o=e.map(r,function(e){if(e.match(/^["']/)){e=e.replace(/\n/g,"\\u0000\\u0000\\u0000\\u0000");e=t(e);return e.replace(/\x00\x00\x00\x00/g,"\n")}return t(e)});var a=e.map(r,function(e){var n=e.match(/^(['"]).*\1$/);return n&&n[1]||""});var s=n.substring(i.length).trim();return{command:n,name:i,args:o,args_quotes:a,rest:s}}else{return{command:n,name:"",args:[],args_quotes:a,rest:""}}}e.terminal={version:"1.14.0",date:"Sat, 24 Mar 2018 16:04:12 +0000",color_names:["transparent","currentcolor","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"],Cycle:_,History:k,Stack:x,valid_color:function n(t){if(t.match(L)){return true}else{return e.inArray(t.toLowerCase(),e.terminal.color_names)!==-1}},unclosed_strings:function e(n){return!!n.match(M)},escape_regex:function e(n){if(typeof n==="string"){var t=/([-\\^$[\]()+{}?*.|])/g;return n.replace(t,"\\$1")}},have_formatting:function e(n){return typeof n==="string"&&!!n.match(F)},is_formatting:function e(n){return typeof n==="string"&&!!n.match(j)},format_split:function e(n){return n.split(R).filter(Boolean)},iterate_formatting:function e(t,r){function i(e){return t.substring(e-6,e)==="&nbsp;"||t.substring(e-1,e).match(/\s/)}function o(e){return t.substring(e).match(/^(&[^;]+;)/)}var a=false;var s=false;var l=0;var f;var u=-1;var c;var p=0;for(var m=0;m<t.length;m++){f=t.substring(m).match(N);if(f){a=f[1];s=false}else if(a){if(t[m]==="]"){if(s){a="";s=false}else{s=true}}}else{s=true}var h=a&&s||!a;var d=t[m]==="["&&t[m+1]==="[";if(i(m)&&(h||d)){if(u===-1&&c!==m||u!==-1){u=m}}var g=t[m].match(/[[\]]/);if(h){if(t[m]==="&"){f=o(m);if(f){m+=f[1].length-2;continue}++l;++p}else if(t[m]==="]"&&t[m-1]==="\\"){--l;--p}else if(!g){++l;++p}}if(h&&t[m]!=="]"&&!d){if(J(t[m])===2){p++}var v={count:l,index:m,formatting:a,length:p,text:s,space:u};var y=r(v);if(y===false){break}else if(y){if(y.count!==n){l=y.count}if(y.length!==n){p=y.length}if(y.space!==n){c=u;u=y.space}if(y.index!==n){m=y.index}}}else if(m===t.length-1){r({count:l+1,index:m,formatting:a,length:0,text:s,space:u})}}},substring:function t(r,i,o){if(G(r).substring(i,o)===""){return""}var a=0;var s;var l="";var f="";var u;var c=/(&[^;]+);$/;e.terminal.iterate_formatting(r,function(e){var n;if(i&&e.count===i+1){a=e.index;n=r.substring(0,a+1).match(c);if(n){a-=n[1].length}if(e.formatting){l=e.formatting}}if(o&&e.count===o){f=e.formatting;u=e.index}if(e.count===o+1){s=e.index;n=r.substring(0,s+1).match(c);if(n){s-=n[1].length}if(e.formatting){s=u+1}}});if(i&&!a){return""}if(s===n){s=r.length}r=l+r.substring(a,s);if(f){r=r.replace(/(\[\[^\]]+)?\]$/,"");r+="]"}return r},normalize:function e(n){return n.replace(A,function(e,n,t){if(t===""){return""}var r=n.match(/;/g).length;if(r>=4){var i=n.split(/;/);var o=i.slice(0,4).join(";");var a=i.slice(4).join(";");return"[["+o+";"+(a||t)+"]"+t+"]"}else if(r===2){r=";;"}else if(r===3){r=";"}else{r=""}var s=t.replace(/\\\]/g,"&#93;").replace(/\n/g,"\\n").replace(/&nbsp;/g," ");return"[["+n+r+s+"]"+t+"]"})},split_equal:function n(t,r,i){var o="";var a=[];var s=e.terminal.normalize(t).split(/\n/g);for(var l=0,f=s.length;l<f;++l){if(s[l]===""){a.push("");continue}var u=s[l];var c=0;var p;var m=u.length;e.terminal.iterate_formatting(u,function(n){var t=n.index===m-1;if(n.length>=r||t||n.length===r-1&&J(u[n.index+1])===2){var s=false;if(i&&n.space!==-1){var l=e.terminal.strip(u.substring(n.space));l=e("<span>"+l+"</span>").text();var f=l.length;var h=n.index+r+1;l=l.substring(0,h);if(l.match(/\s|&nbsp;/)||h>f){s=true}}if(i&&n.space!==-1&&n.index!==m-1&&s){p=u.substring(c,n.space);var d=n.space-1}else{p=u.substring(c,n.index+1)}if(i){p=p.replace(/^(&nbsp;|\s)+|(&nbsp;|\s)+$/g,"")}c=(d||n.index)+1;if(o){var g=p.match(/^[^\]]*\]/);p=o+p;if(g){o=""}}var v=p.match(A);if(v){var y=v[v.length-1];if(y[y.length-1]!=="]"){o=y.match($)[1];p+="]"}else if(p.match(D)){p=p.replace(D,"");o=y.match($)[1]}}p=p.replace(/^(\[\[[^\]]+\])?\]/,"");a.push(p);return{index:d,length:0,space:-1}}})}return a},amp:function(e){return e.replace(/&(?!#[0-9]+;|[a-zA-Z]+;)/g,"&amp;")},encode:function n(t){return e.terminal.amp(t).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")},nested_formatting:function n(t){if(!e.terminal.have_formatting(t)){return t}var r=[];var i=/((?:\[\[(?:[^\]]|\\\])+\])?(?:[^\][]|\\\])*\]?)/;var o=/(\[\[(?:[^\]]|\\\])+\])[\s\S]*/;return t.split(i).filter(Boolean).map(function(n){if(n.match(/^\[\[/)){if(!e.terminal.is_formatting(n)){n+="]";r.push(n.replace(o,"$1"))}}else{var t=false;if(n.match(/\]/)){t=true}if(r.length){n=r[r.length-1]+n}if(t){r.pop()}else if(r.length){n+="]"}}return n}).join("")},escape_formatting:function n(t){return e.terminal.escape_brackets(t)},apply_formatters:function(n,t){var r=e.terminal.defaults.formatters;var i=0;try{return r.reduce(function(n,r){i++;if(typeof r==="function"&&r.__meta__){var o=r(n,t);if(typeof o==="string"){return o}}else{return e.terminal.format_split(n).map(function(n){if(e.terminal.is_formatting(n)){return n}else{if(r instanceof Array){return n.replace(r[0],r[1])}else if(typeof r==="function"){var i=r(n,t);if(typeof i==="string"){return i}}return n}}).join("")}return n},n)}catch(e){throw new Error("Error in formatter ["+(i-1)+"]")}},format:function n(t,r){function i(e){if(e.match(/\\]/)){e=e.replace(/(\\+)]/g,function(e,n){if(n.length%2===1){return"]"}else{return n.replace(/../,"\\")}})}return X(e)}var o=e.extend({},{linksNoReferrer:false},r||{});if(typeof t==="string"){var a=e.terminal.format_split(t);t=e.map(a,function(n){if(n===""){return n}else if(e.terminal.is_formatting(n)){n=n.replace(/\[\[[^\]]+\]/,function(e){return e.replace(/&nbsp;/g," ")});return n.replace(S,function(n,t,r,a,s,l,f){if(f===""){return""}f=i(f);var u="";if(t.indexOf("b")!==-1){u+="font-weight:bold;"}var c=[];if(t.indexOf("u")!==-1){c.push("underline")}if(t.indexOf("s")!==-1){c.push("line-through")}if(t.indexOf("o")!==-1){c.push("overline")}if(c.length){u+="text-decoration:"+c.join(" ")+";"}if(t.indexOf("i")!==-1){u+="font-style:italic;"}if(e.terminal.valid_color(r)){u+="color:"+r+";";if(t.indexOf("g")!==-1){u+="text-shadow:0 0 5px "+r+";"}}if(e.terminal.valid_color(a)){u+="background-color:"+a}var p;if(l===""){p=f}else{p=l.replace(/&#93;/g,"]").replace(/>/g,"&gt;").replace(/</g,"&lt;")}var m=V(f);if(m){f=Q(f);u+=m}var h;if(t.indexOf("!")!==-1){if(p.match(I)){h='<a href="mailto:'+p+'"'}else{h='<a target="_blank" href="'+p+'"';if(o.linksNoReferrer){h+=' rel="noreferrer noopener"'}else{h+=' rel="noopener"'}}h+=' tabindex="1000"'}else{h="<span"}if(u!==""){h+=' style="'+u+'"'}if(s!==""){h+=' class="'+s+'"'}if(t.indexOf("!")!==-1){h+=">"+f+"</a>"}else{h+=' data-text="'+p.replace(/"/g,"&quote;")+'">'+f+"</span>"}return h})}else{n=i(n);var t=V(n);if(t.length){n=Q(n);return'<span style="'+t+'">'+n+"</span>"}else{return"<span>"+n+"</span>"}}}).join("");return t.replace(/<span><br\s*\/?><\/span>/gi,"<br/>")}else{return""}},escape_brackets:function e(n){return n.replace(/\[/g,"&#91;").replace(/\]/g,"&#93;")},length:function(e){return G(e).length},columns:function(e,n,t){var r=e.map(function(e){return e.length});var i=Math.max.apply(null,r)+t;if(typeof t==="undefined"){t=4}var o=Math.floor(n/i);var a=[];var s;function l(n){var t=new Array(i-e[n].length).join(" ");s.push(e[n]+(n%o===0?"":t))}if(o<2){return e.join("\n")}for(var f=0;f<e.length;++f){if(f%o===0){if(s){l(f);a.push(s.join(""))}s=[]}else{l(f)}}return a.join("\n")},strip:function e(n){n=n.replace(S,"$6");return n.replace(/(\\?)([[\]])/g,function(e,n){if(n){return e}else{return""}})},active:function e(){return ke.front()},last_id:function e(){var n=ke.length();if(n){return n-1}},parse_argument:function e(n,t){function r(e){if(e.match(/^['"]/)){if(e==='""'||e==="''"){return""}var n=e[0];var t=new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)"+n,"g");e=e.replace(t,"$1")}return JSON.parse('"'+e+'"')}if(t===false){if(n[0]==="'"&&n[n.length-1]==="'"){return n.replace(/^'|'$/g,"")}else if(n[0]==='"'&&n[n.length-1]==='"'){return n.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1")}else if(n.match(/\/.*\/[gimy]*$/)){return n}else if(n.match(/['"]]/)){return r(n)}else{return n.replace(/\\ /g," ")}}var i=n.match(W);if(i){return new RegExp(i[1],i[2])}else if(n.match(/['"]/)){return r(n)}else if(n.match(/^-?[0-9]+$/)){return parseInt(n,10)}else if(n.match(B)){return parseFloat(n)}else{return n.replace(/\\(['"() ])/g,"$1")}},parse_arguments:function n(t){return e.map(t.match(P)||[],e.terminal.parse_argument)},split_arguments:function(n){return e.map(n.match(P)||[],function(n){return e.terminal.parse_argument(n,false)})},parse_command:function n(t){return ae(t,e.terminal.parse_argument)},split_command:function(n){return ae(n,function(n){return e.terminal.parse_argument(n,false)})},extended_command:function e(n,t){try{Ce=false;n.exec(t,true).done(function(){Ce=true})}catch(e){}},formatter:new function(){try{this[Symbol.split]=function(n){return e.terminal.format_split(n)};this[Symbol.match]=function(e){return e.match(A)};this[Symbol.replace]=function(e,n){return e.replace(S,n)};this[Symbol.search]=function(e){return e.search(A)}}catch(e){}}};e.fn.visible=function(){return this.css("visibility","visible")};e.fn.hidden=function(){return this.css("visibility","hidden")};function se(){if(!("KeyboardEvent"in window&&"key"in window.KeyboardEvent.prototype)){return false}var e=window.KeyboardEvent.prototype;var n=Object.getOwnPropertyDescriptor(e,"key").get;return n.toString().match(/\[native code\]/)}function le(e){e="[jQuery Terminal] "+e;if(console&&console.warn){console.warn(e)}else{setTimeout(function(){throw new Error("WARN: "+e)},0)}}var fe={};e.jrpc=function(n,t,r,i,o){var a;if(e.isPlainObject(n)){a=n}else{a={url:n,method:t,params:r,success:i,error:o}}function s(n){return e.isNumeric(n.id)&&(typeof n.result!=="undefined"||typeof n.error!=="undefined")}fe[a.url]=fe[a.url]||0;var l={jsonrpc:"2.0",method:a.method,params:a.params,id:++fe[a.url]};return e.ajax({url:a.url,beforeSend:function n(t,r){if(e.isFunction(a.request)){a.request(t,l)}r.data=JSON.stringify(l)},success:function n(t,r,i){var o=i.getResponseHeader("Content-Type");if(!o.match(/(application|text)\/json/)){le("Response Content-Type is neither application/json"+" nor text/json")}var l;try{l=JSON.parse(t)}catch(e){if(a.error){a.error(i,"Invalid JSON",e)}else{throw new Error("Invalid JSON")}return}if(e.isFunction(a.response)){a.response(i,l)}if(s(l)||a.method==="system.describe"){a.success(l,r,i)}else if(a.error){a.error(i,"Invalid JSON-RPC")}else{throw new Error("Invalid JSON-RPC")}},error:a.error,contentType:"application/json",dataType:"text",async:true,cache:false,type:"POST"})};function ue(n){var t=e('<div class="terminal temp"><div class="cmd"><span cla'+'ss="prompt">&nbsp;</span></div></div>').appendTo("body");t.addClass(n.attr("class"));if(n){var r=n.attr("style");if(r){r=r.split(/\s*;\s*/).filter(function(e){return!e.match(/display\s*:\s*none/i)}).join(";");t.attr("style",r)}}var i=t.find("span")[0].getBoundingClientRect();var o={width:i.width,height:i.height};t.remove();return o}function ce(e,n){var t=e.find(".terminal-fill").width();var r=Math.floor(t/n.width);return r||1e3}function pe(e,n){return Math.floor(e.find(".terminal-fill").height()/n.height)}function me(e,n){var t=e.filter(function(e){return e[n]()===e});return t.length===e.length}function he(e){var n=e.split("");if(me(n,"toLowerCase")){return"lower"}else if(me(n,"toUpperCase")){return"upper"}else{return"mixed"}}function de(e){return he(e)!=="mixed"}var ge=!e.terminal.version.match(/^\{\{/);var ve="Copyright (c) 2011-2018 Jakub Jankiewicz <http://jcubic"+".pl/me>";var ye=ge?" v. "+e.terminal.version:" ";var be=new RegExp(" {"+ye.length+"}$");var we="jQuery Terminal Emulator"+(ge?ye:"");var _e=[["jQuery Terminal","(c) 2011-2018 jcubic"],[we,ve.replace(/^Copyright | *<.*>/g,"")],[we,ve.replace(/^Copyright /,"")],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/_/_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(be," ")+ye,ve],[" __ _____ ________ "+" __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ "+" / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ "+"\\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // "+"/ /__","\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\"+"__\\_\\___/",(" \\/ /____/ "+" ").replace(be,"")+ye,ve]];e.terminal.nested_formatting.__meta__=true;e.terminal.defaults={prompt:"> ",history:true,exit:true,clear:true,enabled:true,maskChar:"*",wrap:true,checkArity:true,raw:false,exceptionHandler:null,pauseEvents:true,softPause:false,memory:false,cancelableAjax:true,processArguments:true,linksNoReferrer:false,processRPCResponse:null,completionEscape:true,convertLinks:true,extra:{},tabs:4,historySize:60,historyState:false,importHistory:false,historyFilter:null,echoCommand:true,scrollOnEcho:true,login:null,outputLimit:-1,formatters:[e.terminal.nested_formatting],onAjaxError:null,pasteImage:true,scrollBottomOffset:20,wordAutocomplete:true,caseSensitiveAutocomplete:true,caseSensitiveSearch:true,clickTimeout:200,request:e.noop,response:e.noop,describe:"procs",onRPCError:null,completion:false,onInit:e.noop,onClear:e.noop,onBlur:e.noop,onFocus:e.noop,onTerminalChange:e.noop,onExit:e.noop,onPush:e.noop,onPop:e.noop,keypress:e.noop,keydown:e.noop,onAfterRedraw:e.noop,onEchoCommand:e.noop,onFlush:e.noop,strings:{comletionParameters:"From version 1.0.0 completion function need to"+" have two arguments",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 describe == false "+"or rpc without system.describe",oneInterpreterFunction:"You can't use more than one function (rpc "+"without system.describe or with option describe == false count"+"s 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",notAString:"%s function: argument is not a string",redrawError:"Internal error, wrong position in cmd redraw",invalidStrings:"Command %s have unclosed strings"}};var xe=[];var ke=new _;var Te=[];var Ee;var Ce=false;var Re=true;var Se=true;e.fn.terminal=function(r,o){function a(n){if(n){this.storage={}}this.set=function(t,r){if(n){this.storage[t]=r}else{e.Storage.set(t,r)}};this.get=function(t){if(n){return this.storage[t]}else{return e.Storage.get(t)}};this.remove=function(t){if(n){delete this.storage[t]}else{e.Storage.remove(t)}}}function s(n){if(e.terminal.unclosed_strings(n)){var t=e.terminal.escape_brackets(n);throw new Error(sprintf(me().invalidStrings,"`"+t+"`"))}else if(e.isFunction(Ue.processArguments)){return ae(n,Ue.processArguments)}else if(Ue.processArguments){return e.terminal.parse_command(n)}else{return e.terminal.split_command(n)}}function l(n){if(typeof n==="string"){ge.echo(n)}else if(n instanceof Array){ge.echo(e.map(n,function(e){return JSON.stringify(e)}).join(" "))}else if(typeof n==="object"){ge.echo(JSON.stringify(n))}else{ge.echo(n)}}function f(n){var t=/(.*):([0-9]+):([0-9]+)$/;var r=n.match(t);if(r){ge.pause(Ue.softPause);e.get(r[1],function(n){var t=location.href.replace(/[^/]+$/,"");var i=r[1].replace(t,"");ge.echo("[[b;white;]"+i+"]");var o=n.split("\n");var a=+r[2]-1;ge.echo(o.slice(a-2,a+3).map(function(n,t){if(t===2){n="[[;#f00;]"+e.terminal.escape_brackets(n)+"]"}return"["+(a+t)+"]: "+n}).join("\n")).resume()},"text")}}function u(n){if(e.isFunction(Ue.onRPCError)){Ue.onRPCError.call(ge,n)}else{ge.error("&#91;RPC&#93; "+n.message);if(n.error&&n.error.message){n=n.error;var t="\t"+n.message;if(n.file){t+=' in file "'+n.file.replace(/.*\//,"")+'"'}if(n.at){t+=" at line "+n.at}ge.error(t)}}}function c(n,t){var r=function(t,r){ge.pause(Ue.softPause);e.jrpc({url:n,method:t,params:r,request:function(e,n){try{Ue.request.call(ge,e,n,ge)}catch(e){_(e,"USER")}},response:function(e,n){try{Ue.response.call(ge,e,n,ge)}catch(e){_(e,"USER")}},success:function n(t){if(t.error){u(t.error)}else if(e.isFunction(Ue.processRPCResponse)){Ue.processRPCResponse.call(ge,t.result,ge)}else{l(t.result)}ge.resume()},error:m})};return function(e,n){if(e===""){return}try{e=s(e)}catch(e){_(e,"TERMINAL (get_processed_command)");return}if(!t||e.name==="help"){r(e.name,e.args)}else{var i=n.token();if(i){r(e.name,[i].concat(e.args))}else{n.error("&#91;AUTH&#93; "+me().noTokenError)}}}}function p(t,r,i,o){return function(a,l){if(a===""){return}var f;try{f=s(a)}catch(n){if(e.isFunction(Ue.exception)){Ue.exception(n,ge)}else{ge.error(n.toString())}return}var u=t[f.name];var c=e.type(u);if(c==="function"){if(r&&u.length!==f.args.length){ge.error("&#91;Arity&#93; "+sprintf(me().wrongArity,f.name,u.length,f.args.length))}else{return u.apply(ge,f.args)}}else if(c==="object"||c==="string"){var m=[];if(c==="object"){m=Object.keys(u);u=p(u,r,i)}l.push(u,{prompt:f.name+"> ",name:f.name,completion:c==="object"?m:n})}else if(e.isFunction(o)){o(a,ge)}else if(e.isFunction(Ue.onCommandNotFound)){Ue.onCommandNotFound.call(ge,a,ge)}else{l.error(sprintf(me().commandNotFound,f.name))}}}function m(n,t,r){ge.resume();if(e.isFunction(Ue.onAjaxError)){Ue.onAjaxError.call(ge,n,t,r)}else if(t!=="abort"){ge.error("&#91;AJAX&#93; "+t+" - "+me().serverResponse+":\n"+e.terminal.escape_brackets(n.responseText))}}function h(n,t,r){function i(n){if(n.error){u(n.error)}else if(e.isFunction(Ue.processRPCResponse)){Ue.processRPCResponse.call(ge,n.result,ge)}else{l(n.result)}ge.resume()}function o(e,n){try{Ue.request.call(ge,e,n,ge)}catch(e){_(e,"USER")}}function a(e,n){try{Ue.response.call(ge,e,n,ge)}catch(e){_(e,"USER")}}function s(s){var l=s;if(Ue.describe!==""){Ue.describe.split(".").forEach(function(e){l=l[e]})}if(l&&l.length){var f={};e.each(l,function(r,s){if(e.isPlainObject(s)&&typeof s.name==="string"){f[s.name]=function(){var r=t&&s.name!=="help";var l=Array.prototype.slice.call(arguments);var f=l.length+(r?1:0);if(Ue.checkArity&&s.params&&s.params.length!==f){ge.error("&#91;Arity&#93; "+sprintf(me().wrongArity,s.name,s.params.length,f))}else{ge.pause(Ue.softPause);if(r){var u=ge.token(true);if(u){l=[u].concat(l)}else{ge.error("&#91;AUTH&#93; "+me().noTokenError)}}e.jrpc({url:n,method:s.name,params:l,request:o,response:a,success:i,error:m})}}}});var u=typeof t==="string"?t:"login";f.help=f.help||function(n){if(typeof n==="undefined"){var r=s.procs.map(function(e){return e.name}).join(", ")+", help";ge.echo("Available commands: "+r)}else{var i=false;e.each(l,function(e,r){if(r.name===n){i=true;var o="";o+="[[bu;;]"+r.name+"]";if(r.params){var a=r.params;if(t&&r.name!==u){a=a.slice(1)}o+=" "+a.join(" ")}if(r.help){o+="\n"+r.help}ge.echo(o);return false}});if(!i){if(n==="help"){ge.echo("[[bu;;]help] [method]\ndisplay help "+"for the method or list of methods if not"+" specified")}else{var o="Method `"+n+"' not found ";ge.error(o)}}}};r(f)}else{r(null)}}return e.jrpc({url:n,method:"system.describe",params:[],success:s,request:o,response:a,error:function e(){r(null)}})}function d(n,t,r){r=r||e.noop;var i=e.type(n);var o;var a={};var s=0;var l;if(i==="array"){o={};(function n(r,i){if(r.length){var a=r[0];var f=r.slice(1);var u=e.type(a);if(u==="string"){ge.pause(Ue.softPause);if(Ue.describe===false){if(++s===1){l=c(a,t)}else{ge.error(me().oneRPCWithIgnore)}n(f,i)}else{h(a,t,function(r){if(r){e.extend(o,r)}else if(++s===1){l=c(a,t)}else{ge.error(me().oneRPCWithIgnore)}ge.resume();n(f,i)})}}else if(u==="function"){if(l){ge.error(me().oneInterpreterFunction)}else{l=a}n(f,i)}else if(u==="object"){e.extend(o,a);n(f,i)}}else{i()}})(n,function(){r({interpreter:p(o,false,t,l.bind(ge)),completion:Object.keys(o)})})}else if(i==="string"){if(Ue.ignoreSystemDescribe){o={interpreter:c(n,t)};if(e.isArray(Ue.completion)){o.completion=Ue.completion}r(o)}else{ge.pause(Ue.softPause);h(n,t,function(e){if(e){a.interpreter=p(e,false,t);a.completion=Object.keys(e)}else{a.interpreter=c(n,t)}r(a);ge.resume()})}}else if(i==="object"){r({interpreter:p(n,Ue.checkArity),completion:Object.keys(n)})}else{if(i==="undefined"){n=e.noop}else if(i!=="function"){throw new Error(i+" is invalid interpreter value")}r({interpreter:n,completion:Ue.completion})}}function v(n,t){var r=e.type(t)==="boolean"?"login":t;return function(t,i,o){ge.pause(Ue.softPause);e.jrpc({url:n,method:r,params:[t,i],request:function(e,n){try{Ue.request.call(ge,e,n,ge)}catch(e){_(e,"USER")}},response:function(e,n){try{Ue.response.call(ge,e,n,ge)}catch(e){_(e,"USER")}},success:function e(n){if(!n.error&&n.result){o(n.result)}else{o(null)}ge.resume()},error:m})}}function _(n,t,r){if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,n,t)}else{ge.exception(n,t);if(!r){setTimeout(function(){throw n},0)}}}function k(){var e;if(ve.prop){e=ve.prop("scrollHeight")}else{e=ve.attr("scrollHeight")}ve.scrollTop(e)}function T(n,t){try{if(e.isFunction(t)){t.call(ge,e.noop,ge)}else if(typeof t!=="string"){var r=n+" must be string or function";throw r}}catch(e){_(e,n.toUpperCase());return false}return true}var E=[];var C=1;function R(t,r,i){var o,a;E.push(C);if(t===""){}else if(!i.raw){if((J(t)>je||t.match(/\n/))&&(Ue.wrap===true&&i.wrap===n||Ue.wrap===false&&i.wrap===true)){var s=i.keepWords;var l=e.terminal.split_equal(t,je,s);for(o=0,a=l.length;o<a;++o){if(l[o]===""||l[o]==="\r"){E.push("<span></span>")}else{E.push(e.terminal.format(l[o],{linksNoReferrer:Ue.linksNoReferrer}))}}}else{t=e.terminal.normalize(t);t=e.terminal.format(t,{linksNoReferrer:Ue.linksNoReferrer});t.split(/\n/).forEach(function(e){E.push(e)})}}else{E.push(t)}E.push({finalize:i.finalize,index:r})}function S(n){try{var t=e.extend({exec:true,raw:false,finalize:e.noop},n.options||{});var r;var i=n.string;var o=e.type(i)==="function";if(o){i=i()}if(e.type(i)!=="string"){if(e.isFunction(Ue.parseObject)){var a=Ue.parseObject(i);if(e.type(a)==="string"){r=a}}else if(i instanceof Array){r=e.terminal.columns(i,ge.cols(),Ue.tabs)}else{r=String(i)}}else{r=i}if(r!==""){r=e.map(r.split(H),function(n){if(n&&n.match(H)&&!e.terminal.is_formatting(n)){n=n.replace(/^\[\[|\]\]$/g,"");if(t.exec){if(ye&&ye.command===n){ge.error(me().recursiveCall)}else{e.terminal.extended_command(ge,n)}}return""}else{return n}}).join("");if(r!==""){if(!t.raw){if(Ue.convertLinks){r=r.replace(I,"[[!;;]$1]").replace(z,"[[!;;]$1]")}if(t.formatters){try{r=e.terminal.apply_formatters(r,Ue)}catch(e){_(e,"FORMATTING")}}r=e.terminal.encode(r)}R(r,n.index,t)}}if(r===""&&o){R(r,n.index,t)}}catch(n){E=[];if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,n,"TERMINAL")}else{y("[Internal Exception(process_line)]",n)}}}function A(n){n=e.extend({},{update:false,scroll:true},n||{});if(!n.update){Qe.resize(je);var t=Ae.empty().detach()}var r=[];if(Ue.outputLimit>=0){var i;if(Ue.outputLimit===0){i=ge.rows()}else{i=Ue.outputLimit}we.forEach(function(n,t){var i=n[0];var o=n[1];if(e.type(i)==="function"){i=i()}if(e.type(i)!=="string"){i=String(i)}r.push({string:i,index:t,options:o})});r=r.slice(r.length-i-1)}else{r=we.map(function(e,n){return{string:e[0],index:n,options:e[1]}})}try{E=[];e.each(r,function(e,n){S(n)});if(!n.update){Qe.before(t)}ge.flush(n);try{Ue.onAfterRedraw.call(ge)}catch(n){Ue.onAfterRedraw=e.noop;_(n,"onAfterRedraw")}}catch(n){if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,n,"TERMINAL (redraw)")}else{y("[redraw]",n)}}}function F(){if(Ue.outputLimit>=0){var n;if(Ue.outputLimit===0){n=ge.rows()}else{n=Ue.outputLimit}var t=Ae.find("> div > div");if(t.length+1>n){var r=t.length-n+1;var i=t.slice(0,r);var o=i.parent();i.remove();o.each(function(){var n=e(this);if(n.is(":empty")){n.remove()}})}}}function j(){if(Ue.greetings===n){ge.echo(ge.signature,{finalize:g,formatters:false})}else if(Ue.greetings){var e=typeof Ue.greetings;if(e==="string"){ge.echo(Ue.greetings)}else if(e==="function"){try{Ue.greetings.call(ge,ge.echo)}catch(e){Ue.greetings=null;_(e,"greetings")}}else{ge.error(me().wrongGreetings)}}}function L(n){if(typeof n==="undefined"){n=ge.get_command()}var t=Qe.prompt();var r=Qe.mask();switch(typeof r){case"string":n=n.replace(/./g,r);break;case"boolean":if(r){n=n.replace(/./g,Ue.maskChar)}else{n=e.terminal.escape_formatting(n)}break}var i={finalize:function t(r){g(r.addClass("command"));try{Ue.onEchoCommand.call(ge,r,n)}catch(n){Ue.onEchoCommand=e.noop;ge.exception(n)}}};if(e.isFunction(t)){var o=t(function(e){ge.echo(e+n,i)});if(o&&o.then){o.then(function(e){if(typeof e==="string"){ge.echo(e+n,i)}})}}else{ge.echo(t+n,i)}}function P(){if(ge.is("body")){return window.innerWidth-document.documentElement.clientWidth>0}return on.outerWidth()!==ge.outerWidth()}function $(e){var n=ke.get()[e[0]];if(!n){throw new Error(me().invalidTerminalId)}var t=e[1];if(Te[t]){n.import_view(Te[t])}else{Ce=false;var r=e[2];if(r){n.exec(r).done(function(){Ce=true;Te[t]=n.export_view()})}}}function N(){if(Ce){Re=false;location.hash="#"+JSON.stringify(Ee);setTimeout(function(){Re=true},100)}}var D=true;var B=[];function W(t,r,i){if(D){D=false;if(Ue.historyState||Ue.execHash&&i){if(!Te.length){ge.save_state()}else{ge.save_state(null)}}}function o(){if(!i){Ce=true;if(Ue.historyState){ge.save_state(t,false)}Ce=u}f.resolve();if(e.isFunction(Ue.onAfterCommand)){Ue.onAfterCommand.call(ge,ge,t)}}function a(e){if(typeof e!=="undefined"){l(e)}o();ge.resume()}try{if(e.isFunction(Ue.onBeforeCommand)){if(Ue.onBeforeCommand.call(ge,ge,t)===false){return}}if(!i){ye=e.terminal.split_command(t)}if(!V()){if(i&&(e.isFunction(Ue.historyFilter)&&Ue.historyFilter(t)||t.match(Ue.historyFilter))){Qe.history().append(t)}}var s=Ve.top();if(!r&&Ue.echoCommand){L(t)}var f=new e.Deferred;var u=Ce;if(t.match(/^\s*login\s*$/)&&ge.token(true)){if(ge.level()>1){ge.logout(true)}else{ge.logout()}o()}else if(Ue.exit&&t.match(/^\s*exit\s*$/)&&!He){var c=ge.level();if(c===1&&ge.get_token()||c>1){if(ge.get_token(true)){ge.set_token(n,true)}ge.pop()}o()}else if(Ue.clear&&t.match(/^\s*clear\s*$/)&&!He){ge.clear();o()}else{var p=s.interpreter.call(ge,t,ge);if(p){ge.pause(Ue.softPause);if(p.then){p.then(a)}else{return e.when(p).done(a)}}else if(Ge){B.push(function(){o()})}else{o()}}return f.promise()}catch(e){_(e,"USER");ge.resume()}}function M(){if(e.isFunction(Ue.onBeforeLogout)){try{if(Ue.onBeforeLogout.call(ge,ge)===false){return}}catch(e){_(e,"onBeforeLogout")}}q();if(e.isFunction(Ue.onAfterLogout)){try{Ue.onAfterLogout.call(ge,ge)}catch(e){_(e,"onAfterlogout")}}ge.login(fn,true,X)}function q(){var e=ge.prefix_name(true)+"_";Ke.remove(e+"token");Ke.remove(e+"login")}function U(n){var t=ge.prefix_name()+"_interpreters";var r=Ke.get(t);if(r){r=JSON.parse(r)}else{r=[]}if(e.inArray(n,r)===-1){r.push(n);Ke.set(t,JSON.stringify(r))}}function Y(n){var t=Ve.top();var r=ge.prefix_name(true);if(!V()){U(r)}Qe.name(r);if(e.isFunction(t.prompt)){Qe.prompt(function(e){var n=t.prompt.call(ge,e,ge);if(n&&n.then){n.then(function(n){if(typeof n==="string"){e(n)}})}})}else{Qe.prompt(t.prompt)}if(e.isPlainObject(t.keymap)){Qe.keymap(e.omap(t.keymap,function(e,n){return function(){var e=[].slice.call(arguments);try{return n.apply(ge,e)}catch(e){_(e,"USER KEYMAP")}}}))}Qe.set("");Pe.resolve();if(!n&&e.isFunction(t.onStart)){t.onStart.call(ge,ge)}}function G(){if(Re&&Ue.execHash){try{if(location.hash){var e=location.hash.replace(/^#/,"");Ee=JSON.parse(decodeURIComponent(e))}else{Ee=[]}if(Ee.length){$(Ee[Ee.length-1])}else if(Te[0]){ge.import_view(Te[0])}}catch(e){_(e,"TERMINAL")}}}function X(){Y();j();if(we.length){ge.refresh()}var n=false;if(e.isFunction(Ue.onInit)){Be=function(){n=true};try{Ue.onInit.call(ge,ge)}catch(e){_(e,"OnInit")}finally{Be=e.noop;if(!n&&ge.enabled()){ge.resume()}}}if(Se){Se=false;e(window).on("hashchange",G)}}function V(){return He||Qe.mask()!==false}function Q(e,n,t){if(!n.length){return""}var r=he(e);var i=[];for(var o=e.length;o<n[0].length;++o){var a=false;var s=n[0].charAt(o),l=s.toLowerCase();for(var f=1;f<n.length;++f){a=true;var u=n[f].charAt(o),c=u.toLowerCase();if(s!==u){if(t||r==="mixed"){a=false;break}else if(l===c){if(r==="lower"){s=s.toLowerCase()}else if(r==="upper"){s=s.toUpperCase()}else{a=false;break}}else{a=false;break}}}if(a){i.push(s)}else{break}}return e+i.join("")}function ne(e){ke.forEach(function(n){n.settings().onTerminalChange.call(n,e)})}function oe(t){var r,i=Ve.top();if(e.isFunction(i.keydown)){r=i.keydown.call(ge,t,ge);if(r!==n){return r}}else if(e.isFunction(Ue.keydown)){r=Ue.keydown.call(ge,t,ge);if(r!==n){return r}}}var se={"CTRL+D":function(n,t){if(!He){if(Qe.get()===""){if(Ve.size()>1||e.isFunction(fn)){ge.pop("")}else{ge.resume();ge.echo("")}}else{t()}}return false},"CTRL+C":function(){if(ee()===""){L(ge.get_command()+"^C");ge.set_command("")}},"CTRL+L":function(){ge.clear()},TAB:function(t,r){var i=Ve.top(),o,a;if(typeof i.caseSensitiveAutocomplete!=="undefined"){a=i.caseSensitiveAutocomplete}else{a=Ue.caseSensitiveAutocomplete}if(Ue.completion&&e.type(Ue.completion)!=="boolean"&&i.completion===n){o=Ue.completion}else{o=i.completion}if(o==="settings"){o=Ue.completion}if(o){switch(e.type(o)){case"function":var s=ge.before_cursor(Ue.wordAutocomplete);if(o.length===3){var l=new Error(me().comletionParameters);_(l,"USER");return false}o.call(ge,s,function(e){ge.complete(e,{echo:true,word:Ue.wordAutocomplete,escape:Ue.completionEscape,caseSensitive:a})});break;case"array":ge.complete(o,{echo:true,word:Ue.wordAutocomplete,escape:Ue.completionEscape,caseSensitive:a});break;default:throw new Error(me().invalidCompletion)}}else{r()}return false},"CTRL+V":function(e,n){n(e);ge.oneTime(200,function(){k()});return true},"CTRL+TAB":function(){if(ke.length()>1){ge.focus(false);return false}},PAGEDOWN:function(){ge.scroll(ge.height())},PAGEUP:function(){ge.scroll(-ge.height())}};function le(t){var r,i;if(ge.enabled()){if(!ge.paused()){r=oe(t);if(r!==n){return r}if(t.which!==9){be=0}ge.attr({scrollTop:ge.attr("scrollHeight")})}else{if(!Ue.pauseEvents){r=oe(t);if(r!==n){return r}}if(t.which===68&&t.ctrlKey){if(Ue.pauseEvents){r=oe(t);if(r!==n){return r}}if(xe.length){for(i=xe.length;i--;){var o=xe[i];if(o.readyState!==4){try{o.abort()}catch(n){if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,t,"AJAX ABORT")}else{ge.error(me().ajaxAbortError)}}}}xe=[]}ge.resume()}return false}}}function fe(e){return function(n){e.add(n)}}function me(){return e.extend({},e.terminal.defaults.strings,Ue&&Ue.strings||{})}var ge=this;if(this.length>1){return this.each(function(){e.fn.terminal.call(e(this),r,e.extend({name:ge.selector},o))})}if(ge.data("terminal")){return ge.data("terminal")}if(ge.length===0){throw new Error(sprintf(me().invalidSelector,ge.selector))}var ve;var ye;var be=0;var we=[];var Ae;var Fe=ke.length();var je;var Le;var Oe;var ze=new x;var Ie=new t;var Pe=new t;var $e=fe(Pe);var Ne=ue(ge);var De=fe(Ie);var He=false;var Be=e.noop;var We,Me;var qe=[];var Ue=e.extend({},e.terminal.defaults,{name:ge.selector},o||{});var Ke=new a(Ue.memory);var Je=Ue.enabled,Ye=false;var Ge=false;var Xe=true;var Ve;var Qe;var Ze;var en;var nn;e.extend(ge,e.omap({id:function(){return Fe},clear:function(){Ae.html("");we=[];try{Ue.onClear.call(ge,ge)}catch(e){_(e,"onClear")}ge.attr({scrollTop:0});return ge},export_view:function(){var n={};if(e.isFunction(Ue.onExport)){try{n=Ue.onExport.call(ge)}catch(e){_(e,"onExport")}}return e.extend({},{focus:Je,mask:Qe.mask(),prompt:ge.get_prompt(),command:ge.get_command(),position:Qe.position(),lines:i(we),interpreters:Ve.clone(),history:Qe.history().data},n)},import_view:function(n){if(He){throw new Error(sprintf(me().notWhileLogin,"import_view"))}if(e.isFunction(Ue.onImport)){try{Ue.onImport.call(ge,n)}catch(n){Ue.onImport=e.noop;_(n,"onImport")}}$e(function e(){ge.set_prompt(n.prompt);ge.set_command(n.command);Qe.position(n.position);Qe.mask(n.mask);if(n.focus){ge.focus()}we=i(n.lines);Ve=n.interpreters;if(Ue.importHistory){Qe.history().set(n.history)}A()});return ge},save_state:function(t,r,i){if(typeof i!=="undefined"){Te[i]=ge.export_view()}else{Te.push(ge.export_view())}if(!e.isArray(Ee)){Ee=[]}if(t!==n&&!r){var o=[Fe,Te.length-1,t];Ee.push(o);N()}},exec:function(n,t,r){var i=r||new e.Deferred;De(function r(){if(e.isArray(n)){(function e(){var r=n.shift();if(r){ge.exec(r,t).done(e)}else{i.resolve()}})()}else if(Ge){qe.push([n,t,i])}else{W(n,t,true).done(function(){i.resolve(ge)})}});return i.promise()},autologin:function(e,n,t){ge.trigger("terminal.autologin",[e,n,t]);return ge},login:function(t,r,i,o){ze.push([].slice.call(arguments));if(He){throw new Error(sprintf(me().notWhileLogin,"login"))}if(!e.isFunction(t)){throw new Error(me().loginIsNotAFunction)}He=true;if(ge.token()&&ge.level()===1&&!Xe){He=false;ge.logout(true)}else if(ge.token(true)&&ge.login_name(true)){He=false;if(e.isFunction(i)){i()}return ge}if(Ue.history){Qe.history().disable()}var a=ge.level();function s(t,s,l){if(s){while(ge.level()>a){ge.pop(n,true)}if(Ue.history){Qe.history().enable()}var f=ge.prefix_name(true)+"_";Ke.set(f+"token",s);Ke.set(f+"login",t);He=false;if(e.isFunction(i)){i()}}else{if(r){if(!l){ge.error(me().wrongPasswordTryAgain)}ge.pop(n,true).set_mask(false)}else{He=false;if(!l){ge.error(me().wrongPassword)}ge.pop(n,true).pop(n,true)}if(e.isFunction(o)){o()}}ge.off("terminal.autologin")}ge.on("terminal.autologin",function(e,n,t,r){s(n,t,r)});ge.push(function(e){ge.set_mask(Ue.maskChar).push(function(n){try{t.call(ge,e,n,function(n,t){s(e,n,t)})}catch(e){_(e,"AUTH")}},{prompt:me().password+": ",name:"password"})},{prompt:me().login+": ",name:"login"});return ge},settings:function(){return Ue},before_cursor:function(e){var n=Qe.position();var t=Qe.get().substring(0,n);var r=t.split(" ");var i;if(e){if(r.length===1){i=r[0]}else{var o=t.match(/(\\?")/g);var a=o?o.filter(function(e){return!e.match(/^\\/)}).length:0;o=t.match(/'/g);var s=o?o.length:0;if(s%2===1){i=t.match(/('[^']*)$/)[0]}else if(a%2===1){i=t.match(/("(?:[^"]|\\")*)$/)[0]}else{i=r[r.length-1];for(sn=r.length-1;sn>0;sn--){var l=r[sn-1];if(l[l.length-1]==="\\"){i=r[sn-1]+" "+i}else{break}}}}}else{i=t}return i},complete:function(n,t){t=e.extend({word:true,echo:false,escape:true,caseSensitive:true},t||{});var r=t.caseSensitive;var i=ge.before_cursor(t.word).replace(/\\"/g,'"');var o=false;if(t.word){if(i.match(/^"/)){o='"'}else if(i.match(/^'/)){o="'"}if(o){i=i.replace(/^["']/,"")}}n=n.slice();if(Ue.clear&&e.inArray("clear",n)===-1){n.push("clear")}if(Ue.exit&&e.inArray("exit",n)===-1){n.push("exit")}if(be%2===0){Oe=ge.before_cursor(t.word)}else{var a=ge.before_cursor(t.word);if(a!==Oe){return}}var s=e.terminal.escape_regex(i);if(t.escape){s=s.replace(/(\\+)(["'() ])/g,function(e,n,t){if(t.match(/[()]/)){return n+"\\?\\"+t}else{return n+"?"+t}})}function l(){var e=[];for(var a=n.length;a--;){if(u.test(n[a])){var s=n[a];if(o==='"'){s=s.replace(/"/g,'\\"')}if(!o&&t.escape){s=s.replace(/(["'() ])/g,"\\$1")}if(!r&&de(s)){if(i.toLowerCase()===i){s=s.toLowerCase()}else if(i.toUpperCase()===i){s=s.toUpperCase()}}e.push(s)}}return e}var f=r?"":"i";var u=new RegExp("^"+s,f);var c=l();function p(e,n){var t=ge.get_command();var r=ge.get_position();var i=new RegExp("^"+e,"i");var a=t.substring(0,r);var s=t.substring(r);var l=n.replace(i,"")+(o||"");ge.set_command(a+l+s);ge.set_position((a+l).length)}if(c.length===1){if(t.escape){p(s,c[0])}else{ge.insert(c[0].replace(u,"")+(o||""))}Oe=ge.before_cursor(t.word);return true}else if(c.length>1){if(++be>=2){be=0;if(t.echo){L();var m=c.reverse().join("\t");ge.echo(e.terminal.escape_brackets(m),{keepWords:true,formatters:false});return true}}else{var h=Q(i,c,r);if(h){p(i,h);Oe=ge.before_cursor(t.word);return true}}}},commands:function(){return Ve.top().interpreter},set_interpreter:function(n,t){function r(){ge.pause(Ue.softPause);d(n,t,function(n){ge.resume();var t=Ve.top();e.extend(t,n);Y(true)})}if(e.type(n)==="string"&&t){ge.login(v(n,t),true,r)}else{r()}return ge},greetings:function(){j();return ge},paused:function(){return Ge},pause:function(n){De(function t(){Be();Ge=true;Qe.disable(n||K);if(!n){Qe.find(".prompt").hidden()}if(e.isFunction(Ue.onPause)){Ue.onPause.call(ge)}});return ge},resume:function(){De(function n(){Ge=false;if(Je&&ke.front()===ge){Qe.enable()}Qe.find(".prompt").visible();var t=qe;qe=[];for(var r=0;r<t.length;++r){ge.exec.apply(ge,t[r])}ge.trigger("resume");var i=B.shift();if(i){i()}k();if(e.isFunction(Ue.onResume)){Ue.onResume.call(ge)}});return ge},cols:function(){if(Ue.numChars){return Ue.numChars}if(typeof je==="undefined"){je=ce(ge,Ne)}return je},rows:function(){if(Ue.numRows){return Ue.numRows}if(typeof Le==="undefined"){Le=pe(ge,Ne)}return Le},history:function(){return Qe.history()},history_state:function(e){function n(){Ue.historyState=true;if(!Te.length){ge.save_state()}else if(ke.length()>1){ge.save_state(null)}}if(e){if(typeof window.setImmediate==="undefined"){setTimeout(n,0)}else{setImmediate(n)}}else{Ue.historyState=false}return ge},clear_history_state:function(){Ee=[];Te=[];return ge},next:function(){if(ke.length()===1){return ge}else{ke.front().disable();var n=ke.rotate().enable();var t=n.offset().top-50;e("html,body").animate({scrollTop:t},500);try{ne(n)}catch(e){_(e,"onTerminalChange")}return n}},focus:function(e,n){De(function t(){if(ke.length()===1){if(e===false){ge.disable(n)}else{ge.enable(n)}}else if(e===false){ge.next()}else{var r=ke.front();if(r!==ge){ke.forEach(function(e){if(e!==ge&&e.enabled()){e.disable(n)}});if(!n){try{ne(ge)}catch(e){_(e,"onTerminalChange")}}}ke.set(ge);ge.enable(n)}});return ge},freeze:function(e){$e(function n(){if(e){ge.disable();Ye=true}else{Ye=false;ge.enable()}})},frozen:function(){return Ye},enable:function(t){if(!Je&&!Ye){if(je===n){ge.resize()}De(function r(){var i;if(!t&&!Je){try{i=Ue.onFocus.call(ge,ge)}catch(n){Ue.onFocus=e.noop;_(n,"onFocus")}}if(!t&&i===n||t){Je=true;if(!ge.paused()){Qe.enable()}}})}return ge},disable:function(t){De(function r(){var i;if(!t&&Je){try{i=Ue.onBlur.call(ge,ge)}catch(n){Ue.onBlur=e.noop;_(n,"onBlur")}}if(!t&&i===n||t){Je=false;Qe.disable()}});return ge},enabled:function(){return Je},signature:function(){var e=ge.cols();for(var n=_e.length;n--;){var t=_e[n].map(function(e){return e.length});if(Math.max.apply(null,t)<=e){return _e[n].join("\n")+"\n"}}return""},version:function(){return e.terminal.version},cmd:function(){return Qe},get_command:function(){return Qe.get()},set_command:function(e,t){$e(function r(){if(typeof e!=="string"){e=JSON.stringify(e)}Qe.set(e,n,t)});return ge},set_position:function(e,n){$e(function t(){Qe.position(e,n)});return ge},get_position:function(){return Qe.position()},insert:function(e,n){if(typeof e==="string"){$e(function t(){var r=ge.is_bottom();Qe.insert(e,n);if(Ue.scrollOnEcho||r){k()}});return ge}else{throw new Error(sprintf(me().notAString,"insert"))}},set_prompt:function(n){$e(function t(){if(T("prompt",n)){if(e.isFunction(n)){Qe.prompt(function(e){n(e,ge)})}else{Qe.prompt(n)}Ve.top().prompt=n}});return ge},get_prompt:function(){return Ve.top().prompt},set_mask:function(e){$e(function n(){Qe.mask(e===true?Ue.maskChar:e)});return ge},get_output:function(n){if(n){return we}else{return e.map(we,function(n){return e.isFunction(n[0])?n[0]():n[0]}).join("\n")}},resize:function(n,t){if(!ge.is(":visible")){ge.stopTime("resize");ge.oneTime(500,"resize",function(){ge.resize(n,t)})}else{if(n&&t){ge.width(n);ge.height(t)}n=ge.width();t=ge.height();if(typeof Ue.numChars!=="undefined"||typeof Ue.numRows!=="undefined"){Qe.resize(Ue.numChars);ge.refresh();return}var r=ce(ge,Ne);var i=pe(ge,Ne);if(r!==je||i!==Le){je=r;Le=i;Qe.resize(je);ge.refresh();var o=Ve.top();if(e.isFunction(o.resize)){o.resize.call(ge,ge)}else if(e.isFunction(Ue.onResize)){Ue.onResize.call(ge,ge)}}}return ge},refresh:function(){if(Ne.width!==0){ge[0].style.setProperty("--char-width",Ne.width)}A({scroll:false,update:true});return ge},flush:function(n){n=e.extend({},{update:false,scroll:true},n||{});try{var t=ge.is_bottom();var r;e.each(E,function(t,i){if(i===C){r=e("<div></div>")}else if(e.isPlainObject(i)&&e.isFunction(i.finalize)){if(n.update){var o="> div[data-index="+i.index+"]";var a=Ae.find(o);if(a.html()!==r.html()){a.replaceWith(r)}}else{r.appendTo(Ae)}i.finalize(r.attr("data-index",i.index))}else{e("<div/>").html(i).appendTo(r).width("100%")}});F();try{Ue.onFlush.call(ge,ge)}catch(n){Ue.onFlush=e.noop;_(n,"onFlush")}if(Ue.scrollOnEcho&&n.scroll||t){k()}E=[]}catch(n){if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,n,"TERMINAL (Flush)")}else{y("[Flush]",n)}}return ge},update:function(e,n,t){$e(function r(){if(e<0){e=we.length+e}if(!we[e]){ge.error("Invalid line number "+e)}else if(n===null){we.splice(e,1);Ae.find("[data-index="+e+"]").remove()}else{we[e][0]=n;if(t){we[e][1]=t}S({string:n,index:e,options:t});ge.flush({scroll:false,update:true})}});return ge},remove:function(e,n){return ge.update(e,null,n)},last_index:function(){return we.length-1},echo:function(t,r){function i(n){try{var t=e.extend({flush:true,raw:Ue.raw,finalize:e.noop,keepWords:false,formatters:true},r||{});(function(n){t.finalize=function(r){if(t.raw){r.addClass("raw")}try{if(e.isFunction(n)){n(r)}}catch(e){_(e,"USER:echo(finalize)");n=null}}})(t.finalize);if(t.flush){if(E.length){ge.flush()}E=[]}if(typeof n==="function"){n=n.bind(ge)}S({string:n,options:t,index:we.length});we.push([n,e.extend(t,{exec:false})]);if(t.flush){ge.flush()}}catch(n){if(e.isFunction(Ue.exceptionHandler)){Ue.exceptionHandler.call(ge,n,"TERMINAL (echo)")}else{y("[Terminal.echo]",n)}}}if(t!==n&&e.isFunction(t.then)){e.when(t).done(i)}else{i(t)}return ge},error:function(n,t){t=e.extend({},t,{raw:false,formatters:false});function r(n){if(typeof n!=="string"){n=String(n)}var t=e.terminal.escape_brackets(n).replace(/\\$/,"&#92;").replace(O,"]$1[[;;;error]");return"[[;;;error]"+t+"]"}if(typeof n==="function"){return ge.echo(function(){return r(n.call(ge))},t)}return ge.echo(r(n),t)},exception:function(n,t){var r=w(n);if(t){r="&#91;"+t+"&#93;: "+r}if(r){ge.error(r,{finalize:function(e){e.addClass("exception message")},keepWords:true})}if(typeof n.fileName==="string"){ge.pause(Ue.softPause);e.get(n.fileName,function(e){var t=n.lineNumber-1;var r=e.split("\n")[t];if(r){ge.error("["+n.lineNumber+"]: "+r)}ge.resume()},"text")}if(n.stack){var i=e.terminal.escape_brackets(n.stack);ge.echo(i.split(/\n/g).map(function(e){return"[[;;;error]"+e.replace(O,function(e){return"]"+e+"[[;;;error]"})+"]"}).join("\n"),{finalize:function(e){e.addClass("exception stack-trace")},formatters:false})}},scroll:function(e){var n;e=Math.round(e);if(ve.prop){if(e>ve.prop("scrollTop")&&e>0){ve.prop("scrollTop",0)}n=ve.prop("scrollTop");ve.scrollTop(n+e)}else{if(e>ve.attr("scrollTop")&&e>0){ve.attr("scrollTop",0)}n=ve.attr("scrollTop");ve.scrollTop(n+e)}return ge},logout:function(e){if(He){throw new Error(sprintf(me().notWhileLogin,"logout"))}$e(function t(){if(e){var r=ze.pop();ge.set_token(n,true);ge.login.apply(ge,r)}else if(Ve.size()===1&&ge.token()){ge.logout(true)}else{while(Ve.size()>1){if(ge.token()){ge.logout(true).pop().pop()}else{ge.pop()}}}});return ge},token:function(e){return Ke.get(ge.prefix_name(e)+"_token")},set_token:function(e,n){var t=ge.prefix_name(n)+"_token";if(typeof e==="undefined"){Ke.remove(t,e)}else{Ke.set(t,e)}return ge},get_token:function(e){return ge.token(e)},login_name:function(e){return Ke.get(ge.prefix_name(e)+"_login")},name:function(){return Ve.top().name},prefix_name:function(e){var n=(Ue.name?Ue.name+"_":"")+Fe;if(e&&Ve.size()>1){var t=Ve.map(function(e){return e.name||""}).slice(1).join("_");if(t){n+="_"+t}}return n},read:function(n,t){var r=new e.Deferred;ge.push(function(n){ge.pop();if(e.isFunction(t)){t(n)}r.resolve(n)},{prompt:n});return r.promise()},push:function(t,r){De(function i(){r=r||{};var o={infiniteLogin:false};var a=e.extend({},o,r);if(!a.name&&ye){a.name=ye.name}if(a.prompt===n){a.prompt=(a.name||">")+" "}var s=Ve.top();if(s){s.mask=Qe.mask()}var l=Ge;function f(){Ue.onPush.call(ge,s,Ve.top(),ge);Y()}d(t,r.login,function(n){Ve.push(e.extend({},n,a));if(a.completion===true){if(e.isArray(n.completion)){Ve.top().completion=n.completion}else if(!n.completion){Ve.top().completion=false}}if(a.login){var r;var i=e.type(a.login);if(i==="function"){r=a.infiniteLogin?e.noop:ge.pop;ge.login(a.login,a.infiniteLogin,f,r)}else if(e.type(t)==="string"&&i==="string"||i==="boolean"){r=a.infiniteLogin?e.noop:ge.pop;ge.login(v(t,a.login),a.infiniteLogin,f,r)}}else{f()}if(!l&&ge.enabled()){ge.resume()}})});return ge},pop:function(t,r){if(t!==n){L(t)}var i=ge.token(true);var o;if(Ve.size()===1){o=Ve.top();if(Ue.login){if(!r){Ue.onPop.call(ge,o,null,ge)}M();if(e.isFunction(Ue.onExit)){try{Ue.onExit.call(ge,ge)}catch(n){Ue.onExit=e.noop;_(n,"onExit")}}}else{ge.error(me().canExitError)}}else{if(i){q()}var a=Ve.pop();o=Ve.top();Y();if(!r){Ue.onPop.call(ge,a,o)}if(He&&ge.get_prompt()!==me().login+": "){He=false}if(e.isFunction(a.onExit)){try{a.onExit.call(ge,ge)}catch(n){a.onExit=e.noop;_(n,"onExit")}}ge.set_mask(o.mask)}return ge},option:function(n,t){if(typeof t==="undefined"){if(typeof n==="string"){return Ue[n]}else if(typeof n==="object"){e.each(n,function(e,n){Ue[e]=n})}}else{Ue[n]=t;if(n.match(/^num(Chars|Rows)$/)){A()}}return ge},keymap:function(n,t){if(arguments.length===0){return Qe.keymap()}if(typeof t==="undefined"){if(typeof n==="string"){return Qe.keymap(n)}else if(e.isPlainObject(n)){n=e.omap(n||{},function(e,n){if(!mn[e]){return n.bind(ge)}return function(t,r){return n.call(ge,t,function(){return mn[e](t,r)})}});Qe.keymap(n)}}else if(typeof t==="function"){var r=n;if(!mn[r]){Qe.keymap(r,t.bind(ge))}else{Qe.keymap(r,function(e,n){return t.call(ge,e,function(){return mn[r](e,n)})})}}},level:function(){return Ve.size()},reset:function(){$e(function e(){ge.clear();while(Ve.size()>1){Ve.pop()}X()});return ge},purge:function(){$e(function n(){var t=ge.prefix_name()+"_";var r=Ke.get(t+"interpreters");if(r){e.each(JSON.parse(r),function(e,n){Ke.remove(n+"_commands");Ke.remove(n+"_token");Ke.remove(n+"_login")})}Qe.purge();Ke.remove(t+"interpreters")});return ge},destroy:function(){$e(function n(){Qe.destroy().remove();Ae.remove();tn.remove();e(document).unbind(".terminal_"+ge.id());e(window).unbind(".terminal_"+ge.id());ge.unbind("click wheel mousewheel mousedown mouseup");ge.removeData("terminal").removeClass("terminal").unbind(".terminal");if(Ue.width){ge.css("width","")}if(Ue.height){ge.css("height","")}e(window).off("blur",cn).off("focus",un);ge.find(".terminal-fill").remove();ge.stopTime();ke.remove(Fe);if(en){en.unobserve(ge[0])}if(nn){nn.disconnect()}ge.resizer("unbind");rn.resizer("unbind").remove();if(!ke.length()){e(window).off("hashchange")}});return ge},scroll_to_bottom:function(){k();return ge},is_bottom:function(){if(Ue.scrollBottomOffset===-1){return false}else{var n,t,r;if(ge.is("body")){n=e(document).height();t=e(window).scrollTop();r=window.innerHeight}else{n=ve[0].scrollHeight;t=ve.scrollTop();r=ve.outerHeight()}var i=n-Ue.scrollBottomOffset;return t+r>i}}},function(e,n){return function(){try{return n.apply(ge,[].slice.apply(arguments))}catch(n){if(e!=="exec"&&e!=="resume"){_(n,"TERMINAL",true)}if(!Ue.exceptionHandler){throw n}}}}));if(Ue.ignoreSystemDescribe===true){Ue.describe=false}if(Ue.width){ge.width(Ue.width)}if(Ue.height){ge.height(Ue.height)}if(ge.is("body,html")){ve=e("body,html")}else{ve=ge}e(document).bind("ajaxSend.terminal_"+ge.id(),function(e,n){xe.push(n)});var tn=e('<div class="terminal-wrapper"/>').appendTo(ge);var rn=e('<div class="font"/>').appendTo(ge);var on=e('<div class="terminal-fill"/>').appendTo(ge);Ae=e("<div>").addClass("terminal-output").attr("role","log").appendTo(tn);ge.addClass("terminal");if(Ue.login&&e.isFunction(Ue.onBeforeLogin)){try{if(Ue.onBeforeLogin.call(ge,ge)===false){Xe=false}}catch(n){Ue.onBeforeLogin=e.noop;_(n,"onBeforeLogin")}}var an;if(typeof r==="string"){an=r}else if(r instanceof Array){for(var sn=0,ln=r.length;sn<ln;++sn){if(typeof r[sn]==="string"){an=r[sn];break}}}var fn;if(e.isFunction(Ue.login)){fn=Ue.login}else if(an&&(typeof Ue.login==="string"||Ue.login===true)){fn=v(an,Ue.login)}ke.append(ge);function un(){if(Ze){ge.focus()}}function cn(){Ze=Je;ge.disable().find("textarea").trigger("blur",[true])}function pn(e){e=e.originalEvent;function n(e,n){return e.type.indexOf(n)!==-1}if(e.clipboardData){if(ge.enabled()){var t=e.clipboardData.items;if(t){for(var r=0;r<t.length;r++){if(n(t[r],"image")&&Ue.pasteImage){var i=t[r].getAsFile();var o=window.URL||window.webkitURL;var a=o.createObjectURL(i);ge.echo('<img src="'+a+'"/>',{raw:true})}else if(n(t[r],"text/plain")){t[r].getAsString(ge.insert)}}}else if(e.clipboardData.getData){var s=e.clipboardData.getData("text/plain");ge.insert(s)}return false}}}e(document).on("paste.terminal_"+ge.id(),pn);var mn=e.extend({},se,e.omap(Ue.keymap||{},function(e,n){if(!se[e]){return n.bind(ge)}return function(t,r){return n.call(ge,t,function(){return se[e](t,r)})}}));d(r,Ue.login,function(t){if(Ue.completion&&typeof Ue.completion!=="boolean"||!Ue.completion){t.completion="settings"}Ve=new x(e.extend({},Ue.extra,{name:Ue.name,prompt:Ue.prompt,keypress:Ue.keypress,keydown:Ue.keydown,resize:Ue.onResize,greetings:Ue.greetings,mousewheel:Ue.mousewheel,keymap:mn},t));Qe=e("<div/>").appendTo(tn).cmd({prompt:Ue.prompt,history:Ue.memory?"memory":Ue.history,historyFilter:Ue.historyFilter,historySize:Ue.historySize,caseSensitiveSearch:Ue.caseSensitiveSearch,width:"100%",enabled:false,keydown:le,keymap:mn,clickTimeout:Ue.clickTimeout,keypress:function(n){var t=Ve.top();if(Je&&(!Ge||!Ue.pauseEvents)){if(e.isFunction(t.keypress)){return t.keypress.call(ge,n,ge)}else if(e.isFunction(Ue.keypress)){return Ue.keypress.call(ge,n,ge)}}},onCommandChange:function(n){if(e.isFunction(Ue.onCommandChange)){try{Ue.onCommandChange.call(ge,n,ge)}catch(n){Ue.onCommandChange=e.noop;_(n,"onCommandChange")}}k()},commands:W});function r(n){n=n.originalEvent;if(n){var t=document.elementFromPoint(n.clientX,n.clientY);if(!e(t).closest(".terminal").length&&ge.enabled()){ge.disable()}}}ge.oneTime(100,function(){e(document).bind("click.terminal_"+ge.id(),r).bind("contextmenu.terminal_"+ge.id(),r)});var i=e(window);document.addEventListener("resume",function(){ge.disable()});if(Z){ge.click(function(){if(!Ye){if(!ge.enabled()){ge.focus();Qe.enable()}else{ge.disable()}}})}else{i.on("focus.terminal_"+ge.id(),un).on("blur.terminal_"+ge.id(),cn);(function(){var n=0;var t;var r="click_"+ge.id();var i=ge.find("textarea");function o(){if(t.is(".terminal")||t.is(".terminal-wrapper")){var e=ge.get_command().length;ge.set_position(e)}else if(t.closest(".prompt").length){ge.set_position(0)}if(!i.is(":focus")){i.focus()}a()}function a(){n=0;t=null}ge.mousedown(function(n){if(!b(n,on)){t=e(n.target)}}).mouseup(function(){if(ee()===""&&t){if(++n===1){if(!Ye){if(!Je){ge.focus()}else{var e=Ue.clickTimeout;ge.oneTime(e,r,o);return}}}else{ge.stopTime(r)}}a()}).dblclick(function(){a();ge.stopTime(r)})})();(function(){var n=ge.find("textarea");ge.on("contextmenu.terminal",function(t){if(ee()===""){if(!e(t.target).is("img,value,audio,object,canvas,a")){if(!ge.enabled()){ge.enable()}var r=Qe.offset();n.css({left:t.pageX-r.left-20,top:t.pageY-r.top-20,width:"5em",height:"4em"});if(!n.is(":focus")){n.focus()}ge.stopTime("textarea");ge.oneTime(100,"textarea",function(){n.css({left:"",top:"",width:"",height:""})});ge.stopTime("selection");ge.everyTime(20,"selection",function(){if(n[0].selection!==n[0].value){if(te(n[0])){re(n[0]);ie(ge.find(".terminal-output")[0],ge.find(".cmd div:last-of-type")[0]);ge.stopTime("selection")}}})}}})})()}ge.delegate("a","mouseup",function(n){var t=e(this);if(t.closest(".exception").length){var r=t.attr("href");if(r.match(/:[0-9]+$/)){n.preventDefault();f(r)}}ge.find("textarea").focus()});if(ge.is(":visible")){je=ge.cols();Qe.resize(je);if(!Ne){Ne=ue(ge)}Le=pe(ge,Ne)}function o(){if(ge.is(":visible")){var e=on.width();var n=on.height();if(Me!==n||We!==e){ge.resize()}Me=n;We=e}}function a(){ge.resizer("unbind").resizer(o);rn.resizer("unbind").resizer(function(){Ne=ue(ge);ge.resize()})}if(ge.is(":visible")){a()}function s(){if(en){en.unobserve(ge[0])}var n=ge.enabled();var t=ge.is(":visible");if(t){a()}en=new IntersectionObserver(function(){if(ge.is(":visible")&&!t){t=true;a();Ne=ue(ge);o();if(n){ge.enable()}}else if(t&&!ge.is(":visible")){t=false;n=e.terminal.active()===ge&&ge.enabled();ge.disable()}},{root:document.body});en.observe(ge[0])}var l=!!ge.closest("body").length;var u=window.MutationObserver||window.WebKitMutationObserver;if(window.IntersectionObserver){if(u){nn=new u(function(){if(ge.closest("body").length){if(!l){ge.scroll_to_bottom();s()}l=true}else if(l){l=false}});nn.observe(document.body,{childList:true})}if(l){s()}}Ie.resolve();if(Je&&ge.is(":visible")&&!Z){ge.focus(n,true)}else{ge.disable()}if(e.isFunction(fn)){ge.login(fn,true,X)}else{X()}function c(n){var t=ke.get()[n[0]];if(t&&Fe===t.id()){if(n[2]){try{if(Ge){var r=e.Deferred();B.push(function(){return t.exec(n[2]).done(function(){t.save_state(n[2],true,n[1]);r.resolve()})});return r.promise()}else{return t.exec(n[2]).done(function(){t.save_state(n[2],true,n[1])})}}catch(n){var i=t.settings();if(e.isFunction(i.exceptionHandler)){i.exceptionHandler.call(ge,n,"EXEC HASH")}else{var o=e.terminal.escape_brackets(Oe);var a="Error while exec with command "+o;t.error(a).exception(n)}}}}}if(Ue.execHash){if(location.hash){setTimeout(function(){try{var e=location.hash.replace(/^#/,"");Ee=JSON.parse(decodeURIComponent(e));var n=0;(function e(){var t=Ee[n++];if(t){c(t).done(e)}else{Ce=true}})()}catch(e){}})}else{Ce=true}}else{Ce=true}var p=false;e(document).bind("keydown.terminal_"+ge.id(),function(e){if(e.shiftKey){p=true}}).bind("keyup.terminal_"+ge.id(),function(e){if(e.shiftKey||e.which===16){p=false}});function m(n,t){if(!p){var r=Ve.top();var i;if(e.isFunction(r.mousewheel)){i=r.mousewheel(n,t,ge)}else if(e.isFunction(Ue.mousewheel)){i=Ue.mousewheel(n,t,ge)}if(P()||i===false){n.stopPropagation();n.preventDefault()}if(i===false){return}if(t>0){ge.scroll(-40)}else{ge.scroll(40)}}}if(e.event.special.mousewheel){ge.on("mousewheel",m)}else{var h;var d=document.createElement("div");if("onwheel"in d){h="wheel"}else if(document.onmousewheel!==n){h="mousewheel"}else{h="DOMMouseScroll"}d=null;ge.on(h,function(e){var n;if(h==="mousewheel"){n=-1/40*e.originalEvent.wheelDelta}else{n=e.originalEvent.deltaY||e.originalEvent.detail}m(e,-n)})}});ge.data("terminal",ge);return ge}});
/* global define, KeyboardEvent, module */
(function () {
var keyboardeventKeyPolyfill = {
polyfill: polyfill,
keys: {
3: 'Cancel',
6: 'Help',
8: 'Backspace',
9: 'Tab',
12: 'Clear',
13: 'Enter',
16: 'Shift',
17: 'Control',
18: 'Alt',
19: 'Pause',
20: 'CapsLock',
27: 'Escape',
28: 'Convert',
29: 'NonConvert',
30: 'Accept',
31: 'ModeChange',
32: ' ',
33: 'PageUp',
34: 'PageDown',
35: 'End',
36: 'Home',
37: 'ArrowLeft',
38: 'ArrowUp',
39: 'ArrowRight',
40: 'ArrowDown',
41: 'Select',
42: 'Print',
43: 'Execute',
44: 'PrintScreen',
45: 'Insert',
46: 'Delete',
48: ['0', ')'],
49: ['1', '!'],
50: ['2', '@'],
51: ['3', '#'],
52: ['4', '$'],
53: ['5', '%'],
54: ['6', '^'],
55: ['7', '&'],
56: ['8', '*'],
57: ['9', '('],
91: 'OS',
93: 'ContextMenu',
144: 'NumLock',
145: 'ScrollLock',
181: 'VolumeMute',
182: 'VolumeDown',
183: 'VolumeUp',
186: [';', ':'],
187: ['=', '+'],
188: [',', '<'],
189: ['-', '_'],
190: ['.', '>'],
191: ['/', '?'],
192: ['`', '~'],
219: ['[', '{'],
220: ['\\', '|'],
221: [']', '}'],
222: ["'", '"'],
224: 'Meta',
225: 'AltGraph',
246: 'Attn',
247: 'CrSel',
248: 'ExSel',
249: 'EraseEof',
250: 'Play',
251: 'ZoomOut'
}
};
// Function keys (F1-24).
var i;
for (i = 1; i < 25; i++) {
keyboardeventKeyPolyfill.keys[111 + i] = 'F' + i;
}
// Printable ASCII characters.
var letter = '';
for (i = 65; i < 91; i++) {
letter = String.fromCharCode(i);
keyboardeventKeyPolyfill.keys[i] = [letter.toLowerCase(), letter.toUpperCase()];
}
function log(arg) {
var pre = $('#shell');
if (typeof arg != 'string') {
arg = JSON.stringify(arg);
}
pre.html(pre.html() + arg + '\n');
}
function polyfill () {
if (!('KeyboardEvent' in window) ||
('key' in KeyboardEvent.prototype &&
Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, 'key') != undefined)) {
return false;
}
// Polyfill `key` on `KeyboardEvent`.
var proto = {
get: function (x) {
var key = keyboardeventKeyPolyfill.keys[this.which || this.keyCode];
if (Array.isArray(key)) {
key = key[+this.shiftKey];
}
return key;
},
configurable: true
};
delete KeyboardEvent.prototype.key;
Object.defineProperty(KeyboardEvent.prototype, 'key', proto);
return proto;
}
if (typeof define === 'function' && define.amd) {
define('keyboardevent-key-polyfill', keyboardeventKeyPolyfill);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
module.exports = keyboardeventKeyPolyfill;
} else if (window) {
window.keyboardeventKeyPolyfill = keyboardeventKeyPolyfill;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment