Documentation
¶
Index ¶
- func NewProgressLog(lines int, prefix, title, header string) *progressLog
- type Asker
- type AskerConsole
- func (c *AskerConsole) Confirm(ctx context.Context, options ConsoleOptions) (bool, error)
- func (c *AskerConsole) DoInteraction(action func() error) error
- func (c *AskerConsole) EnsureBlankLine(ctx context.Context)
- func (c *AskerConsole) GetFormatter() output.Formatter
- func (c *AskerConsole) GetWriter() io.Writer
- func (c *AskerConsole) Handles() ConsoleHandles
- func (c *AskerConsole) IsSpinnerInteractive() bool
- func (c *AskerConsole) IsSpinnerRunning(ctx context.Context) bool
- func (c *AskerConsole) IsUnformatted() bool
- func (c *AskerConsole) Message(ctx context.Context, message string)
- func (c *AskerConsole) MessageUxItem(ctx context.Context, item ux.UxItem)
- func (c *AskerConsole) MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)
- func (c *AskerConsole) Prompt(ctx context.Context, options ConsoleOptions) (string, error)
- func (c *AskerConsole) PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)
- func (c *AskerConsole) PromptFs(ctx context.Context, options ConsoleOptions, fsOpts FsOptions) (string, error)
- func (c *AskerConsole) Select(ctx context.Context, options ConsoleOptions) (int, error)
- func (c *AskerConsole) SetWriter(writer io.Writer)
- func (c *AskerConsole) ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer
- func (c *AskerConsole) ShowSpinner(ctx context.Context, title string, format SpinnerUxType)
- func (c *AskerConsole) StopPreviewer(ctx context.Context, keepLogs bool)
- func (c *AskerConsole) StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)
- func (c *AskerConsole) SupportsPromptDialog() bool
- func (c *AskerConsole) WaitForEnter()
- func (c *AskerConsole) WarnForFeature(ctx context.Context, key alpha.FeatureId)
- type Console
- type ConsoleHandles
- type ConsoleOptions
- type ConsoleShim
- type ExternalPromptConfiguration
- type FsOptions
- type FsSuggestOptions
- type PromptDialog
- type PromptDialogChoice
- type PromptDialogItem
- type ShowPreviewerOptions
- type SpinnerUxType
- type TerminalWidthFn
- type Writers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewProgressLog ¶
NewProgressLog returns a new instance of a progressLog.
Types ¶
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) DoInteraction ¶
func (c *AskerConsole) DoInteraction(action func() error) error
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) PromptFs ¶
func (c *AskerConsole) PromptFs(ctx context.Context, options ConsoleOptions, fsOpts FsOptions) (string, error)
PromptFs prompts the user for a filesystem path or directory
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) 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)
// PromptFs prompts the user for a filesystem path or directory.
PromptFs(ctx context.Context, options ConsoleOptions, fsOptions FsOptions) (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
// Executes an interactive action, managing spinner state
DoInteraction(action func() error) error
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 ConsoleOptions ¶
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
Transporter policy.Transporter
}
ExternalPromptConfiguration allows configuring the console to delegate prompts to an external service.
type FsOptions ¶
type FsOptions struct {
// Root directory.
Root string
// Path suggestion options.
SuggestOpts FsSuggestOptions
}
FsOptions provides options for prompting a filesystem path or directory.
type FsSuggestOptions ¶
type FsSuggestOptions struct {
// Exclude the current directory './' in suggestions. Only applicable if displaying directories.
ExcludeCurrentDir bool
// Include hidden files in suggestions.
IncludeHiddenFiles bool
// Exclude directories from suggestions.
ExcludeDirectories bool
// Exclude files from suggestions.
ExcludeFiles bool
}
FsSuggestOptions provides options for listing filesystem suggestions.
type PromptDialog ¶
type PromptDialog struct {
Title string
Description string
Prompts []PromptDialogItem
}
type PromptDialogChoice ¶
type PromptDialogItem ¶
type ShowPreviewerOptions ¶
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