Change normal options.limit type to array.

This commit is contained in:
anseki 2015-04-05 18:11:30 +09:00
parent de4f2b2ffd
commit e521609b5e
2 changed files with 36 additions and 20 deletions

View file

@ -81,7 +81,7 @@ readlineSync.setPrompt({
toString: function() {
return '[' + require('path').basename(process.cwd()) + ']# '; // Get and show current directory.
}
})
});
```
### setPrint

View file

@ -23,7 +23,7 @@ var
prompt: '> ',
noEchoBack: false,
mask: '*',
limit: '',
limit: [],
caseSensitive: false,
noTrim: false,
encoding: 'utf8',
@ -36,7 +36,7 @@ var
extHostPath, extHostArgs, tempdir, salt = 0;
/*
display: other (to string)
display: string
keyIn: boolean
noEchoBack: boolean
mask: string
@ -45,8 +45,8 @@ var
noTrim: boolean
encoding, bufferSize, print
*/
function _readlineSync(options) {
var input = '', displaySave = (options.display += ''),
function _readlineSync(options) {return options;
var input = '', displaySave = options.display,
silent = !options.display && options.keyIn && options.noEchoBack && !options.mask;
function tryExt() {
@ -414,7 +414,6 @@ function margeOptions() {
// _readlineSync defaultOptions
// string
case 'mask': // * *
case 'limit': // * *
case 'encoding': // * *
/* jshint eqnull:true */
options[optionName] = value != null ? value + '' : '';
@ -436,9 +435,19 @@ function margeOptions() {
case 'print': // * *
options[optionName] = typeof value === 'function' ? value : void 0;
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
case 'prompt': // *
case 'display': // *
case 'display': // * readlineExt
/* jshint eqnull:true */
options[optionName] = value != null ? value : '';
/* jshint eqnull:false */
@ -466,30 +475,37 @@ function flattenArray(array, validate) {
exports._useExtSet = function(use) { useExt = use; };
exports.prompt = function(options) {
var readOptions = margeOptions(true, options);
readOptions.display = readOptions.prompt;
return _readlineSync(readOptions);
var readOptions = margeOptions(true, options),
limit = readOptions.limit, res;
readOptions.display = readOptions.prompt + '';
readOptions.limit = ''; // for readlineExt
res = _readlineSync(readOptions);
return res;
};
exports.question = function(query, options) {
var readOptions = margeOptions(margeOptions(true, options), {
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) {
var limit = 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), {
var readOptions = margeOptions(margeOptions(true, options), {
display: query,
keyIn: true,
limit: limit,
noTrim: true
});
return _readlineSync(readOptions);
}), res;
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) {