Skip to content
GitHub no longer supports this web browser. Learn more about the browsers we support.
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 Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
.gitignore Improve lint installation Dec 6, 2019
.golangci.yml Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
.travis.yml Remove support for go1.11 Jan 11, 2020
CHANGELOG.md Update changelog for v0.7.0 Jan 11, 2020
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md Oct 16, 2017
LICENSE.md Add initial LICENSE.md Oct 16, 2017
Makefile Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
README.md Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
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 Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
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 Remove support for go1.11 Jan 11, 2020
go.sum separate out tools 'package' to reduce 'promptui' package's dependency Dec 29, 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 Set custom stdio for Prompt Jan 2, 2020
promptui.go Improved documentation further and the SelectWithAdd example Jul 19, 2018
select.go Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol… Jan 11, 2020
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

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.