package core

import "github.com/AlecAivazis/survey/v2/core"

Index

Variables

var DisableColor = false

DisableColor can be used to make testing reliable

var TemplateFuncsNoColor = map[string]interface{}{

	"color": func(color string) string {
		return ""
	},
}
var TemplateFuncsWithColor = map[string]interface{}{

	"color": ansi.ColorCode,
}

Functions

func GetTemplatePair

func GetTemplatePair(tmpl string) ([2]*template.Template, error)

GetTemplatePair returns a pair of compiled templates where the first template is generated for user-facing output and the second is generated for use by the renderer. The second template does not contain any color escape codes, whereas the first template may or may not depending on DisableColor.

func IsFieldNotMatch

func IsFieldNotMatch(err error) (string, bool)

IsFieldNotMatch reports whether an "err" is caused by a non matching field. It returns the Question.Name that couldn't be matched with a destination field.

Usage:

if err := survey.Ask(qs, &v); err != nil {
	if name, ok := core.IsFieldNotMatch(err); ok {
		// name is the question name that did not match a field
	}
}

func RunTemplate

func RunTemplate(tmpl string, data interface{}) (string, string, error)

RunTemplate returns two formatted strings given a template and the data it requires. The first string returned is generated for user-facing output and may or may not contain ANSI escape codes for colored output. The second string does not contain escape codes and can be used by the renderer for layout purposes.

func WriteAnswer

func WriteAnswer(t interface{}, name string, v interface{}) (err error)

Types

type OptionAnswer

type OptionAnswer struct {
	Value string
	Index int
}

OptionAnswer is the return type of Selects/MultiSelects that lets the appropriate information get copied to the user's struct

func OptionAnswerList

func OptionAnswerList(incoming []string) []OptionAnswer

type Settable

type Settable interface {
	WriteAnswer(field string, value interface{}) error
}

Settable allow for configuration when assigning answers

Bugs

the current implementation might cause weird conflicts if there are two fields with same name that only differ by casing.

Source Files

template.go write.go

Version
v2.3.7 (latest)
Published
Dec 8, 2022
Platform
linux/amd64
Imports
11 packages
Last checked
16 hours ago

Tools for package owners.