select-shell
Advanced tools
Comparing version 0.0.5 to 0.1.0
20
index.js
@@ -38,6 +38,9 @@ 'use strict'; | ||
checked: ' ✓', | ||
unchecked: '', | ||
checkedColor: 'green', | ||
msgCancel: 'No selected options!', | ||
msgCancelColor: 'red', | ||
multiSelect: true | ||
multiSelect: true, | ||
inverse: false, | ||
prepend: false | ||
}; | ||
@@ -85,7 +88,16 @@ this.options = []; | ||
me.options.forEach(function(option, position){ | ||
var prefix = ( position === me.pointerPosition ) ? me.config.pointer : me.config.pointer.replace(/[(\w\W)(\ )]/g, ' '), | ||
checked = me.optionsSelected.indexOf(option) !== -1 ? me.config.checked[ me.config.checkedColor ] : ''; | ||
var prefix = ( position === me.pointerPosition ) ? me.config.pointer | ||
: me.config.pointer.replace(/[(\w\W)(\ )]/g, ' ') | ||
var checked = me.optionsSelected.indexOf(option) !== -1 ? me.config.checked[ me.config.checkedColor ] | ||
: me.config.unchecked[ me.config.checkedColor ] | ||
me.currentoption = prefix.trim() ? option : me.currentoption; | ||
console.log( prefix[ me.config.pointerColor ] + option.text + checked ); | ||
console.log( prefix[ me.config.pointerColor ] + | ||
(me.config.prepend ? checked : '') + | ||
(position === me.pointerPosition && me.config.inverse ? option.text[ 'inverse' ] : option.text) + | ||
(me.config.prepend ? '' : checked) | ||
); | ||
}); | ||
@@ -92,0 +104,0 @@ processOut.write(encode('[?25l')); |
{ | ||
"name": "select-shell", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "list of select for nodejs on terminal.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,20 +23,28 @@ select-shell | ||
``` | ||
'use strict'; | ||
var selectShell = require('./index'); | ||
var list = require('./index')( | ||
/* possible configs */ | ||
{ | ||
pointer: ' ▸ ', | ||
pointerColor: 'yellow', | ||
checked: ' ◉ ', | ||
unchecked:' ◎ ', | ||
checkedColor: 'blue', | ||
msgCancel: 'No selected options!', | ||
msgCancelColor: 'orange', | ||
multiSelect: true, | ||
inverse: true, | ||
prepend: true | ||
} | ||
); | ||
var stream = process.stdin; | ||
var select = selectShell(); | ||
/* | ||
select.option(text, value) | ||
Value is optinal. The default value is equal the text. | ||
*/ | ||
select.option('One', 1) | ||
.option('Two', 2) | ||
.option('Three', 3) | ||
.select(); | ||
list.option(' One ') | ||
.option(' Two ') | ||
.option(' Three ') | ||
.list(); | ||
select.on('select', function(options){ | ||
/* Return the options selected. Ex.: [{ text: '', value: '' }] or { text: '', value: '' } depends the config multiSelect */ | ||
list.on('select', function(options){ | ||
console.log(options); | ||
@@ -46,5 +54,4 @@ process.exit(0); | ||
select.on('cancel', function(options){ | ||
/* Return the options selected. Ex.: [{ text: '', value: '' }] or { text: '', value: '' } depends the config multiSelect */ | ||
console.log('Cancel select, '+ options.length +' options selected'); | ||
list.on('cancel', function(options){ | ||
console.log('Cancel list, '+ options.length +' options selected'); | ||
process.exit(0); | ||
@@ -54,6 +61,9 @@ }); | ||
![select-shell example image](https://raw.github.com/mralexgray/select-shell/selection-options/sample.png) | ||
###Optional configs | ||
``` | ||
var select = require('select-shell)( | ||
/* Default values */ | ||
var select = require('select-shell')( | ||
/* These are the default values */ | ||
{ | ||
@@ -63,9 +73,13 @@ pointer: '> ', | ||
checked: ' ✓', | ||
unchecked: '', | ||
checkedColor: 'green', | ||
msgCancel: 'No selected options!', | ||
msgCancelColor: 'red', | ||
multiSelect: true | ||
multiSelect: true, | ||
inverse: false, | ||
prepend: false | ||
} | ||
); | ||
``` | ||
###The scheme of color is equal to the module [colors](https://github.com/Marak/colors.js "module colors"). | ||
@@ -87,2 +101,2 @@ | ||
- zebra | ||
- random | ||
- random |
'use strict'; | ||
var list = require('./index')(); | ||
var list = require('./index')( | ||
/* possible configs */ | ||
{ | ||
pointer: ' ▸ ', | ||
pointerColor: 'yellow', | ||
checked: ' ◉ ', | ||
unchecked:' ◎ ', | ||
checkedColor: 'blue', | ||
msgCancel: 'No selected options!', | ||
msgCancelColor: 'orange', | ||
multiSelect: true, | ||
inverse: true, | ||
prepend: true | ||
} | ||
); | ||
var stream = process.stdin; | ||
list.option('One') | ||
.option('Two') | ||
.option('Three') | ||
list.option(' One ') | ||
.option(' Two ') | ||
.option(' Three ') | ||
.list(); | ||
@@ -10,0 +25,0 @@ |
24519
8
274
98