prompt

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 9 Imported by: 2

README

prompt

GoDoc CI

Ascetic and minimalistic CLI prompt library.

This is yet another CLI prompt library in Go. Its main purpose is to provide as simple as possible API for both users of the library and users of the program using this library.

Usage

// Simple line reading.
name, _ := prompt.ReadLine(ctx, "What's your name? ")

// Y/n confirmation.
yes, _ := prompt.Confirm(context.TODO(), name+", do you want to continue?")
if !yes {
	return
}

// Menu with single possible answer.
x, _ := prompt.SelectSingle(ctx, 
	"Which football club is your favorite?", 
	[]string{
		"FC Barcelona",
		"Spartak Moscow",
		"Manchester United",
		"Juventus",
	},
)

For more details please visit example folder.

Screencast

This screencast was recorded by running binary from example folder.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPrompt = Prompt{
		Verbose: false,
	}
	DefaultQuestion = Question{
		Strict:  false,
		Mode:    QuestionSuffix,
		Default: true,
	}
	DefaultSelect = Select{
		Filter: true,
		Paging: 8,
	}
)

Functions

func Confirm

func Confirm(ctx context.Context, msg string) (bool, error)

func ReadLine

func ReadLine(ctx context.Context, msg string) (string, error)

func SelectMultiple

func SelectMultiple(ctx context.Context, msg string, opts []string) ([]int, error)

func SelectSingle

func SelectSingle(ctx context.Context, msg string, opts []string) (int, error)

Types

type Prompt

type Prompt struct {
	Message string
	Default string
	Verbose bool
	Prompt  string
	// contains filtered or unexported fields
}

func (*Prompt) ReadLine

func (p *Prompt) ReadLine(ctx context.Context) (string, error)

type Question

type Question struct {
	Message string
	// Default value when user just press Enter without any input.
	Default bool
	Strict  bool
	Mode    QuestionMode
}

func (*Question) Confirm

func (q *Question) Confirm(ctx context.Context) (result bool, err error)

type QuestionDefault added in v0.2.2

type QuestionDefault uint8

type QuestionMode added in v0.2.2

type QuestionMode uint8
const (
	QuestionEmpty QuestionMode = iota
	QuestionSuffix
	QuestionNewLine
)

type Select

type Select struct {
	Message string
	Options []string
	Filter  bool
	Paging  int
	// contains filtered or unexported fields
}

func (*Select) Multiple

func (s *Select) Multiple(ctx context.Context) (answer []int, err error)

func (*Select) Single

func (s *Select) Single(ctx context.Context) (answer int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL