input

package
v0.0.0-...-f36c340 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(stdoutFd uintptr, stdinFd uintptr) bool

IsTerminal returns true if the given file descriptors are attached to a terminal, taking into account of environment variables that force TTY behavior.

func NewProgressLog

func NewProgressLog(lines int, prefix, title, header string) *progressLog

NewProgressLog returns a new instance of a progressLog.

Types

type Asker

type Asker func(p survey.Prompt, response interface{}) error

func NewAsker

func NewAsker(noPrompt bool, isTerminal bool, w io.Writer, r io.Reader) Asker

type AskerConsole

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

func (*AskerConsole) Confirm

func (c *AskerConsole) Confirm(ctx context.Context, options ConsoleOptions) (bool, error)

Prompts the user to confirm an operation

func (*AskerConsole) EnsureBlankLine

func (c *AskerConsole) EnsureBlankLine(ctx context.Context)

func (*AskerConsole) GetFormatter

func (c *AskerConsole) GetFormatter() output.Formatter

func (*AskerConsole) GetWriter

func (c *AskerConsole) GetWriter() io.Writer

Gets the underlying writer for the console

func (*AskerConsole) Handles

func (c *AskerConsole) Handles() ConsoleHandles

func (*AskerConsole) IsSpinnerInteractive

func (c *AskerConsole) IsSpinnerInteractive() bool

func (*AskerConsole) IsSpinnerRunning

func (c *AskerConsole) IsSpinnerRunning(ctx context.Context) bool

func (*AskerConsole) IsUnformatted

func (c *AskerConsole) IsUnformatted() bool

func (*AskerConsole) Message

func (c *AskerConsole) Message(ctx context.Context, message string)

Prints out a message to the underlying console write

func (*AskerConsole) MessageUxItem

func (c *AskerConsole) MessageUxItem(ctx context.Context, item ux.UxItem)

func (*AskerConsole) MultiSelect

func (c *AskerConsole) MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)

func (*AskerConsole) Prompt

func (c *AskerConsole) Prompt(ctx context.Context, options ConsoleOptions) (string, error)

Prompts the user for a single value

func (*AskerConsole) PromptDialog

func (c *AskerConsole) PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)

PromptDialog prompts for multiple values using a single dialog. When successful, it returns a map of prompt IDs to their values.

func (*AskerConsole) PromptDir

func (c *AskerConsole) PromptDir(ctx context.Context, options ConsoleOptions) (string, error)

Prompts the user for a single value

func (*AskerConsole) Select

func (c *AskerConsole) Select(ctx context.Context, options ConsoleOptions) (int, error)

Prompts the user to select from a set of values

func (*AskerConsole) SetWriter

func (c *AskerConsole) SetWriter(writer io.Writer)

Sets the underlying writer for output the console or if writer is nil, sets it back to the default writer.

func (*AskerConsole) ShowPreviewer

func (c *AskerConsole) ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer

func (*AskerConsole) ShowSpinner

func (c *AskerConsole) ShowSpinner(ctx context.Context, title string, format SpinnerUxType)

func (*AskerConsole) StopPreviewer

func (c *AskerConsole) StopPreviewer(ctx context.Context, keepLogs bool)

func (*AskerConsole) StopSpinner

func (c *AskerConsole) StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)

func (*AskerConsole) SupportsPromptDialog

func (c *AskerConsole) SupportsPromptDialog() bool

func (*AskerConsole) WaitForEnter

func (c *AskerConsole) WaitForEnter()

wait until the next enter

func (*AskerConsole) WarnForFeature

func (c *AskerConsole) WarnForFeature(ctx context.Context, key alpha.FeatureId)

type Console

type Console interface {
	// Prints out a message to the underlying console write
	Message(ctx context.Context, message string)
	// Prints out a message following a contract ux item
	MessageUxItem(ctx context.Context, item ux.UxItem)
	WarnForFeature(ctx context.Context, id alpha.FeatureId)
	// Prints progress spinner with the given title.
	// If a previous spinner is running, the title is updated.
	ShowSpinner(ctx context.Context, title string, format SpinnerUxType)
	// Stop the current spinner from the console and change the spinner bar for the lastMessage
	// Set lastMessage to empty string to clear the spinner message instead of a displaying a last message
	// If there is no spinner running, this is a no-op function
	StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)
	// Preview mode brings an embedded console within the current session.
	// Use nil for options to use defaults.
	// Use the returned io.Writer to produce the output within the previewer
	ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer
	// Finalize the preview mode from console.
	StopPreviewer(ctx context.Context, keepLogs bool)
	// Determines if there is a current spinner running.
	IsSpinnerRunning(ctx context.Context) bool
	// Determines if the current spinner is an interactive spinner, where messages are updated periodically.
	// If false, the spinner is non-interactive, which means messages are rendered as a new console message on each
	// call to ShowSpinner, even when the title is unchanged.
	IsSpinnerInteractive() bool
	SupportsPromptDialog() bool
	PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)
	// Prompts the user for a single value
	Prompt(ctx context.Context, options ConsoleOptions) (string, error)
	// Prompts the user for a directory path.
	PromptDir(ctx context.Context, options ConsoleOptions) (string, error)
	// Prompts the user to select a single value from a set of values
	Select(ctx context.Context, options ConsoleOptions) (int, error)
	// Prompts the user to select zero or more values from a set of values
	MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)
	// Prompts the user to confirm an operation
	Confirm(ctx context.Context, options ConsoleOptions) (bool, error)
	// block terminal until the next enter
	WaitForEnter()
	// Writes a new line to the writer if there if the last two characters written are not '\n'
	EnsureBlankLine(ctx context.Context)
	// Sets the underlying writer for the console
	SetWriter(writer io.Writer)
	// Gets the underlying writer for the console
	GetWriter() io.Writer
	// Gets the standard input, output and error stream
	Handles() ConsoleHandles
	ConsoleShim
}

func NewConsole

func NewConsole(
	noPrompt bool,
	isTerminal bool,
	writers Writers,
	handles ConsoleHandles,
	formatter output.Formatter,
	externalPromptCfg *ExternalPromptConfiguration) Console

Creates a new console with the specified writers, handles and formatter. When externalPromptCfg is non nil, it is used instead of prompting on the console.

type ConsoleHandles

type ConsoleHandles struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

type ConsoleOptions

type ConsoleOptions struct {
	Message string
	Help    string
	Options []string

	// OptionDetails is an optional field that can be used to provide additional information about the options.
	OptionDetails []string
	DefaultValue  any

	// Prompt-only options
	IsPassword bool
}

type ConsoleShim

type ConsoleShim interface {
	// True if the console was instantiated with no format options.
	IsUnformatted() bool

	// Gets the underlying formatter used by the console
	GetFormatter() output.Formatter
}

A shim to allow a single Console construction in the application. To be removed once formatter and Console's responsibilities are reconciled

type ExternalPromptConfiguration

type ExternalPromptConfiguration struct {
	Endpoint string
	Key      string
	Client   httputil.HttpClient
}

ExternalPromptConfiguration allows configuring the console to delegate prompts to an external service.

type PromptDialog

type PromptDialog struct {
	Title       string
	Description string
	Prompts     []PromptDialogItem
}

type PromptDialogChoice

type PromptDialogChoice struct {
	Value       string
	Description string
}

type PromptDialogItem

type PromptDialogItem struct {
	ID           string
	Kind         string
	DisplayName  string
	Description  *string
	DefaultValue *string
	Required     bool
	Choices      []PromptDialogChoice
}

type ShowPreviewerOptions

type ShowPreviewerOptions struct {
	Prefix       string
	MaxLineCount int
	Title        string
}

ShowPreviewerOptions provide the settings to start a console previewer.

type SpinnerUxType

type SpinnerUxType int
const (
	Step SpinnerUxType = iota
	StepDone
	StepFailed
	StepWarning
	StepSkipped
)

func GetStepResultFormat

func GetStepResultFormat(result error) SpinnerUxType

type TerminalWidthFn

type TerminalWidthFn func() int

type Writers

type Writers struct {
	// The writer to write output to.
	Output io.Writer

	// The writer to write spinner output to. If nil, the spinner will write to Output.
	Spinner io.Writer
}

Writers that back the underlying console.

Jump to

Keyboard shortcuts

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