No description
  • Go 98.3%
  • Makefile 1.7%
Find a file
2018-05-22 10:02:14 -04:00
.github Create listbot.md 2017-11-16 15:32:02 -04:00
_examples Improve documentation (#27) 2017-11-23 14:26:04 -04:00
list Fix list index when item doesn't support comparison (#23) 2017-11-16 12:35:50 -04:00
screenbuf Fix first line being erased when output increased (#15) 2017-10-25 09:46:42 -04:00
.gitignore Add go dep 2017-10-16 14:36:42 -04:00
.travis.yml Add travis config 2017-10-16 14:51:32 -04:00
CHANGELOG.md Release 0.3.0 (#67) 2018-05-22 10:02:14 -04:00
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md 2017-10-16 13:35:25 -03:00
codes.go Background colors template helpers (#36) 2017-12-01 09:54:19 -04:00
codes_test.go Custom style/output for prompt and select (#8) 2017-10-19 20:50:57 -04:00
Gopkg.lock Update dep after juju/ansiterm fix (#51) 2017-12-12 15:54:06 -05:00
Gopkg.toml fix typo in Gopkg.toml (#50) 2017-12-12 15:41:45 -05:00
keycodes.go Fix backspace on Windows (#37) 2017-12-05 08:36:01 -05:00
keycodes_windows.go Fix backspace on Windows (#37) 2017-12-05 08:36:01 -05:00
LICENSE.md Add initial LICENSE.md 2017-10-16 13:35:23 -03:00
Makefile Vendor linting cmds (#12) 2017-10-22 09:14:23 -04:00
prompt.go Fix display problem when deleting UTF-8 characters sequence 2018-03-08 08:10:52 -08:00
promptui.go Remove prompt success/failure funcs (#17) 2017-10-25 14:17:55 -04:00
README.md Release v0.2.1 (#30) 2017-11-30 11:26:18 -04:00
select.go Add StartInSearchMode (#60) 2018-02-02 08:18:13 -05:00
select_test.go Prompt improve default value (#21) 2017-11-02 09:48:02 -04:00
styles.go Remove prompt success/failure funcs (#17) 2017-10-25 14:17:55 -04:00
styles_windows.go Remove prompt success/failure funcs (#17) 2017-10-25 14:17:55 -04:00

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