prompter: github.com/Songmu/prompter Index | Examples | Files | Directories

package prompter

import "github.com/Songmu/prompter"

Package prompter is utility for easy prompting

Index

Examples

Package Files

funcs.go prompter.go

Constants

const VERSION = "0.4.0"

VERSION version of prompter

func Choose Uses

func Choose(message string, choices []string, defaultChoice string) string

Choose make a choice

Code:

lang := prompter.Choose("Which language do you like the most?", []string{"Perl", "Golang", "Scala", "Ruby"}, "Perl")
fmt.Println("Perl")
fmt.Printf("Great! You like %s!", lang)

Output:

Which language do you like the most? (Perl/Golang/Scala/Ruby) [Perl]: Perl
Great! You like Perl!

func Password Uses

func Password(message string) string

Password asks password

Code:

passwd := prompter.Password("Enter your password")
_ = passwd
fmt.Println("****")
fmt.Print("I got your password! :P")

Output:

Enter your password: ****
I got your password! :P

func Prompt Uses

func Prompt(message, defaultAnswer string) string

Prompt simple prompting

Code:

answer := prompter.Prompt("Enter your twitter ID", "")
_ = answer
fmt.Println("Songmu")
fmt.Printf("Hi Songmu!")

Output:

Enter your twitter ID: Songmu
Hi Songmu!

func Regexp Uses

func Regexp(message string, reg *regexp.Regexp, defaultAnswer string) string

Regexp checks the answer by regexp

func YN Uses

func YN(message string, defaultToYes bool) bool

YN y/n choice

Code:

if prompter.YN("Do you like sushi?", true) {
    fmt.Println("y")
    fmt.Print("Nice! Let's go sushi bar!")
}

Output:

Do you like sushi? (y/n) [y]: y
Nice! Let's go sushi bar!

func YesNo Uses

func YesNo(message string, defaultToYes bool) bool

YesNo yes/no choice

Code:

if !prompter.YesNo("Do you like beer?", false) {
    fmt.Println("no")
    fmt.Print("Oops!")
}

Output:

Do you like beer? (yes/no) [no]: no
Oops!

type Prompter Uses

type Prompter struct {
    Message string
    // choices of answer
    Choices    []string
    IgnoreCase bool
    Default    string
    // specify answer pattern by regexp. When both Choices and Regexp are specified, Regexp takes a priority.
    Regexp *regexp.Regexp
    // for passwords and so on.
    NoEcho     bool
    UseDefault bool
    // contains filtered or unexported fields
}

Prompter is object for prompting

Code:

input := (&prompter.Prompter{
    Choices:    []string{"aa", "bb", "cc"},
    Default:    "aa",
    Message:    "please select",
    IgnoreCase: true,
}).Prompt()
fmt.Println("aa")
fmt.Printf("your input is %s.", input)

Output:

please select (aa/bb/cc) [aa]: aa
your input is aa.

func (*Prompter) Prompt Uses

func (p *Prompter) Prompt() string

Prompt displays a prompt and returns answer

Directories

PathSynopsis
example

Package prompter imports 7 packages (graph) and is imported by 47 packages. Updated 2020-08-31. Refresh now. Tools for package owners.