Skip to content

Commit

Permalink
better read method #397
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 21, 2018
1 parent 926d9c4 commit c0cc3cd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 35 deletions.
36 changes: 25 additions & 11 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: Mon, 21 May 2018 07:39:35 +0000
* Date: Mon, 21 May 2018 08:58:52 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2872,7 +2872,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Mon, 21 May 2018 07:39:35 +0000',
date: 'Mon, 21 May 2018 08:58:52 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -6695,18 +6695,32 @@
// -------------------------------------------------------------
// :: wrapper for common use case
// -------------------------------------------------------------
read: function(message, callback) {
var d = new $.Deferred();
self.push(function(text) {
self.pop();
if ($.isFunction(callback)) {
callback(text);
read: function(message, success, cancel) {
var defer = jQuery.Deferred();
var history = self.history();
var read = false;
history.disable();
self.push(function(string) {
read = true;
defer.resolve(string);
if ($.isFunction(success)) {
success(string);
}
d.resolve(text);
self.pop();
}, {
prompt: message
name: 'read',
prompt: prompt || '',
onExit: function() {
if (!read) {
defer.reject();
if ($.isFunction(cancel)) {
cancel();
}
}
history.enable();
}
});
return d.promise();
return defer.promise();
},
// -------------------------------------------------------------
// :: Push a new interenter on the Stack
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-1.15.0.min.js

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -6695,18 +6695,32 @@
// -------------------------------------------------------------
// :: wrapper for common use case
// -------------------------------------------------------------
read: function(message, callback) {
var d = new $.Deferred();
self.push(function(text) {
self.pop();
if ($.isFunction(callback)) {
callback(text);
read: function(message, success, cancel) {
var defer = jQuery.Deferred();
var history = self.history();
var read = false;
history.disable();
self.push(function(string) {
read = true;
defer.resolve(string);
if ($.isFunction(success)) {
success(string);
}
d.resolve(text);
self.pop();
}, {
prompt: message
name: 'read',
prompt: prompt || '',
onExit: function() {
if (!read) {
defer.reject();
if ($.isFunction(cancel)) {
cancel();
}
}
history.enable();
}
});
return d.promise();
return defer.promise();
},
// -------------------------------------------------------------
// :: Push a new interenter on the Stack
Expand Down
36 changes: 25 additions & 11 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: Mon, 21 May 2018 07:39:35 +0000
* Date: Mon, 21 May 2018 08:58:52 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2872,7 +2872,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Mon, 21 May 2018 07:39:35 +0000',
date: 'Mon, 21 May 2018 08:58:52 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -6695,18 +6695,32 @@
// -------------------------------------------------------------
// :: wrapper for common use case
// -------------------------------------------------------------
read: function(message, callback) {
var d = new $.Deferred();
self.push(function(text) {
self.pop();
if ($.isFunction(callback)) {
callback(text);
read: function(message, success, cancel) {
var defer = jQuery.Deferred();
var history = self.history();
var read = false;
history.disable();
self.push(function(string) {
read = true;
defer.resolve(string);
if ($.isFunction(success)) {
success(string);
}
d.resolve(text);
self.pop();
}, {
prompt: message
name: 'read',
prompt: prompt || '',
onExit: function() {
if (!read) {
defer.reject();
if ($.isFunction(cancel)) {
cancel();
}
}
history.enable();
}
});
return d.promise();
return defer.promise();
},
// -------------------------------------------------------------
// :: Push a new interenter on the Stack
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

0 comments on commit c0cc3cd

Please sign in to comment.