Skip to content

Commit ca1e69c

Browse files
committed
fix returning Terminal instance from interpreter #994
1 parent d886d78 commit ca1e69c

8 files changed

+61
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* improve mobile support
1313
* ignore empty command in Pipe extension [#984](https://github.com/jcubic/jquery.terminal/issues/984)
1414
* fix processing Hex HTML entities [#992](https://github.com/jcubic/jquery.terminal/issues/992)
15+
* fix returning Terminal instance from interpreter [#994](https://github.com/jcubic/jquery.terminal/issues/994)
1516

1617
## 2.44.1
1718
### Bugfix

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
99
![bower](https://img.shields.io/badge/bower-DEV-yellow.svg)
1010
[![Build and test](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml)
11-
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&30337a9afb55435af852014140b95ef5)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
11+
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&98337d9e45365737fee0a9c68019ec79)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
1212
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
1313
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
1414
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)

__tests__/__snapshots__/terminal.spec.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ exports[`Terminal plugin cmd plugin should move cursor 2`] = `
5858

5959
exports[`Terminal plugin events enter text text should appear and interpreter function should be called 1`] = `"<span data-text=">&nbsp;foo">&gt;&nbsp;foo</span>"`;
6060

61+
exports[`Terminal plugin interprer return should render array 1`] = `
62+
"> cmd
63+
"foo" "bar" 10"
64+
`;
65+
66+
exports[`Terminal plugin interprer return should rener promise of array 1`] = `
67+
"> cmd
68+
"foo" "bar" 10"
69+
`;
70+
6171
exports[`Terminal plugin jQuery Terminal methods exec should invoke array of commands when each command pause terminal 1`] = `
6272
"> exec_async_array
6373
> async_command 0

__tests__/terminal.spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,46 @@ describe('Terminal plugin', function() {
36823682
}).toThrow(error);
36833683
});
36843684
});
3685+
describe('interprer return', () => {
3686+
let term;
3687+
beforeEach(() => {
3688+
term = $('<div/>').appendTo('body').terminal({}, {
3689+
greetings: false
3690+
});
3691+
});
3692+
afterEach(() => {
3693+
term.destroy().remove();
3694+
});
3695+
function render(value) {
3696+
term.push(function() {
3697+
return value;
3698+
});
3699+
term.exec('cmd');
3700+
}
3701+
it('should render jQuery object', () => {
3702+
const node = $('<span class="x">hello</span>');
3703+
render(node);
3704+
expect(term.find('.x').is(node)).toBeTruthy();
3705+
});
3706+
it('should ignore Terminal instance', () => {
3707+
render(term);
3708+
expect(term.closest('body').length).toBe(1);
3709+
});
3710+
it('should render a promise', async () => {
3711+
render(Promise.resolve(10));
3712+
await term.delay(0);
3713+
expect(term.get_output()).toEqual('> cmd\n10');
3714+
});
3715+
it('should rener promise of array', async () => {
3716+
render(Promise.resolve(['foo', 'bar', 10]));
3717+
await term.delay(0);
3718+
expect(term.get_output()).toMatchSnapshot();
3719+
});
3720+
it('should render array', () => {
3721+
render(['foo', 'bar', 10]);
3722+
expect(term.get_output()).toMatchSnapshot();
3723+
});
3724+
});
36853725
describe('cursor', function() {
36863726
it('only one terminal should have blinking cursor', function() {
36873727
var term1 = $('<div/>').appendTo('body').terminal($.noop);

js/jquery.terminal-src.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8849,7 +8849,8 @@
88498849
}
88508850
// -----------------------------------------------------------------
88518851
function show(result, promise) {
8852-
if (typeof result !== 'undefined') {
8852+
// don't attempt to return terminal instance #994
8853+
if (typeof result !== 'undefined' && result !== self) {
88538854
display_object(result);
88548855
}
88558856
after_exec();

js/jquery.terminal.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* broken image by Sophia Bai from the Noun Project (CC-BY)
4343
*
44-
* Date: Tue, 14 Jan 2025 23:23:39 +0000
44+
* Date: Sun, 19 Jan 2025 22:25:51 +0000
4545
*/
4646
/* global define, Map, BigInt */
4747
/* eslint-disable */
@@ -5436,7 +5436,7 @@
54365436
// -------------------------------------------------------------------------
54375437
$.terminal = {
54385438
version: 'DEV',
5439-
date: 'Tue, 14 Jan 2025 23:23:39 +0000',
5439+
date: 'Sun, 19 Jan 2025 22:25:51 +0000',
54405440
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
54415441
color_names: [
54425442
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
@@ -8849,7 +8849,8 @@
88498849
}
88508850
// -----------------------------------------------------------------
88518851
function show(result, promise) {
8852-
if (typeof result !== 'undefined') {
8852+
// don't attempt to return terminal instance #994
8853+
if (typeof result !== 'undefined' && result !== self) {
88538854
display_object(result);
88548855
}
88558856
after_exec();

js/jquery.terminal.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/jquery.terminal.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)