Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create nodejs cli select/options menu

How do you create an arrow-key menu list?

I'm looking for something like after entering in eslint init or create-react-app <project>? (see images below)

ESlint

eslint CLI menu

yeoman

create-react-app cli menu

Searching around to find ways to create a CLI, I found NodeJS to be an option followed by a few tools: Commander.js, Vorpal, and/or create-new-cli.

If I am on the right track, how can I create a CLI arrow-key select menu?

like image 912
Chance Smith Avatar asked Apr 08 '18 12:04

Chance Smith


People also ask

Why should I Write my CLI in Node JS?

One of the reasons why Node.js got so popular is the rich package ecosystem with over 900,000 packages in the npm registry. By writing your CLIs in Node.js you can tap into this ecosystem including it's big amount of CLI-focused packages.

What is the use of select-options in Node JS?

What this select-options does is that it enables you to select an option from a list of options. The core of the program is the readline.emitKeyPressEvents (stream) method of the readline module. The readline module is one of the standard (inbuilt) node.js lib that enables you to read from the console.

How to create a select class in Node JS?

First, initialize a Node environment and create a select.js file. When done, open the select.js file. We start with creating a Select class We will create a constructor that will take the configuration in an object literal. Here, we have our opts param with default settings.

How to highlight the current index in the terminal using NodeJS?

Now, when either the up or down arrow button is pressed we will use the readline#cursorTo to adjust the cursor and use coloring to highlight the current index in the terminal. Let’s do this. First, initialize a Node environment and create a select.js file. When done, open the select.js file. We start with creating a Select class


Video Answer


1 Answers

I believe yeoman is using inquirer. Source: yo's dependencies.

I've also seen prompts which has a similar arrow selection feature and other cli ui/ux features. See the demos about halfway down the page.

Note: I've never actually used either, I'm just in the same research phase.

like image 80
jhr Avatar answered Sep 30 '22 19:09

jhr