Skip to content
Interactive prompt for command-line applications
Go Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github add a note about running make before you submit Jan 2, 2019
_examples Improved documentation further and the SelectWithAdd example Jul 19, 2018
list Add hooks so that multiple calls to a select can maintain scroll and … Jan 7, 2019
screenbuf add support for hiding selected text Feb 19, 2019
.gitignore collect coverage for each package separately Jan 15, 2019
.travis.yml collect coverage for each package separately Jan 15, 2019
CHANGELOG.md update changelog Feb 19, 2019
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md Oct 16, 2017
Gopkg.lock Update lint tools (#104) Apr 11, 2019
Gopkg.toml Update lint tools (#104) Apr 11, 2019
LICENSE.md Add initial LICENSE.md Oct 16, 2017
Makefile collect coverage for each package separately Jan 15, 2019
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
cursor.go repair the _examples Jan 11, 2019
cursor_test.go repair the _examples Jan 11, 2019
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 Update lint tools (#104) Apr 11, 2019
go.sum Update lint tools (#104) Apr 11, 2019
keycodes.go Fix the document and code blank line Jan 16, 2019
keycodes_windows.go Change description for navigation keys for Windows (#74) Jul 26, 2018
prompt.go fix: Interrupt was not catched because err was out of scope (#103) Apr 11, 2019
promptui.go Improved documentation further and the SelectWithAdd example Jul 19, 2018
select.go Allow search prompt to be customized (#106) Jul 9, 2019
select_test.go add a test for the clearScreen function Feb 19, 2019
styles.go Gofmt'd the whole project Jul 19, 2018
styles_windows.go New doc fixes Jul 20, 2018
tools.go Update lint tools (#104) Apr 11, 2019

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

You can’t perform that action at this time.