surveyext

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatePickerQuestionTemplate = `` /* 537-byte string literal not displayed */
View Source
var MultiSelectQuestionTemplate = `` /* 1230-byte string literal not displayed */
View Source
var OctoEditorQuestionTemplate = `` /* 696-byte string literal not displayed */
View Source
var SelectQuestionTemplate = `` /* 1033-byte string literal not displayed */

Functions

This section is empty.

Types

type DatePicker added in v0.2.1

type DatePicker struct {
	survey.Renderer
	Message         string
	Default         time.Time
	Min             time.Time
	Max             time.Time
	Help            string
	AnswerFormatter func(*DatePicker, time.Time) string
	OverrideNow     time.Time // for unit testing; lets you override the definition of 'now'
	// contains filtered or unexported fields
}

DatePicker is a prompt that presents a date/time picker. Response type is a time.Time

selectedTime := time.Time{}
prompt := &surveyext.DatePicker {
	Message: "Choose a date and time:",
	Default: time.Now(),
}
survey.AskOne(prompt, &selectedTime)

func (*DatePicker) Cleanup added in v0.2.1

func (d *DatePicker) Cleanup(config *survey.PromptConfig, val interface{}) error

func (*DatePicker) Error added in v0.2.1

func (d *DatePicker) Error(*survey.PromptConfig, error) error

func (*DatePicker) Now added in v0.2.1

func (d *DatePicker) Now() time.Time

Now returns the OverrideNow property (if it is set), else time.Now()

func (*DatePicker) Prompt added in v0.2.1

func (d *DatePicker) Prompt(config *survey.PromptConfig) (interface{}, error)

type DatePickerAnswer added in v0.2.1

type DatePickerAnswer struct {
	Time time.Time
}

DatePickerAnswer exists to workaround a survey bug (unintented code path?) where if the answer is a struct it thinks you're asking multiple questions and collecting the answers into struct fields. If you do this:

var answer time.Time
err = asker(&surveyext.DatePicker{ Message: "When?" }, &answer)

then the code in survey Write.go sees that the answer is a struct, and tries to go putting the response value into a named field on that struct (which doesn't exist). Workaround is to have a response-holder structure that implements survey.core.Settable

func (*DatePickerAnswer) WriteAnswer added in v0.2.1

func (a *DatePickerAnswer) WriteAnswer(_ string, value interface{}) error

type DatePickerTemplateData added in v0.2.1

type DatePickerTemplateData struct {
	DatePicker
	RawInput          string // this is full of ansi escape sequences... It'd be nice to have survey's template thing render this, TODO attempt that later
	Answer            string
	ShowAnswer        bool
	ShowHelp          bool
	SelectedComponent componentIdx
	Config            *survey.PromptConfig
}

type MultiSelectTemplateData added in v0.6.0

type MultiSelectTemplateData struct {
	MultiSelectWithAdd
	Answer        string
	ShowAnswer    bool
	Checked       map[int]bool
	SelectedIndex int
	ShowHelp      bool
	PageEntries   []core.OptionAnswer
	Config        *survey.PromptConfig

	// These fields are used when rendering an individual option
	CurrentOpt   core.OptionAnswer
	CurrentIndex int
}

data available to the templates when processing

func (MultiSelectTemplateData) IterateOption added in v0.6.0

func (m MultiSelectTemplateData) IterateOption(ix int, opt core.OptionAnswer) interface{}

IterateOption sets CurrentOpt and CurrentIndex appropriately so a multiselect option can be rendered individually

type MultiSelectWithAdd added in v0.6.0

type MultiSelectWithAdd struct {
	survey.Renderer
	Message       string
	Options       []string
	Default       interface{}
	Help          string
	PageSize      int
	VimMode       bool
	FilterMessage string
	Filter        func(filter string, value string, index int) bool
	// contains filtered or unexported fields
}

MultiSelectWithAdd is a prompt that presents a list of various options to the user for them to select using the arrow keys and enter, typing allows the user to add new entries not in the list. Response type is a slice of strings.

days := []string{}
prompt := &survey.MultiSelect{
	Message: "What days do you prefer:",
	Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
}
survey.AskOne(prompt, &days)

func (*MultiSelectWithAdd) Cleanup added in v0.6.0

func (m *MultiSelectWithAdd) Cleanup(config *survey.PromptConfig, val interface{}) error

Cleanup removes the options section, and renders the ask like a normal question.

func (*MultiSelectWithAdd) OnChange added in v0.6.0

func (m *MultiSelectWithAdd) OnChange(key rune, config *survey.PromptConfig)

OnChange is called on every keypress.

func (*MultiSelectWithAdd) Prompt added in v0.6.0

func (m *MultiSelectWithAdd) Prompt(config *survey.PromptConfig) (interface{}, error)

type OctoEditor

type OctoEditor struct {
	*survey.Editor
	Optional bool
	// contains filtered or unexported fields
}

func (*OctoEditor) Cleanup

func (e *OctoEditor) Cleanup(config *survey.PromptConfig, val interface{}) error

func (*OctoEditor) Prompt

func (e *OctoEditor) Prompt(config *survey.PromptConfig) (interface{}, error)

func (*OctoEditor) PromptAgain

func (e *OctoEditor) PromptAgain(config *survey.PromptConfig, invalid interface{}, err error) (interface{}, error)

type OctoEditorTemplateData

type OctoEditorTemplateData struct {
	survey.Editor
	Optional   bool
	Answer     string
	ShowAnswer bool
	ShowHelp   bool
	Config     *survey.PromptConfig
}

type Select added in v0.5.0

type Select struct {
	survey.Renderer
	Message       string
	Options       []string
	Default       interface{}
	Help          string
	PageSize      int
	VimMode       bool
	FilterMessage string
	Filter        func(filter string, value string, index int) bool
	Description   func(value string, index int) string
	// contains filtered or unexported fields
}

Select is a prompt that presents a list of various options to the user for them to select using the arrow keys and enter. Response type is a string.

color := ""
prompt := &survey.Select{
	Message: "Choose a color:",
	Options: []string{"red", "blue", "green"},
}
survey.AskOne(prompt, &color)

func (*Select) Cleanup added in v0.5.0

func (s *Select) Cleanup(config *survey.PromptConfig, val interface{}) error

func (*Select) OnChange added in v0.5.0

func (s *Select) OnChange(key rune, config *survey.PromptConfig) bool

OnChange is called on every keypress.

func (*Select) Prompt added in v0.5.0

func (s *Select) Prompt(config *survey.PromptConfig) (interface{}, error)

type SelectTemplateData added in v0.5.0

type SelectTemplateData struct {
	Select
	PageEntries   []core.OptionAnswer
	SelectedIndex int
	Answer        string
	ShowAnswer    bool
	ShowHelp      bool
	Description   func(value string, index int) string
	Config        *survey.PromptConfig

	// These fields are used when rendering an individual option
	CurrentOpt   core.OptionAnswer
	CurrentIndex int
}

SelectTemplateData is the data available to the templates when processing

func (SelectTemplateData) GetDescription added in v0.5.0

func (s SelectTemplateData) GetDescription(opt core.OptionAnswer) string

func (SelectTemplateData) IterateOption added in v0.5.0

func (s SelectTemplateData) IterateOption(ix int, opt core.OptionAnswer) interface{}

IterateOption sets CurrentOpt and CurrentIndex appropriately so a select option can be rendered individually

Jump to

Keyboard shortcuts

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