Skip to content

PatBlr/Cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cli

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();

Write

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?");

grafik

Ask

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.

Choose

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);

choose

Returns the index of the chosen option.

Select

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],
  ]);

Animation

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 ]
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published