You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
86 lines
3.1 KiB
/**@license
|
|
* __ _____ ________ __
|
|
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
|
|
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
|
|
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
|
|
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
|
|
* \/ /____/
|
|
* http://terminal.jcubic.pl
|
|
*
|
|
* This is example of how to create custom formatter for jQuery Terminal
|
|
*
|
|
* Copyright (c) 2014-2021 Jakub Jankiewicz <https://jcubic.pl/me>
|
|
* Released under the MIT license
|
|
*
|
|
*/
|
|
/* global define */
|
|
(function(factory) {
|
|
var root = typeof window !== 'undefined' ? window : global;
|
|
if (typeof define === 'function' && define.amd) {
|
|
// AMD. Register as an anonymous module.
|
|
// istanbul ignore next
|
|
define(['jquery', 'jquery.terminal'], factory);
|
|
} else if (typeof module === 'object' && module.exports) {
|
|
// Node/CommonJS
|
|
module.exports = function(root, jQuery) {
|
|
if (jQuery === undefined) {
|
|
// require('jQuery') returns a factory that requires window to
|
|
// build a jQuery instance, we normalize how we use modules
|
|
// that require this pattern but the window provided is a noop
|
|
// if it's defined (how jquery works)
|
|
if (typeof window !== 'undefined') {
|
|
jQuery = require('jquery');
|
|
} else {
|
|
jQuery = require('jquery')(root);
|
|
}
|
|
}
|
|
if (!jQuery.fn.terminal) {
|
|
if (typeof window !== 'undefined') {
|
|
require('jquery.terminal');
|
|
} else {
|
|
require('jquery.terminal')(jQuery);
|
|
}
|
|
}
|
|
factory(jQuery);
|
|
return jQuery;
|
|
};
|
|
} else {
|
|
// Browser
|
|
// istanbul ignore next
|
|
factory(root.jQuery);
|
|
}
|
|
})(function($) {
|
|
if (!$.terminal) {
|
|
throw new Error('$.terminal is not defined');
|
|
}
|
|
// this formatter allow to echo xml where tags are colors like:
|
|
// <red>hello <navy>blue</navy> world</red>
|
|
function xml_formatter(string) {
|
|
var stack = [];
|
|
var output = [];
|
|
var parts = string.split(/(<\/?[a-zA-Z]+>)/);
|
|
for (var i = 0; i < parts.length; ++i) {
|
|
if (parts[i][0] === '<') {
|
|
if (parts[i][1] === '/') {
|
|
if (stack.length) {
|
|
stack.pop();
|
|
}
|
|
} else {
|
|
stack.push(parts[i].replace(/^<|>$/g, ''));
|
|
}
|
|
} else {
|
|
if (stack.length) {
|
|
// top of the stack
|
|
output.push('[[;' + stack[stack.length - 1] + ';]');
|
|
}
|
|
output.push(parts[i]);
|
|
if (stack.length) {
|
|
output.push(']');
|
|
}
|
|
}
|
|
}
|
|
return output.join('');
|
|
}
|
|
$.terminal.xml_formatter = xml_formatter;
|
|
$.terminal.new_formatter(xml_formatter);
|
|
});
|
|
|