interact

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2018 License: MIT Imports: 8 Imported by: 0

README

Interactive on cli

Documentation

Overview

Package interact collect some interactive methods for CLI

Index

Constants

View Source
const (
	// OK success exit code
	OK = 0
	// ERR error exit code
	ERR = 2
)

Variables

This section is empty.

Functions

func AnswerIsYes

func AnswerIsYes(def ...bool) bool

AnswerIsYes check user inputted answer is right fmt.Print("are you OK?") ok := AnswerIsYes() ok := AnswerIsYes(true)

func Ask

func Ask()

func Checkbox

func Checkbox()

func Confirm

func Confirm(message string, defVal ...bool) bool

Confirm a question, returns bool

func MultiSelect

func MultiSelect(message string)

func NewAsk

func NewAsk(q string)

func QuickSelect

func QuickSelect(title string, options interface{}, defOpt string, allowQuit ...bool) string

QuickSelect select one of the options, returns selected option value map options:

	{
   // option value => option name
   'a' => 'chengdu',
   'b' => 'beijing'
	}

array options:

	{
   // only name, value will use index
   'chengdu',
   'beijing'
	}

func ReadFirst

func ReadFirst(question string) (string, error)

ReadFirst read first char

func ReadLine

func ReadLine(question string) (string, error)

ReadLine read line for user input in := ReadLine("") ans := ReadLine("your name?")

Types

type Interactive

type Interactive struct {
	Name string
}

func New

func New(name string) *Interactive

type Option

type Option struct {
	Quit bool
	// default value
	DefVal string
}

type Question

type Question struct {
	// contains filtered or unexported fields
}

type Select

type Select struct {
	// Title message for select. e.g "Your city?"
	Title string
	// Options the options data for select. allow: []int,[]string,map[string]string
	Options interface{}
	// DefOpt default option when not input answer
	DefOpt string
	// NoQuit option. if is false, will display "quit" option
	NoQuit bool
	// contains filtered or unexported fields
}

Select definition

func NewSelect

func NewSelect(title string, options interface{}) *Select

NewSelect instance. usage:

s := NewSelect("Your city?", []string{"chengdu", "beijing"})
val := s.Run().String() // "1"

func (*Select) Run

func (s *Select) Run() *Value

Run select and receive use input answer

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value data store

func (Value) Int

func (v Value) Int() (val int)

Int convert

func (Value) IsEmpty

func (v Value) IsEmpty() bool

IsEmpty value

func (Value) String

func (v Value) String() string

String convert

func (Value) Val

func (v Value) Val() interface{}

Val get

Jump to

Keyboard shortcuts

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