Promtpui is a Go library to ask for user input on the command-line. Our team has been working on Promptui for some time now and we believe it can be useful for other developers and companies. The main goal is to provide an efficient and effective way to gather information while respecting the limitations of terminals and the simplicity most people expect when using a command-line application.
James Bowes started the development of Promptui back in August 2016. The library used to be part of our first cli tool and, after that, we started using it across multiple projects. We’ve recently created a github repository for Prompui. We plan to keep expanding its functionality and customizability in regards to the look and feel in different use cases.
Promptui has two main input types: Prompt and Select.
Prompt is what one usually expects from a form input: it provides a single line to type and enter information. The most useful feature is that the prompt can validate information and give feedback as users type. For example, if we are asking for an email prompt can validate if the input has a valid format before they press enter. The input can also receive a mask to hide sensitive information like passwords and secrets.
<img src="https://media.giphy.com/media/3ohjULdsNsjOvlWoRG/giphy.gif" />
Select provides a list of options to choose from. Users can navigate through the list either one item at a time or by pagination. One of its coolest features is the ability to search. It can be customized to match information that is not even visible on the screen. It’s very useful if items have metadata associated with them.
<img src="https://media.giphy.com/media/xUNda0Ngb5qsogLsBi/giphy.gif" />
My hands-down favorite feature is the Select details view. It is an optional feature to show more information about an item while users navigate through the list. We have been using this feature extensively in the Manifold CLI to give more context about the options users are about to choose. If you are trying to provision a new service, for example, we can give you details about the product features, how much it would cost and so on.
<img src="https://media.giphy.com/media/26FfgSKnDDjW81BoA/giphy.gif" />
What’s cool about Promptui?
Promptui leverages a very powerful implementation of GNU-Readline in Go that also means developers have access to many of its features, including key bindings and vi-mode.
Promptui is awesome because it is very flexible. Developers can specify what they want and how it should look while Promptui takes care of how to display that on terminals.
Another interesting thing is that we use default Go templates to add logic and styles for each input type. It should feel very familiar to Go developers to write and expand them. By default we have many helper functions, like colors and styles, and developers can define their own to achieve different goals.
Internally we use Promptui as a fallback when a user doesn’t provide arguments necessary to run a cli command. That way we can cater both those familiar with the tool, but also give an interactive way for those that just started exploring.