Skip to content

Commit

Permalink
Havy refactor of unix_formatting using proper parser #553
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 1, 2020
1 parent 1090b06 commit 54ae16e
Show file tree
Hide file tree
Showing 12 changed files with 819 additions and 333 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ http://terminal.jcubic.pl

[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-DEV-yellow.svg)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&e066504922af108aa103a5e6c9f435310fbb2452)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&65e46dacd627aa8e35cef61bdb0bda57)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&1090b06b354f633244d57b66a5c26d027a8c4bd9)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&ea922dfe0d9b9476db2ce2ee4d7401c5)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
![downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![package quality](http://npm.packagequality.com/shield/jquery.terminal.svg)](http://packagequality.com/#?package=jquery.terminal)
[![](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded)](https://www.jsdelivr.com/package/npm/jquery.terminal)
Expand Down
241 changes: 211 additions & 30 deletions __tests__/__snapshots__/terminal.spec.js.snap

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ global.location = global.window.location = {hash: ''};
global.document = window.document;
global.jQuery = global.$ = require("jquery");
global.wcwidth = require('wcwidth');

var iconv = require('iconv-lite');
// mock Canvas & Image
var gm = require('gm');
window.Image = class Image {
Expand Down Expand Up @@ -541,13 +541,8 @@ describe('Terminal utils', function() {
var output = $.terminal.from_ansi(input);
expect(output).toEqual(input);
});
it('should escape brakets', function() {
var input = 'foo [ bar ]';
var output = $.terminal.from_ansi(input, {
unixFormattingEscapeBrackets: true
});
expect(output).toEqual('foo [ bar ]');
});
// TODO: add tests when ervy fix https://github.com/chunqiuyiyu/ervy/issues/14
/*
it('should format plots with moving cursors', function() {
return Promise.all([
fs.readFileAsync('__tests__/ervy-plot-01'),
Expand All @@ -558,6 +553,19 @@ describe('Terminal utils', function() {
});
});
});
*/
it('should render ANSI art', function() {
return Promise.all(['nf-marble.ans', 'bs-pacis.ans'].map(fname => {
return fs.readFileAsync(`__tests__/${fname}`).then(data => {
var str = iconv.decode(data, 'CP437');
return $.terminal.from_ansi(str);
});
})).then(data => {
data.forEach(ansi => {
expect(ansi).toMatchSnapshot();
});
});
});
});
describe('$.terminal.overtyping', function() {
it('should convert to terminal formatting', function() {
Expand Down
14 changes: 7 additions & 7 deletions js/jquery.terminal-2.11.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Thu, 26 Dec 2019 19:14:37 +0000
* Date: Wed, 01 Jan 2020 13:17:25 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -4138,7 +4138,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Thu, 26 Dec 2019 19:14:37 +0000',
date: 'Wed, 01 Jan 2020 13:17:25 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4832,7 +4832,7 @@
// ---------------------------------------------------------------------
apply_formatters: function apply_formatters(string, settings) {
if (string === "") {
if (typeof settings.position === 'number') {
if (settings && typeof settings.position === 'number') {
return ["", settings.position];
} else {
return "";
Expand Down Expand Up @@ -5152,9 +5152,9 @@
style_str += 'background-color:' + background + ';';
}
var data = clean_data(data_text, text);
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
style_str += extra;
}
var result;
Expand Down Expand Up @@ -5219,9 +5219,9 @@
} else {
text = safe(text);
text = text.replace(/\\\]/, ']');
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra.length) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
return '<span style="' + extra + '">' + text + '</span>';
} else {
return '<span>' + text + '</span>';
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-2.11.1.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -4832,7 +4832,7 @@
// ---------------------------------------------------------------------
apply_formatters: function apply_formatters(string, settings) {
if (string === "") {
if (typeof settings.position === 'number') {
if (settings && typeof settings.position === 'number') {
return ["", settings.position];
} else {
return "";
Expand Down Expand Up @@ -5152,9 +5152,9 @@
style_str += 'background-color:' + background + ';';
}
var data = clean_data(data_text, text);
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
style_str += extra;
}
var result;
Expand Down Expand Up @@ -5219,9 +5219,9 @@
} else {
text = safe(text);
text = text.replace(/\\\]/, '&#93;');
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra.length) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
return '<span style="' + extra + '">' + text + '</span>';
} else {
return '<span>' + text + '</span>';
Expand Down
14 changes: 7 additions & 7 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Thu, 26 Dec 2019 19:14:37 +0000
* Date: Wed, 01 Jan 2020 13:17:25 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -4138,7 +4138,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Thu, 26 Dec 2019 19:14:37 +0000',
date: 'Wed, 01 Jan 2020 13:17:25 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4832,7 +4832,7 @@
// ---------------------------------------------------------------------
apply_formatters: function apply_formatters(string, settings) {
if (string === "") {
if (typeof settings.position === 'number') {
if (settings && typeof settings.position === 'number') {
return ["", settings.position];
} else {
return "";
Expand Down Expand Up @@ -5152,9 +5152,9 @@
style_str += 'background-color:' + background + ';';
}
var data = clean_data(data_text, text);
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
style_str += extra;
}
var result;
Expand Down Expand Up @@ -5219,9 +5219,9 @@
} else {
text = safe(text);
text = text.replace(/\\\]/, '&#93;');
var extra = extra_css(text, options);
var extra = extra_css(text, settings);
if (extra.length) {
text = wide_characters(text, options);
text = wide_characters(text, settings);
return '<span style="' + extra + '">' + text + '</span>';
} else {
return '<span>' + text + '</span>';
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.terminal.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 54ae16e

Please sign in to comment.