Skip to content

Commit

Permalink
supports for promises returned from completion function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 17, 2018
1 parent 1f9c5fc commit 156945e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* allow to have limited import when export is save and restored from JSON [#393](https://github.com/jcubic/jquery.terminal/issues/393)
* add support for new u and s regex flags when parsing commands
* add less plugin based on the one from leash
* supports for promises returned from completion function

### Bugs
* fix resizer in Firefox [#395](https://github.com/jcubic/jquery.terminal/issues/395)
Expand Down
31 changes: 15 additions & 16 deletions js/jquery.terminal-1.15.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Thu, 17 May 2018 04:01:57 +0000
* Date: Thu, 17 May 2018 06:43:41 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2872,7 +2872,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Thu, 17 May 2018 04:01:57 +0000',
date: 'Thu, 17 May 2018 06:43:41 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -5303,6 +5303,14 @@
if (completion === 'settings') {
completion = settings.completion;
}
function resolve(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
}
if (completion) {
switch ($.type(completion)) {
case 'function':
Expand All @@ -5312,22 +5320,13 @@
display_exception(error, 'USER');
return false;
}
completion.call(self, string, function(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
});
var result = completion.call(self, string, resolve);
if (result && $.isFunction(result.then)) {
result.then(resolve);
}
break;
case 'array':
self.complete(completion, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
resolve(completion);
break;
default:
throw new Error(strings().invalidCompletion);
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-1.15.0.min.js

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -5303,6 +5303,14 @@
if (completion === 'settings') {
completion = settings.completion;
}
function resolve(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
}
if (completion) {
switch ($.type(completion)) {
case 'function':
Expand All @@ -5312,22 +5320,13 @@
display_exception(error, 'USER');
return false;
}
completion.call(self, string, function(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
});
var result = completion.call(self, string, resolve);
if (result && $.isFunction(result.then)) {
result.then(resolve);
}
break;
case 'array':
self.complete(completion, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
resolve(completion);
break;
default:
throw new Error(strings().invalidCompletion);
Expand Down
31 changes: 15 additions & 16 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Thu, 17 May 2018 04:01:57 +0000
* Date: Thu, 17 May 2018 06:43:41 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2872,7 +2872,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Thu, 17 May 2018 04:01:57 +0000',
date: 'Thu, 17 May 2018 06:43:41 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -5303,6 +5303,14 @@
if (completion === 'settings') {
completion = settings.completion;
}
function resolve(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
}
if (completion) {
switch ($.type(completion)) {
case 'function':
Expand All @@ -5312,22 +5320,13 @@
display_exception(error, 'USER');
return false;
}
completion.call(self, string, function(commands) {
self.complete(commands, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
});
var result = completion.call(self, string, resolve);
if (result && $.isFunction(result.then)) {
result.then(resolve);
}
break;
case 'array':
self.complete(completion, {
echo: true,
word: settings.wordAutocomplete,
escape: settings.completionEscape,
caseSensitive: caseSensitive
});
resolve(completion);
break;
default:
throw new Error(strings().invalidCompletion);
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions spec/terminalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,24 @@ function tests_on_ready() {
expect(term.get_command()).toEqual("asd \"foo 'bar' baz\"");
term.destroy().remove();
});
iit('should complete when function returm promise', function(done) {
term = $('<div/>').appendTo('body').terminal({}, {
completion: function() {
return new Promise(function(resolve) {
setTimeout(function() {
resolve(["foo", "bar", "baz"]);
}, 200);
});
}
});
term.focus();
term.insert('f');
shortcut(false, false, false, 9, 'tab');
setTimeout(function() {
expect(term.get_command()).toEqual("foo");
done();
}, 400);
});
});
describe('jQuery Terminal methods', function() {
var terminal_name = 'methods';
Expand Down

0 comments on commit 156945e

Please sign in to comment.