JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
/*
* fix for buggy Windows 7
* handling of small font size
*/
.terminal {
--size: 1.4;
--color: white;
}
/*
for IE:
.terminal, .terminal-output > :not(.raw) span, .terminal-output > :not(.raw) a, .terminal-output > :not(.raw) div, .cmd, .cmd span, .cmd div {
font-size: 14px;
line-height: 16px;
}
*/
var url = 'https://terminal.jcubic.pl/ansi/read.php'; // CORS enabled
(async function() {
function get(url) {
return fetch(url).then(res => res.text()).then(text=>text.trim());
}
var files = (await get(url + '?action=ls')).split('\n');
function get_ansi(name) {
return fetch(url + '?raw=1&file=' + name).
then(res => res.arrayBuffer()).then(a => new Uint8Array(a));
}
function echo_ansi(buff) {
var meta = AnsiLove.sauceBytes(buff);
var cols = 80;
var str = iconv.decode(buff, 'CP437');
// remove code that move cursor after new line - hope this works
str = str.replace(/\r?\n?\x1b\[A\x1b\[[0-9]+C/g, '');
// main code - this will use unix_formatting file to format ANSI artwork
str = $.terminal.apply_formatters(str, {});
if (meta) {
if (str.match(/\x1a/)) { // 26 - end of file in DOS
str = str.replace(/\x1a.*/, '');
}
console.log(meta);
cols = meta.tInfo1;
var lines = $.terminal.split_equal(str, cols);
// one flush to output whole image to the screen
lines.map(line => term.echo(line, {flush: false}));
term.flush();
} else {
// should we wrap to 80 cols if there is no meta SAUCE data?
term.echo(str);
}
term.resume();
}
var term = $('body').terminal({
help: function() {
this.echo([
'use [[;#444;]ls] to display list of files and [[;#444;]cat]',
' to display the artwork, you can also [[u;;]drag and drop] the file.',
'\nOnly Code Page 437 encoding files will work (classic demo s',
'cene files).\nType [[;#444;]credits] to show credits for ANSI',
' Art works. Use tab so you don\'t need to type whole filename.',
'\nType [[;#444;]clear] to clear terminal.'
].join(''), {keepWords: true});
},
cat: function(name) {
this.pause();
get_ansi(name).then(echo_ansi);
},
ls: function() {
console.log(files);
this.echo(files);
},
credits: function() {
this.echo('ANSI artworks taken from [[!;;;;https://fuel.wtf/packs/fuel27/]fuel magazine]')
}
}, {
completion: function(string, callback) {
if (this.get_command().match(/^cat /)) {
callback(files);
} else {
callback(['ls', 'file', 'credits', 'help']);
}
},
outputLimit: 250,
greetings: 'ANSI ART Terminal viewer\nType [[;#444;]help] for more info\n',
name: 'ansi'
}).drop(function(array_buff) { // drop plugin
echo_ansi(new Uint8Array(array_buff));
return term.read('press enter to continue ');
}, {
type: 'arraybuffer',
error: function(e) {
term.exception(e);
},
complete: function() {
term.echo('all files rendered');
}
});
})();
Also see: Tab Triggers