Documentation
¶
Overview ¶
Package tap provides high-level, clack-style terminal prompts, spinners, progress bars, and message helpers. The package exposes simple synchronous helper functions and manages a default interactive session under the hood.
Index ¶
- func Box(message string, title string, opts BoxOptions)
- func Confirm(opts ConfirmOptions) bool
- func CyanBorder(s string) string
- func GrayBorder(s string) string
- func Intro(title string)
- func MultiSelect[T any](opts MultiSelectOptions[T]) []T
- func Outro(message string)
- func Password(opts PasswordOptions) string
- func Select[T any](opts SelectOptions[T]) T
- func SetTermIO(in core.Reader, out core.Writer)
- func Text(opts TextOptions) string
- type BoxAlignment
- type BoxOptions
- type ConfirmOptions
- type MultiSelectOptions
- type PasswordOptions
- type Progress
- type ProgressOptions
- type SelectOption
- type SelectOptions
- type Spinner
- type SpinnerOptions
- type Stream
- type StreamOptions
- type TextOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Box ¶
func Box(message string, title string, opts BoxOptions)
Box renders a framed message with optional title and alignment using the current session writer or stdout if no session is active.
func Confirm ¶
func Confirm(opts ConfirmOptions) bool
Confirm displays a yes/no confirmation prompt and returns the selection. A terminal is created and cleaned up automatically per call.
func CyanBorder ¶
CyanBorder formats a string with a cyan box-drawing border.
func GrayBorder ¶
GrayBorder formats a string with a gray box-drawing border.
func Intro ¶
func Intro(title string)
Intro prints an introductory message using the current session writer or stdout if no session is active.
func MultiSelect ¶ added in v0.5.0
func MultiSelect[T any](opts MultiSelectOptions[T]) []T
MultiSelect displays a multi-selection list and returns the chosen typed values. A terminal is created and cleaned up automatically per call.
func Outro ¶
func Outro(message string)
Outro prints a closing message using the current session writer or stdout if no session is active.
func Password ¶
func Password(opts PasswordOptions) string
Password displays a masked text input prompt and returns the entered value. A terminal is created and cleaned up automatically per call.
func Select ¶
func Select[T any](opts SelectOptions[T]) T
Select displays a single-selection list and returns the chosen typed value. A terminal is created and cleaned up automatically per call.
func SetTermIO ¶ added in v0.4.0
SetTermIO sets a custom reader and writer used by helpers. Pass nil values to restore default terminal behavior.
func Text ¶
func Text(opts TextOptions) string
Text displays an interactive single-line text input prompt and returns the entered value. A terminal is created and cleaned up automatically per call.
Types ¶
type BoxAlignment ¶
type BoxAlignment = prompts.BoxAlignment
BoxAlignment is an alias of prompts.BoxAlignment to control box content alignment.
type BoxOptions ¶
type BoxOptions struct {
Columns int
WidthFraction float64
WidthAuto bool
TitlePadding int
ContentPadding int
TitleAlign BoxAlignment
ContentAlign BoxAlignment
Rounded bool
IncludePrefix bool
FormatBorder func(string) string
}
BoxOptions configures the Box message renderer.
type ConfirmOptions ¶
ConfirmOptions configures the Confirm prompt. I/O fields are managed by tap.
type MultiSelectOptions ¶ added in v0.5.0
type MultiSelectOptions[T any] struct { Message string Options []SelectOption[T] InitialValues []T MaxItems *int }
MultiSelectOptions configures the MultiSelect prompt. I/O fields are managed by tap.
type PasswordOptions ¶
type PasswordOptions struct {
Message string
DefaultValue string
InitialValue string
Validate func(string) error
}
PasswordOptions configures the Password prompt. I/O fields are managed by tap.
type Progress ¶ added in v0.4.0
type Progress struct {
// contains filtered or unexported fields
}
Progress wraps a progress bar and ensures terminal cleanup on Stop.
func NewProgress ¶
func NewProgress(opts ProgressOptions) *Progress
NewProgress creates a progress bar bound to a terminal writer (or the override writer set via SetTermIO in tests). The underlying terminal, when created, is cleaned up on Stop.
func (*Progress) Advance ¶ added in v0.4.0
Advance moves the progress bar forward by step and updates the message.
type ProgressOptions ¶
ProgressOptions configures a progress bar. Output is managed by tap.
type SelectOption ¶
SelectOption represents a selectable item with a typed value, label, and optional hint for display.
type SelectOptions ¶
type SelectOptions[T any] struct { Message string Options []SelectOption[T] InitialValue *T MaxItems *int }
SelectOptions configures the Select prompt. I/O fields are managed by tap.
type Spinner ¶ added in v0.4.0
type Spinner struct {
// contains filtered or unexported fields
}
Spinner wraps a spinner and ensures terminal cleanup on Stop.
func NewSpinner ¶
func NewSpinner(opts SpinnerOptions) *Spinner
NewSpinner creates a spinner bound to a terminal writer (or the override writer set via SetTermIO in tests). The underlying terminal, when created, is cleaned up on Stop.
func (*Spinner) IsCanceled ¶ added in v0.4.0
IsCanceled reports whether the spinner was canceled by the user.
func (*Spinner) IsCancelled ¶ added in v0.4.0
IsCancelled reports whether the spinner was cancelled by the user. Deprecated: Use IsCanceled for Go-idiomatic spelling.
type SpinnerOptions ¶
type SpinnerOptions struct {
Indicator string
Frames []string
Delay time.Duration
CancelMessage string
ErrorMessage string
}
SpinnerOptions configures a spinner. Output is managed by tap.
type Stream ¶ added in v0.6.0
type Stream struct {
// contains filtered or unexported fields
}
Stream wraps a styled live stream renderer and ensures terminal cleanup on Stop.
func NewStream ¶ added in v0.6.0
func NewStream(opts StreamOptions) *Stream
NewStream creates a live stream bound to a terminal writer (or override), and ensures the underlying terminal is closed on Stop.
func (*Stream) Start ¶ added in v0.6.0
Start prints the stream header and prepares to receive lines.
type StreamOptions ¶ added in v0.6.0
type StreamOptions struct {
ShowTimer bool
}
StreamOptions configures a live output stream. Output is managed by tap.