Debian Codegraph @

/

debian golang-github-manifoldco-promptui 0.9.0-1debian golang-github-manifoldco-promptui-dev gomod github.com/manifoldco/promptui debiangogoinimakemakefilemarkdownshellyaml 48 files · 392 symbols
View dependency graph

Depends on

README (full)

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

dir .github/
dir _examples/
dir debian/
dir list/
dir screenbuf/
file .gitignore
file .golangci.yml
file .travis.yml
file CHANGELOG.md
file CODE_OF_CONDUCT.md
file LICENSE.md
file Makefile
file README.md
file codes.go
file codes_test.go
file cursor.go
file cursor_test.go
file example_main_test.go
file example_prompt_test.go
file example_select_test.go
file example_selectwithadd_test.go
file go.mod
file go.sum
file keycodes.go
file keycodes_other.go
file keycodes_windows.go
file prompt.go
file promptui.go
file select.go
file select_test.go
file styles.go
file styles_windows.go