userio

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterrupted = errors.New("input was interrupted")
)
View Source
var (
	ErrValueIsNotSet = errors.New("value is not set")
)

Functions

func IsTerminalInteractive added in v0.25.3

func IsTerminalInteractive(in io.Reader, out io.Writer) bool

func Required

func Required(s string) (string, error)

func ValidateFilePath

func ValidateFilePath(path string, opt FileValidatorOptions) error

Types

type FilePicker

type FilePicker struct {
	Prompt         string
	WorkingDir     string
	InitialValue   string
	ValidateAndMap ValidateAndMap[string, string]
}

func (*FilePicker) GetInput

func (ifp *FilePicker) GetInput(streams IOStreams) (string, error)

type FileValidatorOptions

type FileValidatorOptions struct {
	ExistingOnly bool
	DirsOnly     bool
	DirIsEmpty   bool
	FilesOnly    bool
	Optional     bool
}

type IOStreams

type IOStreams struct {
	CurrentHandler wizard.Handler
	// contains filtered or unexported fields
}

func NewIOStreams

func NewIOStreams(stdin io.Reader, stdout io.Writer, stderr io.Writer) IOStreams

func NewIOStreamsWithInteractive

func NewIOStreamsWithInteractive(stdin io.Reader, stdout io.Writer, stderr io.Writer, isInteractive bool) IOStreams

func NewTestIOStreams added in v0.23.1

func NewTestIOStreams(in io.Reader, out io.Writer, isInteractive bool) IOStreams

func (IOStreams) Error added in v0.25.3

func (s IOStreams) Error(messages string)

func (*IOStreams) Execute added in v0.25.3

func (s *IOStreams) Execute(model tea.Model, opts ...tea.ProgramOption) (tea.Model, error)

func (IOStreams) GetOutput

func (s IOStreams) GetOutput() io.Writer

func (IOStreams) Info

func (s IOStreams) Info(messages string)

func (IOStreams) IsInteractive

func (s IOStreams) IsInteractive() bool

func (IOStreams) MsgE added in v0.25.3

func (s IOStreams) MsgE(message string, style lipgloss.Style, stream *lipgloss.Renderer) error

func (IOStreams) Print added in v0.25.3

func (s IOStreams) Print(messages string)

func (IOStreams) Warn added in v0.25.3

func (s IOStreams) Warn(messages string)

func (*IOStreams) Wizard added in v0.25.2

func (s *IOStreams) Wizard(title string, completedTitle string) wizard.Handler

type InputPrompt

type InputPrompt[V any] interface {
	GetInput(streams IOStreams) (V, error)
}

type InputSourceSwitch

type InputSourceSwitch[V, T any] struct {
	DefaultValue        Zeroable[V]
	Optional            bool
	InteractivePromptFn func() (InputPrompt[V], error)
	ValidateAndMap      ValidateAndMap[V, T]
	ErrMessage          string
	// contains filtered or unexported fields
}

func (*InputSourceSwitch[V, T]) GetValue

func (iss *InputSourceSwitch[V, T]) GetValue(streams IOStreams) (T, error)

func (*InputSourceSwitch[V, T]) Validate

func (iss *InputSourceSwitch[V, T]) Validate(streams IOStreams) error

type MultiSelect

type MultiSelect struct {
	Prompt         string
	Items          []string
	ValidateAndMap ValidateAndMap[[]string, []string]
}

func (*MultiSelect) GetInput

func (op *MultiSelect) GetInput(streams IOStreams) ([]string, error)

type NonInteractiveStyles added in v0.25.3

type NonInteractiveStyles struct {
	InfoStyle         lipgloss.Style
	ErrorHeadingStyle lipgloss.Style
	ErrorMessageStyle lipgloss.Style
	WarnHeadingStyle  lipgloss.Style
	WarnMessageStyle  lipgloss.Style
	Bold              lipgloss.Style
	Status            wizard.TaskStatusStyle
}

func NewNonInteractiveStyles added in v0.25.3

func NewNonInteractiveStyles() NonInteractiveStyles

type SingleSelect

type SingleSelect struct {
	Prompt          string
	Items           []string
	PreselectedItem string
}

func (*SingleSelect) GetInput

func (op *SingleSelect) GetInput(streams IOStreams) (string, error)

type TextInput

type TextInput[V interface{}] struct {
	Prompt         string
	InitialValue   string
	Placeholder    string
	ValidateAndMap ValidateTextAndMapFn[V]
}

func (*TextInput[V]) GetInput

func (ti *TextInput[V]) GetInput(streams IOStreams) (V, error)

type ValidateAndMap

type ValidateAndMap[V, T any] func(V) (T, error)

type ValidateTextAndMapFn

type ValidateTextAndMapFn[V interface{}] func(string) (V, error)

type Zeroable

type Zeroable[V any] interface {
	Value() V
	IsZeroValue() bool
}

Zeroable this interface is required to check if a value is not set we could use simply "comparable" as generic constraint, but slices are not comparable, which makes them impossible to use. This interface abstracts helps mitigate the issue

func AsZeroable

func AsZeroable[V comparable](value V) Zeroable[V]

func AsZeroableSlice

func AsZeroableSlice[V []T, T any](value V) Zeroable[V]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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