No description
  • Go 98.3%
  • Makefile 1.7%
Find a file
Guillaume St-Pierre ae9f05e744
Merge pull request #94 from royeo/hide-selected
add support for hiding selected text
2019-02-21 10:05:23 -05:00
.github add a note about running make before you submit 2019-01-01 22:03:29 -08:00
_examples Improved documentation further and the SelectWithAdd example 2018-07-19 11:45:46 -04:00
list Add hooks so that multiple calls to a select can maintain scroll and cursor position 2019-01-06 19:03:05 -05:00
screenbuf add support for hiding selected text 2019-02-19 22:40:44 +08:00
.gitignore collect coverage for each package separately 2019-01-15 16:18:25 -05:00
.travis.yml collect coverage for each package separately 2019-01-15 16:18:25 -05:00
CHANGELOG.md update changelog 2019-02-19 22:41:31 +08:00
CODE_OF_CONDUCT.md Add initial CODE_OF_CONDUCT.md 2017-10-16 13:35:25 -03:00
codes.go Improved documentation further and the SelectWithAdd example 2018-07-19 11:45:46 -04:00
codes_test.go Custom style/output for prompt and select (#8) 2017-10-19 20:50:57 -04:00
cursor.go repair the _examples 2019-01-10 21:16:04 -08:00
cursor_test.go repair the _examples 2019-01-10 21:16:04 -08:00
example_main_test.go New doc fixes 2018-07-20 14:07:37 -04:00
example_prompt_test.go Gofmt'd the whole project 2018-07-19 14:06:31 -04:00
example_select_test.go Gofmt'd the whole project 2018-07-19 14:06:31 -04:00
example_selectwithadd_test.go Improved documentation further and the SelectWithAdd example 2018-07-19 11:45:46 -04:00
go.mod Use go modules when building on go 1.11.x 2018-11-26 10:54:48 -04:00
go.sum Use go modules when building on go 1.11.x 2018-11-26 10:54:48 -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 the document and code blank line 2019-01-17 02:08:53 +08:00
keycodes_windows.go Change description for navigation keys for Windows (#74) 2018-07-26 08:37:04 -04:00
LICENSE.md Add initial LICENSE.md 2017-10-16 13:35:23 -03:00
Makefile collect coverage for each package separately 2019-01-15 16:18:25 -05:00
prompt.go Fix typos in PromptTemplates documentation (#95) 2019-02-14 07:13:14 -08:00
promptui.go Improved documentation further and the SelectWithAdd example 2018-07-19 11:45:46 -04:00
README.md Release v0.2.1 (#30) 2017-11-30 11:26:18 -04:00
select.go add a test for the clearScreen function 2019-02-19 22:40:44 +08:00
select_test.go add a test for the clearScreen function 2019-02-19 22:40:44 +08:00
styles.go Gofmt'd the whole project 2018-07-19 14:06:31 -04:00
styles_windows.go New doc fixes 2018-07-20 14:07:37 -04:00
tools.go Use go modules when building on go 1.11.x 2018-11-26 10:54:48 -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