Skip to content

Commit

Permalink
fix returning Terminal instance from interpreter #994
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 19, 2025
1 parent d886d78 commit ca1e69c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* improve mobile support
* ignore empty command in Pipe extension [#984](https://github.com/jcubic/jquery.terminal/issues/984)
* fix processing Hex HTML entities [#992](https://github.com/jcubic/jquery.terminal/issues/992)
* fix returning Terminal instance from interpreter [#994](https://github.com/jcubic/jquery.terminal/issues/994)

## 2.44.1
### Bugfix
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![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)
[![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)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&30337a9afb55435af852014140b95ef5)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&98337d9e45365737fee0a9c68019ec79)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)
Expand Down
10 changes: 10 additions & 0 deletions __tests__/__snapshots__/terminal.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ exports[`Terminal plugin cmd plugin should move cursor 2`] = `

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>"`;

exports[`Terminal plugin interprer return should render array 1`] = `
"> cmd
"foo" "bar" 10"
`;

exports[`Terminal plugin interprer return should rener promise of array 1`] = `
"> cmd
"foo" "bar" 10"
`;

exports[`Terminal plugin jQuery Terminal methods exec should invoke array of commands when each command pause terminal 1`] = `
"> exec_async_array
> async_command 0
Expand Down
40 changes: 40 additions & 0 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,46 @@ describe('Terminal plugin', function() {
}).toThrow(error);
});
});
describe('interprer return', () => {
let term;
beforeEach(() => {
term = $('<div/>').appendTo('body').terminal({}, {
greetings: false
});
});
afterEach(() => {
term.destroy().remove();
});
function render(value) {
term.push(function() {
return value;
});
term.exec('cmd');
}
it('should render jQuery object', () => {
const node = $('<span class="x">hello</span>');
render(node);
expect(term.find('.x').is(node)).toBeTruthy();
});
it('should ignore Terminal instance', () => {
render(term);
expect(term.closest('body').length).toBe(1);
});
it('should render a promise', async () => {
render(Promise.resolve(10));
await term.delay(0);
expect(term.get_output()).toEqual('> cmd\n10');
});
it('should rener promise of array', async () => {
render(Promise.resolve(['foo', 'bar', 10]));
await term.delay(0);
expect(term.get_output()).toMatchSnapshot();
});
it('should render array', () => {
render(['foo', 'bar', 10]);
expect(term.get_output()).toMatchSnapshot();
});
});
describe('cursor', function() {
it('only one terminal should have blinking cursor', function() {
var term1 = $('<div/>').appendTo('body').terminal($.noop);
Expand Down
3 changes: 2 additions & 1 deletion js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -8849,7 +8849,8 @@
}
// -----------------------------------------------------------------
function show(result, promise) {
if (typeof result !== 'undefined') {
// don't attempt to return terminal instance #994
if (typeof result !== 'undefined' && result !== self) {
display_object(result);
}
after_exec();
Expand Down
7 changes: 4 additions & 3 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: Tue, 14 Jan 2025 23:23:39 +0000
* Date: Sun, 19 Jan 2025 22:25:51 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -5436,7 +5436,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Tue, 14 Jan 2025 23:23:39 +0000',
date: 'Sun, 19 Jan 2025 22:25:51 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -8849,7 +8849,8 @@
}
// -----------------------------------------------------------------
function show(result, promise) {
if (typeof result !== 'undefined') {
// don't attempt to return terminal instance #994
if (typeof result !== 'undefined' && result !== self) {
display_object(result);
}
after_exec();
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 ca1e69c

Please sign in to comment.