Object oriented approach of a dynamic CLI-Library without the use of any additional npm packages except for buildin packages.
Create a new CLI:
const cli = new Cli();
Writes a given string to the console. The textcolor can be passed as an optional parameter.
Supported textcolors
- Black
- Blue
- Green
- Grey
- Magenta
- Red
- White
- Yellow
- Reset ( Resets to the default CLI-Color )
Note that the textcolor as a parameter is case-insensitive.
cli.write("This is a colored text! ", "cyan");
cli.writeln("(This one ends with a newline!)", "yellow");
cli.write("See?");
Prompts the user to answer a given question.
const response = await cli.ask("What is your favorite fruit? ");
Returns the given response as a string.
Prompts the user to choose an option from an array of options.
Arrow keys are used for the navigation and return to submit.
const options = ["Apple", "Banana", "Orange", "Strawberry", "Raspberry"];
const choice_idx = await cli.choose(options);
Returns the index of the chosen option.
Prompts the user to select options of a given array of tuples.
Arrow keys are used for the navigation, spacebar to select / deselect and return to submit.
Tuples first entry is the option as a string and the second entry is a boolean whether the option is pre-selected.
cli.write("What kind of fruits do you like? ");
cli.writeln("(Everyone likes apples)", "grey");
const selected = await cli.select([
["Apple", true],
["Banana", false],
["Orange", false],
["Strawberry", false],
["Raspberry", false],
]);
Returns the altered array of tuples, where the selected options are marked with true and the unselected ones with false.
[
[ 'Apple', true ],
[ 'Banana', true ],
[ 'Orange', false ],
[ 'Strawberry', true ],
[ 'Raspberry', false ]
]