Skip to content

Commit

Permalink
merge with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Aug 21, 2020
2 parents 40ea49e + e0f3610 commit 70eed4d
Show file tree
Hide file tree
Showing 22 changed files with 629 additions and 258 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## 2.18.0
### Features
* new API to use `renderHandler` with update
* new API (`apply_formatters` function option) to pick where processing of formatting should work [#588](https://github.com/jcubic/jquery.terminal/issues/588)
* allow to toggle formatters in prism (enabled by default only for echo and command)
* escape slash in `escape_formatting`/`escape_brackets` [#605](https://github.com/jcubic/jquery.terminal/issues/605)
* add support for rgb(a) and hsl(a) colors [#590](https://github.com/jcubic/jquery.terminal/issues/590)
* unify Firefox and Webkit (chrome) custom scrollbars [#607](https://github.com/jcubic/jquery.terminal/issues/607)
### Bugfix
* fix same cases of wrong calculated size of the character when --size is used [#602](https://github.com/jcubic/jquery.terminal/issues/602)
* add custom scrollbar on Firefox
* fix colors of Webkit scrollbar
* fix `renderHandler` in update
* fix formatting in update - reusing options from echo
* fix normal return string from prompt
* fix pipe symbol inside strings [#606](https://github.com/jcubic/jquery.terminal/issues/606)
* fix spaces in images in less & text selection
* fix regresion in fontawesome icons
* fix inconsistency with emoji and wide characters in terminal and cmd
* fix rounding issue that cause exception in less when rendering images

## 2.17.6
### Bugfix
* fix adding duplicated prism formatters [#573](https://github.com/jcubic/jquery.terminal/issues/573)
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
__ / / // / // / _ / _/ // / / / _ / _/ / / \/ / _ \/ /
/ / / // / // / ___/ // // / / / ___/ // / / / / /\ / // / /__
\___/____ \\__/____/_/ \__ / /_/____/_//_/_/_/_/_/ \/\__\_\___/
\/ /____/ version 2.17.6
\/ /____/ version DEV
```
https://terminal.jcubic.pl

[![npm](https://img.shields.io/badge/npm-2.17.6-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-2.17.6-yellow.svg)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&ec8cb9e09df5db396ac8ee716c02d8def875d0ad)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=master&9db85deb88e33acaed6caaea513d5bb3)](https://coveralls.io/github/jcubic/jquery.terminal?branch=master)
[![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&e33ee366116c0955f6fb2a8503885992924576a5)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&8052ac5d4b2845ef44d4d06c7fbd96f1)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
![downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded)](https://www.jsdelivr.com/package/npm/jquery.terminal)
[![LICENSE MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jcubic/jquery.terminal/blob/master/LICENSE)

[![Paid Support](https://github.com/jcubic/jquery.terminal/blob/master/.github/support.svg?raw=true)](https://xscode.com/jcubic/jquery.terminal)

“jQuery Terminal is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial”

### Summary

jQuery Terminal Emulator is a plugin for creating command line interpreters in
Expand Down Expand Up @@ -78,20 +80,20 @@ Include jQuery library, you can use cdn from https://jquery.com/download/
```


Then include js/jquery.terminal-2.17.6.min.js and css/jquery.terminal-2.17.6.min.css
Then include js/jquery.terminal-DEV.min.js and css/jquery.terminal-DEV.min.css

You can grab the files from CDN:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.17.6/js/jquery.terminal.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.17.6/css/jquery.terminal.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/DEV/js/jquery.terminal.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/DEV/css/jquery.terminal.min.css" rel="stylesheet"/>
```

or

```html
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@2.17.6/js/jquery.terminal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery.terminal@2.17.6/css/jquery.terminal.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@DEV/js/jquery.terminal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery.terminal@DEV/css/jquery.terminal.min.css">
```

If you always want latest version, you can get it from [unpkg](https://unpkg.com/) without specifying version,
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/terminal.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ exports[`Terminal utils $.terminal.format should handle emails 2`] = `"<a href=\

exports[`Terminal utils $.terminal.format should handle wider characters without formatting 1`] = `"<span style=\\"width: 24ch\\" data-text=\\"ターミナルウィンドウは黒\\"><span style=\\"width: 24ch\\"><span style=\\"width: 2ch\\">タ</span><span style=\\"width: 2ch\\">ー</span><span style=\\"width: 2ch\\">ミ</span><span style=\\"width: 2ch\\">ナ</span><span style=\\"width: 2ch\\">ル</span><span style=\\"width: 2ch\\">ウ</span><span style=\\"width: 2ch\\">ィ</span><span style=\\"width: 2ch\\">ン</span><span style=\\"width: 2ch\\">ド</span><span style=\\"width: 2ch\\">ウ</span><span style=\\"width: 2ch\\">は</span><span style=\\"width: 2ch\\">黒</span></span></span><span style=\\"width: 4ch\\" data-text=\\"です\\"><span><span style=\\"width: 4ch\\"><span style=\\"width: 2ch\\">で</span><span style=\\"width: 2ch\\">す</span></span></span></span>"`;
exports[`Terminal utils $.terminal.format should merge color style with style attr 1`] = `"<span style=\\"color:green;--color:green;--original-color:green;--size: 2\\" data-text=\\"Foo\\"><span>Foo</span></span>"`;
exports[`Terminal utils $.terminal.format should not allow attributes 1`] = `"<span data-text=\\"foo\\"><span>foo</span></span>"`;
exports[`Terminal utils $.terminal.format should not duplicate and don't overwrite data-text 1`] = `"<span data-text=\\"foo\\"><span>foo</span></span>"`;
Expand Down
139 changes: 121 additions & 18 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,21 @@ describe('Terminal utils', function() {
});
describe('$.terminal.valid_color', function() {
it('should mark hex color as valid', function() {
var valid_colors = ['#fff', '#fab', '#ffaacc', 'red', 'blue'];
var valid_colors = [
'#fff', '#fab', '#ffaacc', 'red', 'blue',
'rgba(100,100,100,1)', 'rgb(100, 200, 300)',
'hsl(100, 20, 20)', 'hsla(100,10,20, 1)'
];
valid_colors.forEach(function(color) {
expect($.terminal.valid_color(color)).toBe(true);
});
});
it('should mark hex color as invalid', function() {
var valid_colors = ['foo', '#faro', '#fifa', 'fuck'];
valid_colors.forEach(function(color) {
expect($.terminal.valid_color(color)).toBe(false);
});
});
});
describe('$.terminal.format', function() {
var format = '[[biugs;#fff;#000]Foo][[i;;;foo]Bar][[ous;;]Baz]';
Expand Down Expand Up @@ -1019,6 +1029,13 @@ describe('Terminal utils', function() {
});
expect(output).toMatchSnapshot();
});
it('should merge color style with style attr', function() {
var input = '[[;green;;;;{"style": "--size: 2"}]Foo]';
var output = $.terminal.format(input, {
allowedAttributes: ['style']
});
expect(output).toMatchSnapshot();
});
});
describe('$.terminal.strip', function() {
it('should remove formatting', function() {
Expand Down Expand Up @@ -1087,6 +1104,62 @@ describe('Terminal utils', function() {
var output = $.terminal.apply_formatters(input);
expect(output).toEqual(input.replace(/0/g, 'x'));
});
describe('terminal', function() {
var term, formatters;
beforeEach(function() {
term = $('<div/>').terminal();
formatters = $.terminal.defaults.formatters.slice();
$.terminal.defaults.formatters = [
[/foo/g, 'bar'],
[/prompt/g, 'p__', {prompt: true}],
[/cmd/g, 'c__', {command: true}],
[/echo/g, 'e__', {echo: true}]
];
});
afterEach(function() {
term.destroy();
$.terminal.defaults.formatters = formatters;
});
function test(spec) {
var prompt = spec.prompt;
var echo = spec.echo;
var command = spec.command;
term.set_prompt(prompt[0]);
expect(term.find('.cmd-prompt').text()).toEqual(prompt[1]);
term.clear().echo(echo[0]);
expect(term.find('.terminal-output').text()).toEqual(echo[1]);
term.set_command(command[0]);
expect(term.find('.cmd-prompt').nextAll().text().trim()).toEqual(command[1]);
}
it('should always formatters', function() {
test({
prompt: ['foo>', 'bar>'],
command: ['foo', 'bar'],
echo: ['foo', 'bar']
});
});
it('should apply formatter only in prompt', function() {
test({
prompt: ['prompt>', 'p__>'],
command: ['prompt', 'prompt'],
echo: ['prompt', 'prompt']
});
});
it('should apply formatter only to echo', function() {
test({
prompt: ['echo>', 'echo>'],
command: ['echo', 'echo'],
echo: ['echo', 'e__']
});
});
it('should apply formatter only to command', function() {
test({
prompt: ['cmd>', 'cmd>'],
command: ['cmd', 'c__'],
echo: ['cmd', 'cmd']
});
});
});
});
describe('$.terminal.split_equal', function() {
var text = ['[[bui;#fff;]Lorem ipsum dolor sit amet, consectetur adipi',
Expand Down Expand Up @@ -2251,6 +2324,23 @@ describe('Terminal utils', function() {
}));
await term.exec('echo "|" | read');
expect(get_lines(term)).toEqual(['your text: |']);
term.destroy();
// new API with option that use monkey patch
term = $('<div/>').terminal({
read: function() {
return this.read('').then((text) => {
this.echo('your text: ' + text);
});
},
echo: async function(string) {
await delay(10);
return string;
}
}, {
pipe: true
});
await term.exec('echo "|" | read');
expect(get_lines(term)).toEqual(['your text: |']);
});
it('should filter lines', function() {
var term = $('<div/>').terminal($.terminal.pipe({
Expand Down Expand Up @@ -5437,22 +5527,6 @@ describe('Terminal plugin', function() {
expect(term.find('.terminal-output').text()).toEqual('foobarbaz');
});
});
describe('update', function() {
var term = $('<div/>').terminal($.noop, {greetings: false});
it('should update terminal output', function() {
term.echo('Hello');
term.update(0, 'Hello, World!');
expect(term.find('.terminal-output').text()).toEqual(nbsp('Hello, World!'));
term.clear();
term.echo('Foo');
term.echo('Bar');
term.update(-1, 'Baz');
expect(term.find('.terminal-output').text()).toEqual('FooBaz');
term.update(-2, 'Lorem');
term.update(1, 'Ipsum');
expect(term.find('.terminal-output').text()).toEqual('LoremIpsum');
});
});
describe('last_index', function() {
var term = $('<div/>').terminal($.noop, {greetings: false});
it('should return proper index', function() {
Expand Down Expand Up @@ -6613,19 +6687,47 @@ describe('Terminal plugin', function() {
});
});
describe('update', function() {
var term = $('<div/>').terminal();
var term = $('<div/>').terminal($.noop, {greetings: false});
function last_line() {
return last_div().find('div');
}
function last_div() {
return term.find('.terminal-output > div:last-child');
}
beforeEach(function() {
term.clear();
});
it('should update terminal output', function() {
term.echo('Hello');
term.update(0, 'Hello, World!');
expect(term.find('.terminal-output').text()).toEqual(nbsp('Hello, World!'));
term.clear();
term.echo('Foo');
term.echo('Bar');
term.update(-1, 'Baz');
expect(term.find('.terminal-output').text()).toEqual('FooBaz');
term.update(-2, 'Lorem');
term.update(1, 'Ipsum');
expect(term.find('.terminal-output').text()).toEqual('LoremIpsum');
});
it('should update last line', function() {
term.echo('foo');
expect(last_line().text()).toEqual('foo');
term.update(-1, 'bar');
expect(last_line().text()).toEqual('bar');
});
it('should allow attributes in formatting from echo', function() {
var f = $.terminal.defaults.formatters.slice();
$.terminal.defaults.formatters.push([
/foo/g, '[[;;;;;{"style": "color:#fff"}]foo]'
]);
$.terminal.defaults.allowedAttributes.push('style');
term.echo('hello');
term.update(-1, 'foo', {});
expect(last_line().find('[style*="color"]').length).toEqual(1);
$.terminal.defaults.formatters = f;
$.terminal.defaults.allowedAttributes.pop();
});
it('should remove last line', function() {
var index = term.last_index();
term.echo('quux');
Expand All @@ -6637,6 +6739,7 @@ describe('Terminal plugin', function() {
var options = {
finalize: function() {}
};
term.echo('hello');
spy(options, 'finalize');
term.update(-1, 'baz', options);
expect(options.finalize).toHaveBeenCalled();
Expand Down
Loading

0 comments on commit 70eed4d

Please sign in to comment.