Interactive prompt for command-line applications
Switch branches/tags
Clone or download
Latest commit ad16ba4 Oct 4, 2018
Permalink
Failed to load latest commit information.
.github Create listbot.md Nov 16, 2017
_examples Improved documentation further and the SelectWithAdd example Jul 19, 2018
list Improved documentation further and the SelectWithAdd example Jul 19, 2018
screenbuf Improved documentation further and the SelectWithAdd example Jul 19, 2018
.gitignore Add go dep Oct 16, 2017
.travis.yml Add support for 1.10 and 1.11. Oct 4, 2018
CHANGELOG.md Release v0.3.1 (#75) Jul 26, 2018
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md Oct 16, 2017
Gopkg.lock Update dep after juju/ansiterm fix (#51) Dec 12, 2017
Gopkg.toml fix typo in Gopkg.toml (#50) Dec 12, 2017
LICENSE.md Add initial LICENSE.md Oct 16, 2017
Makefile Vendor linting cmds (#12) Oct 22, 2017
README.md Release v0.2.1 (#30) Nov 30, 2017
codes.go Improved documentation further and the SelectWithAdd example Jul 19, 2018
codes_test.go Custom style/output for prompt and select (#8) Oct 20, 2017
example_main_test.go New doc fixes Jul 20, 2018
example_prompt_test.go Gofmt'd the whole project Jul 19, 2018
example_select_test.go Gofmt'd the whole project Jul 19, 2018
example_selectwithadd_test.go Improved documentation further and the SelectWithAdd example Jul 19, 2018
go.mod Add support for 1.10 and 1.11. Oct 4, 2018
go.sum Add support for 1.10 and 1.11. Oct 4, 2018
keycodes.go Change description for navigation keys for Windows (#74) Jul 26, 2018
keycodes_windows.go Change description for navigation keys for Windows (#74) Jul 26, 2018
prompt.go Merge pull request #73 from manifoldco/godoc-draft Jul 20, 2018
promptui.go Improved documentation further and the SelectWithAdd example Jul 19, 2018
select.go Change description for navigation keys for Windows (#74) Jul 26, 2018
select_test.go Prompt improve default value (#21) Nov 2, 2017
styles.go Gofmt'd the whole project Jul 19, 2018
styles_windows.go New doc fixes Jul 20, 2018

README.md

promptui

Interactive prompt for command-line applications.

We built Promptui because we wanted to make it easy and fun to explore cloud services with manifold cli.

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Overview

promptui

Promptui is a library providing a simple interface to create command-line prompts for go. It can be easily integrated into spf13/cobra, urfave/cli or any cli go application.

Promptui has two main input modes:

  • Prompt provides a single line for user input. Prompt supports optional live validation, confirmation and masking the input.

  • Select provides a list of options to choose from. Select supports pagination, search, detailed view and custom templates.

For a full list of options check GoDoc.

Basic Usage

Prompt

package main

import (
	"errors"
	"fmt"
	"strconv"

	"github.com/manifoldco/promptui"
)

func main() {
	validate := func(input string) error {
		_, err := strconv.ParseFloat(input, 64)
		if err != nil {
			return errors.New("Invalid number")
		}
		return nil
	}

	prompt := promptui.Prompt{
		Label:    "Number",
		Validate: validate,
	}

	result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

Select

package main

import (
	"fmt"

	"github.com/manifoldco/promptui"
)

func main() {
	prompt := promptui.Select{
		Label: "Select Day",
		Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
			"Saturday", "Sunday"},
	}

	_, result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

More Examples

See full list of examples