https://github.com/blurfx/node-option
node.js based option selector for interactive shell application
https://github.com/blurfx/node-option
nodejs nodejs-modules shell shell-prompt terminal terminal-app
Last synced: 3 months ago
JSON representation
node.js based option selector for interactive shell application
- Host: GitHub
- URL: https://github.com/blurfx/node-option
- Owner: blurfx
- Created: 2019-02-03T14:18:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T10:16:04.000Z (over 6 years ago)
- Last Synced: 2025-06-29T07:48:54.358Z (3 months ago)
- Topics: nodejs, nodejs-modules, shell, shell-prompt, terminal, terminal-app
- Language: JavaScript
- Size: 1.41 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-option
An item selection module for interactive shell applications.

## Installation
`npm install node-option`
## API
### add(text, value)
Adds the options that you want to select.
If no value is given, the given text will be a value.
### render()
Displays a options on the shell and allows the user to select.
## Usage
#### Javascript
```javascript
const Selector = require('node-option');const selector = new Selector({
markWrapperColor: 'blue',
checkedMarkColor: 'white',
textColor: 'yellow',
multiselect: true,
});const result = selector
.add('One')
.add('Two')
.add('Three')
.add('Four')
.render();result.then((value) => {
console.log(value);
}, (error) => {
console.log(error);
});
```#### Typescript
```typescript
import Selector from 'node-option';const selector = new Selector({
markWrapperColor: 'blue',
checkedMarkColor: 'white',
textColor: 'yellow',
multiselect: true,
});const result = selector
.add('One')
.add('Two')
.add('Three')
.add('Four')
.render();result.then((value) => {
console.log(value);
}, (error) => {
console.error(error);
})
```## Configuration
`node-option` uses `chalk` to styling. You can check available colors [here](https://github.com/chalk/chalk#colors).
```javascript
{
cursor: '>', // string to item cursor
checkedMark: '✓', // string to mark of selected item
uncheckedMark: ' ', // string to mark of unselected item
markWrapperLeft: '[', // string to the left of the checked/unchecked mark
markWrapperRight: ']', // string to the right of the checked/unchecked mark
cursorColor: 'cyan', // color of cursor
checkedMarkColor: 'green', // color of checked mark
uncheckedMarkColor: 'black', // color of cunhecked mark
markWrapperColor: 'white', // color of markWrapperLeft and markWrapperRight
textColor: 'yellow', // color of item text
multiselect: true, // whether to allow select multiple items
highlight: true, // whether to highlight item that cursor points
}
```