@guillermobrachetta/cli-todo
Version:
CLI to manage todos
36 lines (29 loc) • 842 B
JavaScript
import enquirer from 'enquirer';
import chalk from 'chalk';
import { to } from 'await-to-js';
import handleError from 'cli-handle-error';
import shouldCancel from './cliShouldCancel.js';
const { dim } = chalk;
const { MultiSelect } = enquirer;
const yellow = chalk.hex('#dab000').inverse;
const select = async ({ message, choices }) => {
if (choices.length === 0) {
console.log(yellow(' ALL TODOS DONE! '));
return;
}
const [err, response] = await to(
new MultiSelect({
message,
choices,
hint: dim('\nUse [space] to select & [enter] to submit'),
validate(value) {
return value.length === 0 ? 'Please select at least one todo' : true;
},
})
.on('cancel', () => shouldCancel())
.run()
);
handleError('INPUT: ', err);
return response;
};
export default select;