prompt

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package prompt provides facilities for classifying prompts, displaying prompts, and coordinating prompters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Message added in v0.6.0

func Message(identifier, message string) error

Message invokes the Message method on a prompter in the global registry. If the prompter identifier provided is an empty string, this method is a no-op and returns a nil error.

func Prompt

func Prompt(identifier, prompt string) (string, error)

Prompt invokes the Prompt method on a prompter in the global registry.

func PromptCommandLine

func PromptCommandLine(prompt string) (string, error)

PromptCommandLine performs prompting on the command line.

func RegisterPrompter added in v0.6.0

func RegisterPrompter(prompter Prompter) (string, error)

RegisterPrompter registers a prompter with the global registry. It generates a unique identifier for the prompter that can be used when requesting prompting.

func UnregisterPrompter added in v0.6.0

func UnregisterPrompter(identifier string)

UnregisterPrompter unregisters a prompter from the global registry. If the prompter is not registered, this method panics. If a prompter is unregistered with prompts pending for it, they will be cancelled.

Types

type PromptKind

type PromptKind uint8

PromptKind represents the type of a prompt and how it should be displayed.

const (
	// PromptKindSecret indicates a prompt for which responses should not be
	// echoed.
	PromptKindSecret PromptKind = iota
	// PromptKindEcho indicates a prompt for which responses should be echoed.
	PromptKindEcho
	// PromptKindBinary indicates a prompt for which responses should be echoed,
	// and additionally should be restricted to yes/no answers (potentially with
	// an alternative input control in the case of GUI input).
	PromptKindBinary
)

func Classify

func Classify(prompt string) PromptKind

Classify classifies a prompt based on its text.

type Prompter added in v0.6.0

type Prompter interface {
	// Message should print a message to the user, returning an error if this is
	// not possible.
	Message(string) error
	// Prompt should print a prompt to the user, returning the user's response
	// or an error if this is not possible.
	Prompt(string) (string, error)
}

Prompter is the interface to which types supporting prompting must adhere.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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