Change normal options.limit
type to array.
This commit is contained in:
parent
de4f2b2ffd
commit
e521609b5e
2 changed files with 36 additions and 20 deletions
|
@ -81,7 +81,7 @@ readlineSync.setPrompt({
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '[' + require('path').basename(process.cwd()) + ']# '; // Get and show current directory.
|
return '[' + require('path').basename(process.cwd()) + ']# '; // Get and show current directory.
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### setPrint
|
### setPrint
|
||||||
|
|
|
@ -23,7 +23,7 @@ var
|
||||||
prompt: '> ',
|
prompt: '> ',
|
||||||
noEchoBack: false,
|
noEchoBack: false,
|
||||||
mask: '*',
|
mask: '*',
|
||||||
limit: '',
|
limit: [],
|
||||||
caseSensitive: false,
|
caseSensitive: false,
|
||||||
noTrim: false,
|
noTrim: false,
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
|
@ -36,7 +36,7 @@ var
|
||||||
extHostPath, extHostArgs, tempdir, salt = 0;
|
extHostPath, extHostArgs, tempdir, salt = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
display: other (to string)
|
display: string
|
||||||
keyIn: boolean
|
keyIn: boolean
|
||||||
noEchoBack: boolean
|
noEchoBack: boolean
|
||||||
mask: string
|
mask: string
|
||||||
|
@ -45,8 +45,8 @@ var
|
||||||
noTrim: boolean
|
noTrim: boolean
|
||||||
encoding, bufferSize, print
|
encoding, bufferSize, print
|
||||||
*/
|
*/
|
||||||
function _readlineSync(options) {
|
function _readlineSync(options) {return options;
|
||||||
var input = '', displaySave = (options.display += ''),
|
var input = '', displaySave = options.display,
|
||||||
silent = !options.display && options.keyIn && options.noEchoBack && !options.mask;
|
silent = !options.display && options.keyIn && options.noEchoBack && !options.mask;
|
||||||
|
|
||||||
function tryExt() {
|
function tryExt() {
|
||||||
|
@ -414,7 +414,6 @@ function margeOptions() {
|
||||||
// _readlineSync defaultOptions
|
// _readlineSync defaultOptions
|
||||||
// string
|
// string
|
||||||
case 'mask': // * *
|
case 'mask': // * *
|
||||||
case 'limit': // * *
|
|
||||||
case 'encoding': // * *
|
case 'encoding': // * *
|
||||||
/* jshint eqnull:true */
|
/* jshint eqnull:true */
|
||||||
options[optionName] = value != null ? value + '' : '';
|
options[optionName] = value != null ? value + '' : '';
|
||||||
|
@ -436,9 +435,19 @@ function margeOptions() {
|
||||||
case 'print': // * *
|
case 'print': // * *
|
||||||
options[optionName] = typeof value === 'function' ? value : void 0;
|
options[optionName] = typeof value === 'function' ? value : void 0;
|
||||||
break;
|
break;
|
||||||
|
// array
|
||||||
|
case 'limit': // * * readlineExt
|
||||||
|
/* jshint eqnull:true */
|
||||||
|
options[optionName] = value != null ?
|
||||||
|
flattenArray(value, function(value) {
|
||||||
|
return typeof value === 'string' || typeof value === 'number' ||
|
||||||
|
value instanceof RegExp;
|
||||||
|
}) : [];
|
||||||
|
/* jshint eqnull:false */
|
||||||
|
break;
|
||||||
// other
|
// other
|
||||||
case 'prompt': // *
|
case 'prompt': // *
|
||||||
case 'display': // *
|
case 'display': // * readlineExt
|
||||||
/* jshint eqnull:true */
|
/* jshint eqnull:true */
|
||||||
options[optionName] = value != null ? value : '';
|
options[optionName] = value != null ? value : '';
|
||||||
/* jshint eqnull:false */
|
/* jshint eqnull:false */
|
||||||
|
@ -466,30 +475,37 @@ function flattenArray(array, validate) {
|
||||||
exports._useExtSet = function(use) { useExt = use; };
|
exports._useExtSet = function(use) { useExt = use; };
|
||||||
|
|
||||||
exports.prompt = function(options) {
|
exports.prompt = function(options) {
|
||||||
var readOptions = margeOptions(true, options);
|
var readOptions = margeOptions(true, options),
|
||||||
readOptions.display = readOptions.prompt;
|
limit = readOptions.limit, res;
|
||||||
return _readlineSync(readOptions);
|
readOptions.display = readOptions.prompt + '';
|
||||||
|
readOptions.limit = ''; // for readlineExt
|
||||||
|
res = _readlineSync(readOptions);
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.question = function(query, options) {
|
exports.question = function(query, options) {
|
||||||
var readOptions = margeOptions(margeOptions(true, options), {
|
var readOptions = margeOptions(margeOptions(true, options), {
|
||||||
display: query
|
display: query
|
||||||
});
|
}),
|
||||||
return _readlineSync(readOptions);
|
limit = readOptions.limit, res;
|
||||||
|
readOptions.display += '';
|
||||||
|
readOptions.limit = ''; // for readlineExt
|
||||||
|
res = _readlineSync(readOptions);
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.keyIn = function(query, options) {
|
exports.keyIn = function(query, options) {
|
||||||
var limit = options ?
|
var readOptions = margeOptions(margeOptions(true, options), {
|
||||||
flattenArray(options.limit, function(value)
|
|
||||||
{ return typeof value === 'string' || typeof value === 'number'; })
|
|
||||||
.join('').replace(/\n/g, '').replace(/[^A-Za-z0-9_ ]/g, '\\$&') : '',
|
|
||||||
readOptions = margeOptions(margeOptions(true, options), {
|
|
||||||
display: query,
|
display: query,
|
||||||
keyIn: true,
|
keyIn: true,
|
||||||
limit: limit,
|
|
||||||
noTrim: true
|
noTrim: true
|
||||||
});
|
}), res;
|
||||||
return _readlineSync(readOptions);
|
readOptions.display += '';
|
||||||
|
readOptions.limit = readOptions.limit.filter(function(value)
|
||||||
|
{ return typeof value === 'string' || typeof value === 'number'; })
|
||||||
|
.join('').replace(/\n/g, '').replace(/[^A-Za-z0-9_ ]/g, '\\$&');
|
||||||
|
res = _readlineSync(readOptions);
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setDefault = function(options) {
|
exports.setDefault = function(options) {
|
||||||
|
|
Loading…
Reference in a new issue