Skip to content

Commit

Permalink
Add way to inherit styles in nested formatting #513
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Aug 18, 2019
1 parent 1e389f5 commit 1f440ff
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 39 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&5f72993802385af4b02c824d9efac2eb3d539bdf)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&b51596e4a2c1068f02aef0bd0b97dd0f)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&1e389f525b8f438e86184c1067e6bac704cab78a)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&9664017d971ef7c68cd9ba29e8536517)](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
19 changes: 17 additions & 2 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,30 @@ describe('Terminal utils', function() {
var specs = [
[
'[[;red;]foo[[;blue;]bar]baz]',
'[[;red;]foo][[;blue;]bar][[;red;]baz]'
'[[;red;]foo][[;blue;]bar][[;red;]baz]',
true
],
[
'[[;#fff;] lorem [[b;;]ipsum [[s;;]dolor] sit] amet]',
'[[;#fff;] lorem ][[b;;]ipsum ][[s;;]dolor][[b;;] sit][[;#fff;] amet]'
'[[;#fff;] lorem ][[b;;]ipsum ][[s;;]dolor][[b;;] sit][[;#fff;] amet]',
false
],
[
'[[;#fff;] lorem [[b;;]ipsum [[s;;]dolor] sit] amet]',
'[[;#fff;] lorem ][[b;#fff;]ipsum ][[s;#fff;]dolor][[b;#fff;] sit][[;#fff;] amet]',
true
]
];
var __inherit__;
beforeEach(function() {
__inherit__ = $.terminal.nested_formatting.__inherit__;
});
afterEach(function() {
$.terminal.nested_formatting.__inherit__ = __inherit__;
});
it('should create list of formatting', function() {
specs.forEach(function(spec) {
$.terminal.nested_formatting.__inherit__ = spec[2];
expect($.terminal.nested_formatting(spec[0])).toEqual(spec[1]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion css/emoji.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions css/jquery.terminal-2.7.1.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2019 Jakub Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
* Date: Fri, 16 Aug 2019 19:21:43 +0000
* Date: Sun, 18 Aug 2019 10:00:46 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd-prompt, .cmd-prompt div {
Expand Down Expand Up @@ -190,11 +190,17 @@ body.full-screen-terminal .terminal {
}
.terminal-output > :not(.raw) .emoji, .cmd .emoji {
height: 14px;
background-size: cover;
display: inline-block;
background-size: contain;
background-repeat: no-repeat;
color: transparent;
position: relative;
}
.terminal-output > :not(.raw) .emoji, .terminal-output > :not(.raw) .emoji span,
.cmd .emoji, .cmd .emoji span {
display: inline-block;
width: 2ch;
}

.terminal, .cmd {
box-sizing: border-box;
cursor: text;
Expand Down
4 changes: 2 additions & 2 deletions css/jquery.terminal-2.7.1.min.css

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions css/jquery.terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2019 Jakub Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
* Date: Fri, 16 Aug 2019 19:21:43 +0000
* Date: Sun, 18 Aug 2019 10:00:46 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd-prompt, .cmd-prompt div {
Expand Down Expand Up @@ -190,11 +190,17 @@ body.full-screen-terminal .terminal {
}
.terminal-output > :not(.raw) .emoji, .cmd .emoji {
height: 14px;
background-size: cover;
display: inline-block;
background-size: contain;
background-repeat: no-repeat;
color: transparent;
position: relative;
}
.terminal-output > :not(.raw) .emoji, .terminal-output > :not(.raw) .emoji span,
.cmd .emoji, .cmd .emoji span {
display: inline-block;
width: 2ch;
}

.terminal, .cmd {
box-sizing: border-box;
cursor: text;
Expand Down
4 changes: 2 additions & 2 deletions css/jquery.terminal.min.css

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

50 changes: 43 additions & 7 deletions js/jquery.terminal-2.7.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* emoji regex v7.0.1 by Mathias Bynens
* MIT license
*
* Date: Fri, 16 Aug 2019 19:21:42 +0000
* Date: Sun, 18 Aug 2019 10:00:45 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -3917,7 +3917,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Fri, 16 Aug 2019 19:21:42 +0000',
date: 'Sun, 18 Aug 2019 10:00:45 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4447,20 +4447,54 @@
}
var stack = [];
var re = /((?:\[\[(?:[^\][]|\\\])+\])?(?:[^\][]|\\\])*\]?)/;
var format_re = /(\[\[(?:[^\][]|\\\])+\])[\s\S]*/;
var format_re = /\[\[((?:[^\][]|\\\])+)\][\s\S]*/;
var format_split_re = /^\[\[([^;]*);([^;]*);([^;\]]*)\]/;
function get_inherit_style(stack) {
var style = ['', '', ''];
if (!stack.length) {
return style;
}
for (var i = stack.length; i--;) {
var formatting = stack[i].split(';');
for (var j = 0; j < style.length; ++j) {
var value = formatting[j].trim();
if (value && !style[j]) {
style[j] = value;
}
}
}
return style;
}
return string.split(re).filter(Boolean).map(function(string) {
var style;
if (string.match(/^\[\[/)) {
if (!$.terminal.is_formatting(string)) {
var formatting = string.replace(format_re, '$1');
var is_formatting = $.terminal.is_formatting(string);
string = string.replace(format_split_re, '');
stack.push(formatting);
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = formatting;
}
if (!is_formatting) {
string += ']';
stack.push(string.replace(format_re, '$1'));
} else {
stack.pop();
}
string = '[[' + style + ']' + string;
} else {
var pop = false;
if (string.match(/\]/)) {
pop = true;
}
if (stack.length) {
string = stack[stack.length - 1] + string;
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = stack[stack.length - 1];
}
string = '[[' + style + ']' + string;
}
if (pop) {
stack.pop();
Expand Down Expand Up @@ -5448,6 +5482,8 @@
// :: Default options
// -----------------------------------------------------------------------
$.terminal.nested_formatting.__meta__ = true;
// if set to true nested formatting will inherit styles from styles outside
$.terminal.nested_formatting.__inherit__ = false;
// nested formatting will always return different length so we silent the warning
$.terminal.nested_formatting.__no_warn__ = true;
$.terminal.defaults = {
Expand Down Expand Up @@ -5520,7 +5556,7 @@
onEchoCommand: $.noop,
onPaste: $.noop,
onFlush: $.noop,
onBeforeCommands: null,
onBeforeCommand: null,
onAfterCommand: null,
onBeforeEcho: null,
onAfterEcho: null,
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-2.7.1.min.js

Large diffs are not rendered by default.

44 changes: 40 additions & 4 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -4447,20 +4447,54 @@
}
var stack = [];
var re = /((?:\[\[(?:[^\][]|\\\])+\])?(?:[^\][]|\\\])*\]?)/;
var format_re = /(\[\[(?:[^\][]|\\\])+\])[\s\S]*/;
var format_re = /\[\[((?:[^\][]|\\\])+)\][\s\S]*/;
var format_split_re = /^\[\[([^;]*);([^;]*);([^;\]]*)\]/;
function get_inherit_style(stack) {
var style = ['', '', ''];
if (!stack.length) {
return style;
}
for (var i = stack.length; i--;) {
var formatting = stack[i].split(';');
for (var j = 0; j < style.length; ++j) {
var value = formatting[j].trim();
if (value && !style[j]) {
style[j] = value;
}
}
}
return style;
}
return string.split(re).filter(Boolean).map(function(string) {
var style;
if (string.match(/^\[\[/)) {
if (!$.terminal.is_formatting(string)) {
var formatting = string.replace(format_re, '$1');
var is_formatting = $.terminal.is_formatting(string);
string = string.replace(format_split_re, '');
stack.push(formatting);
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = formatting;
}
if (!is_formatting) {
string += ']';
stack.push(string.replace(format_re, '$1'));
} else {
stack.pop();
}
string = '[[' + style + ']' + string;
} else {
var pop = false;
if (string.match(/\]/)) {
pop = true;
}
if (stack.length) {
string = stack[stack.length - 1] + string;
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = stack[stack.length - 1];
}
string = '[[' + style + ']' + string;
}
if (pop) {
stack.pop();
Expand Down Expand Up @@ -5448,6 +5482,8 @@
// :: Default options
// -----------------------------------------------------------------------
$.terminal.nested_formatting.__meta__ = true;
// if set to true nested formatting will inherit styles from styles outside
$.terminal.nested_formatting.__inherit__ = false;
// nested formatting will always return different length so we silent the warning
$.terminal.nested_formatting.__no_warn__ = true;
$.terminal.defaults = {
Expand Down
50 changes: 43 additions & 7 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* emoji regex v7.0.1 by Mathias Bynens
* MIT license
*
* Date: Fri, 16 Aug 2019 19:21:42 +0000
* Date: Sun, 18 Aug 2019 10:00:45 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -3917,7 +3917,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Fri, 16 Aug 2019 19:21:42 +0000',
date: 'Sun, 18 Aug 2019 10:00:45 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -4447,20 +4447,54 @@
}
var stack = [];
var re = /((?:\[\[(?:[^\][]|\\\])+\])?(?:[^\][]|\\\])*\]?)/;
var format_re = /(\[\[(?:[^\][]|\\\])+\])[\s\S]*/;
var format_re = /\[\[((?:[^\][]|\\\])+)\][\s\S]*/;
var format_split_re = /^\[\[([^;]*);([^;]*);([^;\]]*)\]/;
function get_inherit_style(stack) {
var style = ['', '', ''];
if (!stack.length) {
return style;
}
for (var i = stack.length; i--;) {
var formatting = stack[i].split(';');
for (var j = 0; j < style.length; ++j) {
var value = formatting[j].trim();
if (value && !style[j]) {
style[j] = value;
}
}
}
return style;
}
return string.split(re).filter(Boolean).map(function(string) {
var style;
if (string.match(/^\[\[/)) {
if (!$.terminal.is_formatting(string)) {
var formatting = string.replace(format_re, '$1');
var is_formatting = $.terminal.is_formatting(string);
string = string.replace(format_split_re, '');
stack.push(formatting);
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = formatting;
}
if (!is_formatting) {
string += ']';
stack.push(string.replace(format_re, '$1'));
} else {
stack.pop();
}
string = '[[' + style + ']' + string;
} else {
var pop = false;
if (string.match(/\]/)) {
pop = true;
}
if (stack.length) {
string = stack[stack.length - 1] + string;
if ($.terminal.nested_formatting.__inherit__) {
style = get_inherit_style(stack).join(';');
} else {
style = stack[stack.length - 1];
}
string = '[[' + style + ']' + string;
}
if (pop) {
stack.pop();
Expand Down Expand Up @@ -5448,6 +5482,8 @@
// :: Default options
// -----------------------------------------------------------------------
$.terminal.nested_formatting.__meta__ = true;
// if set to true nested formatting will inherit styles from styles outside
$.terminal.nested_formatting.__inherit__ = false;
// nested formatting will always return different length so we silent the warning
$.terminal.nested_formatting.__no_warn__ = true;
$.terminal.defaults = {
Expand Down Expand Up @@ -5520,7 +5556,7 @@
onEchoCommand: $.noop,
onPaste: $.noop,
onFlush: $.noop,
onBeforeCommands: null,
onBeforeCommand: null,
onAfterCommand: null,
onBeforeEcho: null,
onAfterEcho: null,
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.

0 comments on commit 1f440ff

Please sign in to comment.