1
0
web/static/term/pkg/jquery.terminal/js/jquery.terminal.min.js

37 lines
60 KiB
JavaScript
Raw Normal View History

2024-04-07 17:50:00 +00:00
/**@license
* __ _____ ________ __
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
* \/ /____/ version 0.10.8
*
* This file is part of jQuery Terminal. http://terminal.jcubic.pl
*
* Copyright (c) 2010-2016 Jakub Jankiewicz <http://jcubic.pl>
* Released under the MIT license
*
* Contains:
*
* Storage plugin Distributed under the MIT License
* Copyright (c) 2010 Dave Schindler
*
* jQuery Timers licenced with the WTFPL
* <http://jquery.offput.ca/timers/>
*
* Cross-Browser Split 1.1.1
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
* Available under the MIT License
*
* jQuery Caret
* Copyright (c) 2009, Gideon Sireling
* 3 clause BSD License
*
* sprintf.js
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Tue, 17 May 2016 09:01:51 +0000
*/
(function(e){var r=function(){if(!r.cache.hasOwnProperty(arguments[0])){r.cache[arguments[0]]=r.parse(arguments[0])}return r.format.call(null,r.cache[arguments[0]],arguments)};r.format=function(e,n){var o=1,a=e.length,s="",l,f=[],c,u,h,p,m,g;for(c=0;c<a;c++){s=t(e[c]);if(s==="string"){f.push(e[c])}else if(s==="array"){h=e[c];if(h[2]){l=n[o];for(u=0;u<h[2].length;u++){if(!l.hasOwnProperty(h[2][u])){throw r('[sprintf] property "%s" does not exist',h[2][u])}l=l[h[2][u]]}}else if(h[1]){l=n[h[1]]}else{l=n[o++]}if(/[^s]/.test(h[8])&&t(l)!="number"){throw r("[sprintf] expecting number but found %s",t(l))}switch(h[8]){case"b":l=l.toString(2);break;case"c":l=String.fromCharCode(l);break;case"d":l=parseInt(l,10);break;case"e":l=h[7]?l.toExponential(h[7]):l.toExponential();break;case"f":l=h[7]?parseFloat(l).toFixed(h[7]):parseFloat(l);break;case"o":l=l.toString(8);break;case"s":l=(l=String(l))&&h[7]?l.substring(0,h[7]):l;break;case"u":l=l>>>0;break;case"x":l=l.toString(16);break;case"X":l=l.toString(16).toUpperCase();break}l=/[def]/.test(h[8])&&h[3]&&l>=0?"+"+l:l;m=h[4]?h[4]=="0"?"0":h[4].charAt(1):" ";g=h[6]-String(l).length;p=h[6]?i(m,g):"";f.push(h[5]?l+p:p+l)}}return f.join("")};r.cache={};r.parse=function(e){var r=e,n=[],t=[],i=0;while(r){if((n=/^[^\x25]+/.exec(r))!==null){t.push(n[0])}else if((n=/^\x25{2}/.exec(r))!==null){t.push("%")}else if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(r))!==null){if(n[2]){i|=1;var o=[],a=n[2],s=[];if((s=/^([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1]);while((a=a.substring(s[0].length))!==""){if((s=/^\.([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1])}else if((s=/^\[(\d+)\]/.exec(a))!==null){o.push(s[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}n[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}t.push(n)}else{throw"[sprintf] huh?"}r=r.substring(n[0].length)}return t};var n=function(e,n,t){t=n.slice(0);t.splice(0,0,e);return r.apply(null,t)};function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,r){for(var n=[];r>0;n[--r]=e){}return n.join("")}e.sprintf=r;e.vsprintf=n})(typeof global!="undefined"?global:window);(function(e,r){"use strict";e.omap=function(r,n){var t={};e.each(r,function(e,i){t[e]=n.call(r,e,i)});return t};var n={clone_object:function(r){var n={};if(typeof r=="object"){if(e.isArray(r)){return this.clone_array(r)}else if(r===null){return r}else{for(var t in r){if(e.isArray(r[t])){n[t]=this.clone_array(r[t])}else if(typeof r[t]=="object"){n[t]=this.clone_object(r[t])}else{n[t]=r[t]}}}}return n},clone_array:function(r){if(!e.isFunction(Array.prototype.map)){throw new Error("You'r browser don't support ES5 array map "+"use es5-shim")}return r.slice(0).map(function(e){if(typeof e=="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var t=function(e){return n.clone_object(e)};var i=function(){var e="test",r=window.localStorage;try{r.setItem(e,"1");r.removeItem(e);return true}catch(n){return false}};var o=i();function a(e,r){var n;if(typeof e==="string"&&typeof r==="string"){localStorage[e]=r;return true}else if(typeof e==="object"&&typeof r==="undefined"){for(n in e){if(e.hasOwnProperty(n)){localStorage[n]=e[n]}}return true}return false}function s(e,r){var n,t,i;n=new Date;n.setTime(n.getTime()+31536e6);t="; expires="+n.toGMTString();if(typeof e==="string"&&typeof r==="string"){document.cookie=e+"="+r+t+"; path=/";return true}else if(typeof e==="object"&&typeof r==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+t+"; path=/"}}return true}return false}function l(e){return localStorage[e]}function f(e){var r,n,t,i;r=e+"=";n=document.cookie.split(";");for(t=0;t<n.length;t++){i=n[t];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(r)===0){return i.substring(r.length,i.length)}}return null}function c(e){return delete localStorage[e]}function u(e){return s(e,"",-1)}e.extend({Storage:{set:o?a:s,get:o?l:f,remove:o?c:u}});jQuery.fn.extend({everyTime:function(e,r,n,t,i){ret
e.terminal.defaults={prompt:"> ",history:true,exit:true,clear:true,enabled:true,historySize:60,maskChar:"*",checkArity:true,raw:false,exceptionHandler:null,cancelableAjax:true,processArguments:true,linksNoReferrer:false,processRPCResponse:null,Token:true,convertLinks:true,historyState:false,login:null,outputLimit:-1,formatters:[],onAjaxError:null,onRPCError:null,completion:false,historyFilter:null,onInit:e.noop,onClear:e.noop,onBlur:e.noop,onFocus:e.noop,onTerminalChange:e.noop,onExit:e.noop,keypress:e.noop,keydown:e.noop,strings:{wrongPasswordTryAgain:"Wrong password try again!",wrongPassword:"Wrong password!",ajaxAbortError:"Error while aborting ajax call!",wrongArity:"Wrong number of arguments. Function '%s' expects %s got"+" %s!",commandNotFound:"Command '%s' Not Found!",oneRPCWithIgnore:"You can use only one rpc with ignoreSystemDescr"+"ibe",oneInterpreterFunction:"You can't use more than one function (rpc"+"with ignoreSystemDescribe counts as one)",loginFunctionMissing:"You didn't specify a login function",noTokenError:"Access denied (no token)",serverResponse:"Server responded",wrongGreetings:"Wrong value of greetings parameter",notWhileLogin:"You can't call `%s' function while in login",loginIsNotAFunction:"Authenticate must be a function",canExitError:"You can't exit from main interpreter",invalidCompletion:"Invalid completion",invalidSelector:'Sorry, but terminal said that "%s" is not valid '+"selector!",invalidTerminalId:"Invalid Terminal ID",login:"login",password:"password",recursiveCall:"Recursive call detected, skip"}};var X=[];var Z=window.terminals=new p;var V=[];var er;var rr=false;var nr=true;var tr=true;e.fn.terminal=function(n,i){function o(r){if(e.isFunction(Tr.processArguments)){return x(r,Tr.processArguments)}else if(Tr.processArguments){return e.terminal.parse_command(r)}else{return e.terminal.split_command(r)}}function a(r){if(typeof r==="string"){lr.echo(r)}else if(r instanceof Array){lr.echo(e.map(r,function(r){return e.json_stringify(r)}).join(" "))}else if(typeof r==="object"){lr.echo(e.json_stringify(r))}else{lr.echo(r)}}function s(r){var n=/(.*):([0-9]+):([0-9]+)$/;var t=r.match(n);if(t){lr.pause();e.get(t[1],function(r){var n=location.href.replace(/[^\/]+$/,"");var i=t[1].replace(n,"");lr.echo("[[b;white;]"+i+"]");var o=r.split("\n");var a=+t[2]-1;lr.echo(o.slice(a-2,a+3).map(function(r,n){if(n==2){r="[[;#f00;]"+e.terminal.escape_brackets(r)+"]"}return"["+(a+n)+"]: "+r}).join("\n")).resume()},"text")}}function l(r){if(e.isFunction(Tr.onRPCError)){Tr.onRPCError.call(lr,r)}else{lr.error("&#91;RPC&#93; "+r.message)}}function f(r,n){var t=function(n,t){lr.pause();e.jrpc(r,n,t,function(r){if(r.error){l(r.error)}else{if(e.isFunction(Tr.processRPCResponse)){Tr.processRPCResponse.call(lr,r.result,lr)}else{a(r.result)}}lr.resume()},u)};return function(e,r){if(e===""){return}try{e=o(e)}catch(i){r.error(i.toString());return}if(!n||e.name==="help"){t(e.name,e.args)}else{var a=r.token();if(a){t(e.name,[a].concat(e.args))}else{r.error("&#91;AUTH&#93; "+jr.noTokenError)}}}}function c(n,t,i,a){return function(s,l){if(s===""){return}var f;try{f=o(s)}catch(u){lr.error(u.toString());return}var h=n[f.name];var p=e.type(h);if(p==="function"){if(t&&h.length!==f.args.length){lr.error("&#91;Arity&#93; "+sprintf(jr.wrongArity,f.name,h.length,f.args.length))}else{return h.apply(lr,f.args)}}else if(p==="object"||p==="string"){var m=[];if(p==="object"){m=Object.keys(h);h=c(h,Tr.arity,i)}l.push(h,{prompt:f.name+"> ",name:f.name,completion:p==="object"?m:r})}else{if(e.isFunction(a)){a(s,lr)}else if(e.isFunction(Tr.onCommandNotFound)){Tr.onCommandNotFound(s,lr)}else{l.error(sprintf(jr.commandNotFound,f.name))}}}}function u(r,n,t){lr.resume();if(e.isFunction(Tr.onAjaxError)){Tr.onAjaxError.call(lr,r,n,t)}else if(n!=="abort"){lr.error("&#91;AJAX&#93; "+n+" - "+jr.serverResponse+": \n"+e.terminal.escape_brackets(r.responseText))}}function h(r,n,t){e.jrpc(r,"system.describe",[],function(i){var o=[];if(i.procs){var s={};e.each(i.procs,function(t,i){s[i.name]=function(){var t=n&&i.name!="help";var o=Array.prototype.slice.ca