Skip to content

Commit

Permalink
allow promise in renderHandler + expose AnsiParser from unix_formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 3, 2020
1 parent c559754 commit 60946de
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 180 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 2.12.1
### Features
* allow to return promise from renderHandler
* allow to extend the ansiParser in unix_formatting
### Bugfix
* fix selecting textarea content when selecting cmd
* fix possible loops in renderHandler

## 2.12.0
### Features
Expand Down
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&f070bacfbe26f4e415bef68cb70755777bfc574a)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&b7ada3884d47f626d4bc4928150422dc)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&c559754e85a2e26b1cf6382eb449bb1d150139a8)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&2e2eaf6e584f1373ecdd1e51137dbd22)](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
6 changes: 3 additions & 3 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5650,16 +5650,16 @@ describe('Terminal plugin', function() {
expect(count(interpreter.foo)).toEqual(1);
expect(term.find('.terminal-error').length).toEqual(1);
expect(a0(term.find('.terminal-error').text()))
.toEqual($.terminal.defaults.strings.recursiveCall);
.toEqual($.terminal.defaults.strings.recursiveLoop);
term.echo('[[ foo ]]');
expect(count(interpreter.foo)).toEqual(2);
expect(term.find('.terminal-error').length).toEqual(2);
var output = term.find('.terminal-error').map(function() {
return a0($(this).text());
}).get();
expect(output).toEqual([
$.terminal.defaults.strings.recursiveCall,
$.terminal.defaults.strings.recursiveCall
$.terminal.defaults.strings.recursiveLoop,
$.terminal.defaults.strings.recursiveLoop
]);
});
});
Expand Down
49 changes: 28 additions & 21 deletions js/jquery.terminal-2.12.0.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, 02 Jan 2020 09:26:53 +0000
* Date: Fri, 03 Jan 2020 14:21:41 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -992,7 +992,7 @@
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value) {
if (value !== undefined) {
if (is_function(value.catch)) {
value.catch(error);
}
Expand Down Expand Up @@ -4138,7 +4138,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Thu, 02 Jan 2020 09:26:53 +0000',
date: 'Fri, 03 Jan 2020 14:21:41 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -5798,6 +5798,10 @@
return get_type(object) === 'function';
}
// -----------------------------------------------------------------------
function is_promise(object) {
return is_function(object && (object.then || object.done));
}
// -----------------------------------------------------------------------
function is_array(object) {
return get_type(object) === 'array';
}
Expand Down Expand Up @@ -5913,6 +5917,7 @@
onRPCError: null,
doubleTab: null,
doubleTabEchoCommand: false,
ansiParser: {},
completion: false,
onInit: $.noop,
onClear: $.noop,
Expand Down Expand Up @@ -5964,7 +5969,7 @@
invalidTerminalId: 'Invalid Terminal ID',
login: 'login',
password: 'password',
recursiveCall: 'Recursive call detected, skip',
recursiveLoop: 'Recursive loop in echo detected, skip',
notAString: '%s function: argument is not a string',
redrawError: 'Internal error, wrong position in cmd redraw',
invalidStrings: 'Command %s have unclosed strings',
Expand Down Expand Up @@ -6035,7 +6040,7 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret)) {
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
return ret;
} else {
return value;
Expand Down Expand Up @@ -6798,7 +6803,7 @@
var trim = string.trim();
if (prev_exec_cmd && prev_exec_cmd === trim) {
prev_exec_cmd = '';
self.error(strings().recursiveCall);
self.error(strings().recursiveLoop);
} else {
prev_exec_cmd = trim;
$.terminal.extended_command(self, string, {
Expand Down Expand Up @@ -8717,22 +8722,24 @@
}
value = ret;
}
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
unpromise(value, function(value) {
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
} catch (e) {
// if echo throw exception we can't use error to
// display that exception
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-2.12.0.min.js

Large diffs are not rendered by default.

45 changes: 26 additions & 19 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value) {
if (value !== undefined) {
if (is_function(value.catch)) {
value.catch(error);
}
Expand Down Expand Up @@ -5798,6 +5798,10 @@
return get_type(object) === 'function';
}
// -----------------------------------------------------------------------
function is_promise(object) {
return is_function(object && (object.then || object.done));
}
// -----------------------------------------------------------------------
function is_array(object) {
return get_type(object) === 'array';
}
Expand Down Expand Up @@ -5913,6 +5917,7 @@
onRPCError: null,
doubleTab: null,
doubleTabEchoCommand: false,
ansiParser: {},
completion: false,
onInit: $.noop,
onClear: $.noop,
Expand Down Expand Up @@ -5964,7 +5969,7 @@
invalidTerminalId: 'Invalid Terminal ID',
login: 'login',
password: 'password',
recursiveCall: 'Recursive call detected, skip',
recursiveLoop: 'Recursive loop in echo detected, skip',
notAString: '%s function: argument is not a string',
redrawError: 'Internal error, wrong position in cmd redraw',
invalidStrings: 'Command %s have unclosed strings',
Expand Down Expand Up @@ -6035,7 +6040,7 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret)) {
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
return ret;
} else {
return value;
Expand Down Expand Up @@ -6798,7 +6803,7 @@
var trim = string.trim();
if (prev_exec_cmd && prev_exec_cmd === trim) {
prev_exec_cmd = '';
self.error(strings().recursiveCall);
self.error(strings().recursiveLoop);
} else {
prev_exec_cmd = trim;
$.terminal.extended_command(self, string, {
Expand Down Expand Up @@ -8717,22 +8722,24 @@
}
value = ret;
}
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
unpromise(value, function(value) {
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
} catch (e) {
// if echo throw exception we can't use error to
// display that exception
Expand Down
49 changes: 28 additions & 21 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, 02 Jan 2020 09:26:53 +0000
* Date: Fri, 03 Jan 2020 14:21:41 +0000
*/
/* global location, setTimeout, window, global, sprintf, setImmediate,
IntersectionObserver, ResizeObserver, module, require, define,
Expand Down Expand Up @@ -992,7 +992,7 @@
}
// -----------------------------------------------------------------------
function unpromise(value, callback, error) {
if (value) {
if (value !== undefined) {
if (is_function(value.catch)) {
value.catch(error);
}
Expand Down Expand Up @@ -4138,7 +4138,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Thu, 02 Jan 2020 09:26:53 +0000',
date: 'Fri, 03 Jan 2020 14:21:41 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -5798,6 +5798,10 @@
return get_type(object) === 'function';
}
// -----------------------------------------------------------------------
function is_promise(object) {
return is_function(object && (object.then || object.done));
}
// -----------------------------------------------------------------------
function is_array(object) {
return get_type(object) === 'array';
}
Expand Down Expand Up @@ -5913,6 +5917,7 @@
onRPCError: null,
doubleTab: null,
doubleTabEchoCommand: false,
ansiParser: {},
completion: false,
onInit: $.noop,
onClear: $.noop,
Expand Down Expand Up @@ -5964,7 +5969,7 @@
invalidTerminalId: 'Invalid Terminal ID',
login: 'login',
password: 'password',
recursiveCall: 'Recursive call detected, skip',
recursiveLoop: 'Recursive loop in echo detected, skip',
notAString: '%s function: argument is not a string',
redrawError: 'Internal error, wrong position in cmd redraw',
invalidStrings: 'Command %s have unclosed strings',
Expand Down Expand Up @@ -6035,7 +6040,7 @@
if (ret === false) {
return false;
}
if (typeof ret === 'string' || is_node(ret)) {
if (typeof ret === 'string' || is_node(ret) || is_promise(ret)) {
return ret;
} else {
return value;
Expand Down Expand Up @@ -6798,7 +6803,7 @@
var trim = string.trim();
if (prev_exec_cmd && prev_exec_cmd === trim) {
prev_exec_cmd = '';
self.error(strings().recursiveCall);
self.error(strings().recursiveLoop);
} else {
prev_exec_cmd = trim;
$.terminal.extended_command(self, string, {
Expand Down Expand Up @@ -8717,22 +8722,24 @@
}
value = ret;
}
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
unpromise(value, function(value) {
if (render(value, locals)) {
return self;
}
process_line({
value: value,
options: locals,
index: lines.length
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
});
// extended commands should be processed only
// once in echo and not on redraw
locals.exec = false;
lines.push([value, locals]);
if (locals.flush) {
self.flush();
fire_event('onAfterEcho', [arg]);
}
} catch (e) {
// if echo throw exception we can't use error to
// display that exception
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 60946de

Please sign in to comment.