terminal input prompt for simple menu-driven stuffs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Guillaume St-Pierre ae9f05e744
Merge pull request #94 from royeo/hide-selected
3 months ago
.github add a note about running make before you submit 5 months ago
_examples Improved documentation further and the SelectWithAdd example 11 months ago
list Add hooks so that multiple calls to a select can maintain scroll and cursor position 5 months ago
screenbuf add support for hiding selected text 4 months ago
.gitignore collect coverage for each package separately 5 months ago
.travis.yml collect coverage for each package separately 5 months ago
CHANGELOG.md update changelog 4 months ago
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md 1 year ago
Gopkg.lock Update dep after juju/ansiterm fix (#51) 1 year ago
Gopkg.toml fix typo in Gopkg.toml (#50) 1 year ago
LICENSE.md Add initial LICENSE.md 1 year ago
Makefile collect coverage for each package separately 5 months ago
README.md Release v0.2.1 (#30) 1 year ago
codes.go Improved documentation further and the SelectWithAdd example 11 months ago
codes_test.go Custom style/output for prompt and select (#8) 1 year ago
cursor.go repair the _examples 5 months ago
cursor_test.go repair the _examples 5 months ago
example_main_test.go New doc fixes 11 months ago
example_prompt_test.go Gofmt'd the whole project 11 months ago
example_select_test.go Gofmt'd the whole project 11 months ago
example_selectwithadd_test.go Improved documentation further and the SelectWithAdd example 11 months ago
go.mod Use go modules when building on go 1.11.x 6 months ago
go.sum Use go modules when building on go 1.11.x 6 months ago
keycodes.go Fix the document and code blank line 5 months ago
keycodes_windows.go Change description for navigation keys for Windows (#74) 10 months ago
prompt.go Fix typos in PromptTemplates documentation (#95) 4 months ago
promptui.go Improved documentation further and the SelectWithAdd example 11 months ago
select.go add a test for the clearScreen function 4 months ago
select_test.go add a test for the clearScreen function 4 months ago
styles.go Gofmt'd the whole project 11 months ago
styles_windows.go New doc fixes 11 months ago
tools.go Use go modules when building on go 1.11.x 6 months ago

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