Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improvement in README.md, gif added and a basic working example #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<p align="center">
Simple and interactive solution to provide a list of selectable items on the command line.
<img src="https://cyrilwanner.github.io/packages/cli-select/assets/preview.gif" alt="cli-select preview">
</p>

> Note: cli-select does not produce colored output by default to keep the dependencies at a minimum. See the [examples](#examples) below on how to reproduce this preview.
Expand All @@ -29,8 +28,7 @@ npm install --save cli-select
## Usage

```javascript
const cliSelect = require('cli-select');

import cliSelect from 'cli-select';
cliSelect(options, callback);
```

Expand Down Expand Up @@ -161,23 +159,25 @@ These two packages are also used in the examples below but `cli-select` is also

### Custom value renderer

![Example](./example.gif)

```javascript
const cliSelect = require('cli-select');
const chalk = require('chalk');
import cliSelect from 'cli-select';
import chalk from 'chalk';

cliSelect({
values: ['Major', 'Minor', 'Patch'],
valueRenderer: (value, selected) => {
if (selected) {
return chalk.underline(value);
}

return value;
},
}).then(...);
```
values: ['Major', 'Minor', 'Patch'],
valueRenderer: (value, selected) => {
if (selected) {
return chalk.underline(value);
}

Todo: more examples, also the one in the preview gif
return value;
},
}).then((option) => {
console.log(`Option selected: ${option.value}`)
});
```

## License

Expand Down
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cliSelect from 'cli-select';
import chalk from 'chalk';

cliSelect({
values: ['Major', 'Minor', 'Patch'],
valueRenderer: (value, selected) => {
if (selected) {
return chalk.underline(value);
}

return value;
},
}).then((option) => {
console.log(`Option selected: ${option.value}`)
});
17 changes: 17 additions & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "basic",
"type": "module",
"version": "1.0.0",
"description": "A basic example",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"chalk": "^5.3.0",
"cli-select": "^1.1.2"
}
}