Documentation
¶
Index ¶
- Constants
- func Autocomplete(ctx context.Context, opts AutocompleteOptions) string
- func Box(message string, title string, opts BoxOptions)
- func Cancel(message string, opts ...MessageOptions)
- func Confirm(ctx context.Context, opts ConfirmOptions) bool
- func CyanBorder(s string) string
- func GrayBorder(s string) string
- func GreenBorder(s string) string
- func Intro(title string, opts ...MessageOptions)
- func Message(message string, opts ...MessageOptions)
- func MultiSelect[T any](ctx context.Context, opts MultiSelectOptions[T]) []T
- func Outro(message string, opts ...MessageOptions)
- func Password(ctx context.Context, opts PasswordOptions) string
- func RedBorder(s string) string
- func Select[T any](ctx context.Context, opts SelectOptions[T]) T
- func SetTermIO(in Reader, out Writer)
- func Symbol(state ClackState) string
- func Table(headers []string, rows [][]string, opts TableOptions)
- func Text(ctx context.Context, opts TextOptions) string
- func YellowBorder(s string) string
- type AutocompleteOptions
- type BoxAlignment
- type BoxOptions
- type ClackState
- type ConfirmOptions
- type EventHandler
- type Key
- type MessageOptions
- type MockReadable
- type MockWritable
- type MultiSelectOptions
- type PasswordOptions
- type Progress
- type ProgressOptions
- type Prompt
- func (p *Prompt) CursorSnapshot() int
- func (p *Prompt) Emit(event string, args ...any)
- func (p *Prompt) ErrorSnapshot() string
- func (p *Prompt) On(event string, handler any)
- func (p *Prompt) Prompt(ctx context.Context) any
- func (p *Prompt) SetImmediateValue(v any)
- func (p *Prompt) SetValue(v any)
- func (p *Prompt) StateSnapshot() ClackState
- func (p *Prompt) UserInputSnapshot() string
- func (p *Prompt) ValueSnapshot() any
- type PromptOptions
- type Reader
- type SelectOption
- type SelectOptions
- type Spinner
- type SpinnerOptions
- type Stream
- type StreamOptions
- type TableAlignment
- type TableColor
- type TableOptions
- type TableStyle
- type TextOptions
- type ValidationError
- type Writer
Constants ¶
const ( // Step symbols StepActive = "◆" StepCancel = "■" StepError = "▲" StepSubmit = "◇" // Bar symbols Bar = "│" BarH = "─" BarStart = "┌" BarStartRight = "┐" BarEnd = "└" BarEndRight = "┘" // Corner symbols (rounded) CornerTopLeft = "╭" CornerTopRight = "╮" CornerBottomLeft = "╰" CornerBottomRight = "╯" // Radio symbols RadioActive = "●" RadioInactive = "○" // Checkbox symbols for multiselect CheckboxChecked = "◼" CheckboxUnchecked = "◻" )
Unicode symbols for drawing styled prompts
const ( Reset = "\033[0m" // Colors Gray = "\033[90m" Red = "\033[91m" Green = "\033[92m" Yellow = "\033[93m" Cyan = "\033[96m" // Text styles Dim = "\033[2m" Bold = "\033[1m" Inverse = "\033[7m" Strikethrough = "\033[9m" )
ANSI color codes
const ( // Table border symbols TableTopLeft = "┌" TableTopRight = "┐" TableBottomLeft = "└" TableBottomRight = "┘" TableTopTee = "┬" TableBottomTee = "┴" TableLeftTee = "├" TableRightTee = "┤" TableCross = "┼" TableHorizontal = "─" TableVertical = "│" )
Table symbols
const ( CursorHide = terminal.CursorHide CursorShow = terminal.CursorShow EraseLine = terminal.ClearLine CursorUp = terminal.CursorUp EraseDown = terminal.EraseDown )
Variables ¶
This section is empty.
Functions ¶
func Autocomplete ¶ added in v0.10.0
func Autocomplete(ctx context.Context, opts AutocompleteOptions) string
Autocomplete renders a text prompt with inline suggestions.
func Box ¶
func Box(message string, title string, opts BoxOptions)
Box renders a framed message with optional title.
func Cancel ¶
func Cancel(message string, opts ...MessageOptions)
Cancel prints a cancel-styled message (bar end + red message).
func Confirm ¶
func Confirm(ctx context.Context, opts ConfirmOptions) bool
Confirm creates a styled confirm prompt
func CyanBorder ¶
func GrayBorder ¶
func GreenBorder ¶ added in v0.10.0
func Intro ¶
func Intro(title string, opts ...MessageOptions)
Intro prints an intro title (bar start + title).
func Message ¶ added in v0.9.0
func Message(message string, opts ...MessageOptions)
func MultiSelect ¶ added in v0.5.0
func MultiSelect[T any](ctx context.Context, opts MultiSelectOptions[T]) []T
MultiSelect renders a styled multi-select and returns selected values.
func Outro ¶
func Outro(message string, opts ...MessageOptions)
Outro prints a final outro (bar line, then bar end + message).
func Password ¶
func Password(ctx context.Context, opts PasswordOptions) string
Password creates a styled password input prompt that masks user input
func Select ¶
func Select[T any](ctx context.Context, opts SelectOptions[T]) T
Select creates a styled select prompt
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 Symbol ¶ added in v0.7.0
func Symbol(state ClackState) string
Symbol returns the appropriate symbol for a given state with color
func Table ¶ added in v0.9.0
func Table(headers []string, rows [][]string, opts TableOptions)
Table renders a formatted table with headers and rows
func Text ¶
func Text(ctx context.Context, opts TextOptions) string
Text creates a styled text input prompt
func YellowBorder ¶ added in v0.10.0
Types ¶
type AutocompleteOptions ¶ added in v0.10.0
type AutocompleteOptions struct {
Message string
Placeholder string
DefaultValue string
InitialValue string
Validate func(string) error
Suggest func(string) []string // returns suggestion list for current input
MaxResults int // maximum suggestions to show (default 5)
Input Reader
Output Writer
}
AutocompleteOptions defines options for styled autocomplete text prompt
type BoxAlignment ¶
type BoxAlignment string
const ( BoxAlignLeft BoxAlignment = "left" BoxAlignCenter BoxAlignment = "center" BoxAlignRight BoxAlignment = "right" )
type BoxOptions ¶
type BoxOptions struct {
Output Writer
Columns int // terminal columns; if 0, default to 80
WidthFraction float64 // 0..1 fraction of Columns; ignored if WidthAuto
WidthAuto bool // compute width to content automatically (capped by Columns)
TitlePadding int // spaces padding inside borders around title
ContentPadding int // spaces padding inside borders around content lines
TitleAlign BoxAlignment // left|center|right
ContentAlign BoxAlignment // left|center|right
Rounded bool
IncludePrefix bool
FormatBorder func(string) string // formatter for border glyphs (e.g., color)
}
type ClackState ¶ added in v0.7.0
type ClackState string
const ( StateInitial ClackState = "initial" StateActive ClackState = "active" StateCancel ClackState = "cancel" StateSubmit ClackState = "submit" StateError ClackState = "error" )
type ConfirmOptions ¶
type ConfirmOptions struct {
Message string
Active string
Inactive string
InitialValue bool
Input Reader
Output Writer
}
ConfirmOptions defines options for styled confirm prompt
type EventHandler ¶ added in v0.7.0
type EventHandler any
type MessageOptions ¶ added in v0.7.0
type MessageOptions struct {
Output Writer
}
MessageOptions configures simple message helpers output. If Output is nil, the helper functions are no-ops.
type MockReadable ¶ added in v0.7.0
type MockReadable struct {
// contains filtered or unexported fields
}
func NewMockReadable ¶ added in v0.7.0
func NewMockReadable() *MockReadable
func (*MockReadable) Close ¶ added in v0.7.0
func (m *MockReadable) Close() error
func (*MockReadable) EmitKeypress ¶ added in v0.7.0
func (m *MockReadable) EmitKeypress(char string, key Key)
func (*MockReadable) On ¶ added in v0.7.0
func (m *MockReadable) On(event string, handler func(string, Key))
func (*MockReadable) SendKey ¶ added in v0.7.0
func (m *MockReadable) SendKey(char string, key Key)
SendKey is a convenience method for testing
type MockWritable ¶ added in v0.7.0
type MockWritable struct {
Buffer []string
// contains filtered or unexported fields
}
func NewMockWritable ¶ added in v0.7.0
func NewMockWritable() *MockWritable
func (*MockWritable) Emit ¶ added in v0.7.0
func (m *MockWritable) Emit(event string)
func (*MockWritable) GetFrames ¶ added in v0.7.0
func (m *MockWritable) GetFrames() []string
GetFrames returns all written frames for testing
func (*MockWritable) On ¶ added in v0.7.0
func (m *MockWritable) On(event string, handler func())
type MultiSelectOptions ¶ added in v0.5.0
type MultiSelectOptions[T any] struct { Message string Options []SelectOption[T] InitialValues []T MaxItems *int Input Reader Output Writer }
MultiSelectOptions defines options for styled multi-select prompt
type PasswordOptions ¶
type PasswordOptions struct {
Message string
DefaultValue string
InitialValue string
Validate func(string) error
Input Reader
Output Writer
}
PasswordOptions defines options for styled password prompt
type Progress ¶ added in v0.4.0
type Progress struct {
// contains filtered or unexported fields
}
Progress represents a progress bar that wraps spinner functionality
func NewProgress ¶
func NewProgress(opts ProgressOptions) *Progress
NewProgress creates a new progress bar
func (*Progress) Advance ¶ added in v0.4.0
Advance updates progress by the given step and optionally updates message
type ProgressOptions ¶
type ProgressOptions struct {
Style string // "light", "heavy", "block"
Max int // maximum value (default 100)
Size int // bar width in characters (default 40)
Output Writer
}
ProgressOptions configures the progress bar
type Prompt ¶ added in v0.7.0
type Prompt struct {
// contains filtered or unexported fields
}
func NewPrompt ¶ added in v0.7.0
func NewPrompt(options PromptOptions) *Prompt
NewPrompt creates a new prompt instance with default tracking
func NewPromptWithTracking ¶ added in v0.7.0
func NewPromptWithTracking(options PromptOptions, trackValue bool) *Prompt
NewPromptWithTracking creates a new prompt instance with specified tracking
func (*Prompt) CursorSnapshot ¶ added in v0.7.0
func (*Prompt) ErrorSnapshot ¶ added in v0.7.0
func (*Prompt) SetImmediateValue ¶ added in v0.7.0
SetImmediateValue updates the value in the current event-loop tick if possible. Falls back to enqueuing when called outside the loop.
func (*Prompt) SetValue ¶ added in v0.7.0
SetValue schedules a value update (for tests or programmatic flows). When called from within the event loop, it updates immediately. When called from outside, it enqueues an event.
func (*Prompt) StateSnapshot ¶ added in v0.7.0
func (p *Prompt) StateSnapshot() ClackState
func (*Prompt) UserInputSnapshot ¶ added in v0.7.0
func (*Prompt) ValueSnapshot ¶ added in v0.7.0
type PromptOptions ¶ added in v0.7.0
type SelectOption ¶
SelectOption represents an option in a styled select prompt
type SelectOptions ¶
type SelectOptions[T any] struct { Message string Options []SelectOption[T] InitialValue *T MaxItems *int Input Reader Output Writer }
SelectOptions defines options for styled select prompt
type Spinner ¶ added in v0.4.0
type Spinner struct {
// contains filtered or unexported fields
}
Spinner represents an animated spinner
func NewSpinner ¶
func NewSpinner(opts SpinnerOptions) *Spinner
NewSpinner creates a new Spinner with defaults
func (*Spinner) IsCancelled ¶ added in v0.4.0
IsCancelled reports whether Stop was called with cancel code (1)
type SpinnerOptions ¶
type SpinnerOptions struct {
Indicator string // "dots" (default) or "timer"
Frames []string // custom frames; defaults to unicode spinner frames
Delay time.Duration
Output Writer
CancelMessage string
ErrorMessage string
}
SpinnerOptions configures the spinner behavior
type Stream ¶ added in v0.6.0
type Stream struct {
// contains filtered or unexported fields
}
Stream renders a live stream area with clack-like styling Use Start to begin, WriteLine/Pipe to add content, and Stop to finalize.
func NewStream ¶ added in v0.6.0
func NewStream(opts StreamOptions) *Stream
NewStream creates a Stream
type StreamOptions ¶ added in v0.6.0
type StreamOptions struct {
Output Writer
// If true, show elapsed time on finalize line
ShowTimer bool
}
StreamOptions configure the styled stream renderer
type TableAlignment ¶ added in v0.9.0
type TableAlignment string
const ( TableAlignLeft TableAlignment = "left" TableAlignCenter TableAlignment = "center" TableAlignRight TableAlignment = "right" )
type TableColor ¶ added in v0.9.0
type TableColor string
const ( TableColorDefault TableColor = "default" TableColorGray TableColor = "gray" TableColorRed TableColor = "red" TableColorGreen TableColor = "green" TableColorYellow TableColor = "yellow" TableColorCyan TableColor = "cyan" )
type TableOptions ¶ added in v0.9.0
type TableOptions struct {
Output Writer
ShowBorders bool
IncludePrefix bool
MaxWidth int
ColumnAlignments []TableAlignment
HeaderStyle TableStyle
HeaderColor TableColor
FormatBorder func(string) string
}
TableOptions defines options for styled table rendering
type TableStyle ¶ added in v0.9.0
type TableStyle string
const ( TableStyleNormal TableStyle = "normal" TableStyleBold TableStyle = "bold" TableStyleDim TableStyle = "dim" )
type TextOptions ¶
type TextOptions struct {
Message string
Placeholder string
DefaultValue string
InitialValue string
Validate func(string) error
Input Reader
Output Writer
}
TextOptions defines options for styled text prompt
type ValidationError ¶ added in v0.7.0
type ValidationError struct {
Message string
}
func NewValidationError ¶ added in v0.7.0
func NewValidationError(message string) *ValidationError
func (*ValidationError) Error ¶ added in v0.7.0
func (e *ValidationError) Error() string