Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = Style{FgBlack}
	Red     = Style{FgRed}
	Green   = Style{FgGreen}
	Yellow  = Style{FgYellow}
	Blue    = Style{FgBlue}
	Magenta = Style{FgMagenta}
	Cyan    = Style{FgCyan}
	White   = Style{FgWhite}
)

Functions

This section is empty.

Types

type ANSICode

type ANSICode int
const (
	Reset ANSICode = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)
const (
	FgBlack ANSICode = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)
const (
	BgBlack ANSICode = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

type Attribute

type Attribute struct {
	Key   string
	Value string
}

type Item

type Item struct {
	Key         string
	Name        string
	Description string
	Attributes  []Attribute
}

Item represents an item for selection.

type Level

type Level int

Level represents the verbosity level.

const (
	// Trace shows all messages.
	Trace Level = iota
	// Debug shows Debug, Info, Warn, and Error messages.
	Debug
	// Info shows Info, Warn, and Error messages.
	Info
	// Warn shows Warn and Error messages.
	Warn
	// Error shows only Error messages.
	Error
	// None does not show any messages.
	None
)

type SearchFunc

type SearchFunc func(string, int) bool

SearchFunc is a function for searching and matching items in select.

type Style

type Style []ANSICode

type UI

type UI interface {
	// Output method independent of the verbosity level
	Printf(format string, a ...interface{})

	// Leveled output methods
	GetLevel() Level
	SetLevel(l Level)
	Tracef(s Style, format string, a ...interface{})
	Debugf(s Style, format string, a ...interface{})
	Infof(s Style, format string, a ...interface{})
	Warnf(s Style, format string, a ...interface{})
	Errorf(s Style, format string, a ...interface{})

	// User input methods
	Confrim(prompt string, Default bool) (bool, error)
	Ask(prompt, Default string, f ValidateFunc) (string, error)
	AskSecret(prompt string, confirm bool, f ValidateFunc) (string, error)
	Select(prompt string, size int, items []Item, f SearchFunc) (Item, error)
}

UI is the interface for interacting with users in command-line applications.

func NewInteractive

func NewInteractive(level Level) UI

NewInteractive creates a new interactive user interface. This is a concurrent-safe UI and can be used across multiple Go routines.

func NewNop

func NewNop() UI

NewNop creates a nop user interface for testing purposes.

type ValidateFunc

type ValidateFunc func(string) error

ValidateFunc is a function for validating user inputs.

Jump to

Keyboard shortcuts

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