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)
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?
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 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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With