prompting

package
v0.13.0-beta3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// PrompterEnvironmentVariable is the environment variable in which the
	// Mutagen prompter identifier is stored.
	PrompterEnvironmentVariable = "MUTAGEN_PROMPTER"
)

Variables

This section is empty.

Functions

func Message

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 command line prompting using an automatically determined response mode.

func PromptCommandLineWithResponseMode

func PromptCommandLineWithResponseMode(prompt string, mode ResponseMode) (string, error)

PromptCommandLineWithResponseMode performs command line prompting using the specified response mode.

func RegisterPrompter

func RegisterPrompter(prompter Prompter) (string, error)

RegisterPrompter registers a prompter with the global registry. It automatically generates a unique identifier for the prompter.

func RegisterPrompterWithIdentifier added in v0.12.0

func RegisterPrompterWithIdentifier(identifier string, prompter Prompter) error

RegisterPrompterWithIdentifier registers a prompter with the global registry using the specified identifier.

func UnregisterPrompter

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 Prompter

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. Implementations are not required to be safe for concurrent usage.

type ResponseMode

type ResponseMode uint8

ResponseMode encodes how a prompt response should be displayed and validated.

const (
	// ResponseModeSecret indicates that a prompt response shouldn't be echoed.
	ResponseModeSecret ResponseMode = iota
	// ResponseModeMasked indicates that a prompt response should be masked.
	ResponseModeMasked
	// ResponseModeEcho indicates that a prompt response should be echoed.
	ResponseModeEcho
)

Jump to

Keyboard shortcuts

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