Skip to content
/ promptui Public
forked from manifoldco/promptui

Interactive prompt for command-line applications

License

Notifications You must be signed in to change notification settings

trzsz/promptui

This branch is 13 commits ahead of manifoldco/promptui:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2f3d428 · Aug 17, 2024
Jan 2, 2019
Aug 17, 2024
Feb 4, 2024
Jan 21, 2024
Dec 6, 2019
Jan 11, 2020
Jan 11, 2020
Oct 30, 2021
Oct 16, 2017
Oct 16, 2017
Jan 11, 2020
Aug 17, 2024
Jan 21, 2024
Oct 20, 2017
Sep 28, 2020
Jan 11, 2019
Jul 20, 2018
Jul 19, 2018
Jul 19, 2018
Jul 19, 2018
Jan 21, 2024
Jan 21, 2024
Jul 28, 2023
Apr 14, 2020
Apr 14, 2020
Aug 17, 2024
Jul 19, 2018
Aug 17, 2024
Jul 21, 2023
Jul 19, 2018
Jul 20, 2018
Jan 21, 2024

promptui

Interactive prompt for command-line applications.

Fork from manifoldco/promptui and build for trzsz-ssh ( tssh ).

Code of Conduct | Contribution Guidelines

GitHub release GoDoc 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/trzsz/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/trzsz/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

About

Interactive prompt for command-line applications

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.7%
  • Makefile 1.3%