Skip to content

Commit

Permalink
add animation to exec #679
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Aug 12, 2021
1 parent 0cf3464 commit 6cd6706
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 66 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.29.0
### Feature
* add animation to exec [#679](https://github.com/jcubic/jquery.terminal/issues/679)

## 2.28.1
### Bugfix
* fix applying style of text-decoration (e.g. underline)
Expand Down
65 changes: 45 additions & 20 deletions js/jquery.terminal-2.28.1.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: Wed, 04 Aug 2021 06:57:27 +0000
* Date: Thu, 12 Aug 2021 09:40:51 +0000
*/
/* global define, Map */
/* eslint-disable */
Expand Down Expand Up @@ -4797,7 +4797,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: '2.28.1',
date: 'Wed, 04 Aug 2021 06:57:27 +0000',
date: 'Thu, 12 Aug 2021 09:40: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 @@ -8680,37 +8680,62 @@
// :: Execute a command, it will handle commands that do AJAX
// :: calls and have delays, if the second argument is set to
// :: true it will not echo executed command
// -------------------------------------------------------------
exec: function(command, silent, deferred) {
var d = deferred || new $.Deferred();
// :: if second argument is object is used as options
// -------------------------------------------------------------
exec: function(command, silent, options) {
function invoke(silent) {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
});
}
if (silent && typeof silent === 'object') {
options = silent;
silent = null;
}
var settings = $.extend({
deferred: new $.Deferred(),
silent: false,
typing: false,
delay: 100
}, options);
if (silent === null) {
silent = settings.silent;
}
var d = settings.deferred;
cmd_ready(function ready() {
if ($.isArray(command)) {
(function recur() {
var cmd = command.shift();
if (cmd) {
self.exec(cmd, silent).done(recur);
self.exec(cmd, silent, options).done(recur);
} else {
d.resolve();
}
})();
} else if (paused) {
// both commands executed here (resume will call Term::exec)
// delay command multiple time
delayed_commands.push([command, silent, d]);
} else {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
delayed_commands.push([command, silent, settings]);
} else if (settings.typing && !silent) {
var delay = settings.delay;
var ret = self.typing('enter', delay, command, {
delay: delay
});
ret.then(function() {
invoke(true);
});
} else {
invoke(silent);
}
});
// while testing it didn't executed last exec when using this
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-2.28.1.min.js

Large diffs are not rendered by default.

61 changes: 43 additions & 18 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -8680,37 +8680,62 @@
// :: Execute a command, it will handle commands that do AJAX
// :: calls and have delays, if the second argument is set to
// :: true it will not echo executed command
// -------------------------------------------------------------
exec: function(command, silent, deferred) {
var d = deferred || new $.Deferred();
// :: if second argument is object is used as options
// -------------------------------------------------------------
exec: function(command, silent, options) {
function invoke(silent) {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
});
}
if (silent && typeof silent === 'object') {
options = silent;
silent = null;
}
var settings = $.extend({
deferred: new $.Deferred(),
silent: false,
typing: false,
delay: 100
}, options);
if (silent === null) {
silent = settings.silent;
}
var d = settings.deferred;
cmd_ready(function ready() {
if ($.isArray(command)) {
(function recur() {
var cmd = command.shift();
if (cmd) {
self.exec(cmd, silent).done(recur);
self.exec(cmd, silent, options).done(recur);
} else {
d.resolve();
}
})();
} else if (paused) {
// both commands executed here (resume will call Term::exec)
// delay command multiple time
delayed_commands.push([command, silent, d]);
} else {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
delayed_commands.push([command, silent, settings]);
} else if (settings.typing && !silent) {
var delay = settings.delay;
var ret = self.typing('enter', delay, command, {
delay: delay
});
ret.then(function() {
invoke(true);
});
} else {
invoke(silent);
}
});
// while testing it didn't executed last exec when using this
Expand Down
11 changes: 9 additions & 2 deletions js/jquery.terminal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ declare namespace JQueryTerminal {

type ExtendedPrompt = ((this: JQueryTerminal, setPrompt: setStringFunction) => (void | PromiseLike<string>)) | string;

type execOptions = {
typing?: boolean;
delay?: number;
silent?: boolean;
deferred?: JQuery.Deferred<void>
}

type pushOptions = {
infiniteLogin?: boolean;
prompt?: ExtendedPrompt;
Expand Down Expand Up @@ -397,7 +404,7 @@ declare namespace JQueryTerminal {
items: {[key: string]: any};
name?: string;
}

type formData = Array<simpleInput | passwordInput | checkboxesInput | radioInput>;
}

Expand Down Expand Up @@ -719,7 +726,7 @@ interface JQueryTerminal<TElement = HTMLElement> extends JQuery<TElement> {
export_view(): JQueryTerminal.View;
import_view(view: JQueryTerminal.View): JQueryTerminal;
save_state(command?: string, ignore_hash?: boolean, index?: number): JQueryTerminal;
exec(command: string, silent?: boolean, deferred?: JQuery.Deferred<void>): JQuery.Promise<void>;
exec(command: string, silent_or_options?: boolean | JQueryTerminal.execOptions, options?: JQueryTerminal.execOptions): JQuery.Promise<void>;
autologin(user: string, token: string, silent?: boolean): JQueryTerminal;
// there is success and error callbacks because we call this function from terminal and auth function can
// be created by user
Expand Down
65 changes: 45 additions & 20 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: Wed, 04 Aug 2021 06:57:27 +0000
* Date: Thu, 12 Aug 2021 09:40:51 +0000
*/
/* global define, Map */
/* eslint-disable */
Expand Down Expand Up @@ -4797,7 +4797,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: '2.28.1',
date: 'Wed, 04 Aug 2021 06:57:27 +0000',
date: 'Thu, 12 Aug 2021 09:40: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 @@ -8680,37 +8680,62 @@
// :: Execute a command, it will handle commands that do AJAX
// :: calls and have delays, if the second argument is set to
// :: true it will not echo executed command
// -------------------------------------------------------------
exec: function(command, silent, deferred) {
var d = deferred || new $.Deferred();
// :: if second argument is object is used as options
// -------------------------------------------------------------
exec: function(command, silent, options) {
function invoke(silent) {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
});
}
if (silent && typeof silent === 'object') {
options = silent;
silent = null;
}
var settings = $.extend({
deferred: new $.Deferred(),
silent: false,
typing: false,
delay: 100
}, options);
if (silent === null) {
silent = settings.silent;
}
var d = settings.deferred;
cmd_ready(function ready() {
if ($.isArray(command)) {
(function recur() {
var cmd = command.shift();
if (cmd) {
self.exec(cmd, silent).done(recur);
self.exec(cmd, silent, options).done(recur);
} else {
d.resolve();
}
})();
} else if (paused) {
// both commands executed here (resume will call Term::exec)
// delay command multiple time
delayed_commands.push([command, silent, d]);
} else {
// commands may return promise from user code
// it will resolve exec promise when user promise
// is resolved
var ret = commands(command, silent, true);
unpromise(ret, function() {
// reset prev command for push called after exec
// so push didn't get name/prompt from exec command
prev_command = null;
d.resolve();
}, function() {
prev_command = null;
d.reject();
delayed_commands.push([command, silent, settings]);
} else if (settings.typing && !silent) {
var delay = settings.delay;
var ret = self.typing('enter', delay, command, {
delay: delay
});
ret.then(function() {
invoke(true);
});
} else {
invoke(silent);
}
});
// while testing it didn't executed last exec when using this
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.

4 changes: 3 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ $.terminal.defaults.formatters.push(red);
// -------------------------------------------------------------------------
term.exec("foo");
term.exec("foo", true);
term.exec("foo", true, jQuery.Deferred()).then(function() {
term.exec("foo", true, {typing: true, delay: 200}).then(function() {
});
term.exec("foo", {silent: true, typing: true, delay: 200}).then(function() {
});
// -------------------------------------------------------------------------
// :: autologin
Expand Down

0 comments on commit 6cd6706

Please sign in to comment.