Documentation
¶
Index ¶
- Constants
- func Confirm(opts ConfirmOptions) bool
- func Password(opts PasswordOptions) string
- func Select[T any](opts SelectOptions[T]) T
- func Text(opts TextOptions) string
- type ClackState
- type ConfirmOptions
- type EventHandler
- type Key
- type MockReadable
- type MockWritable
- type PasswordOptions
- 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() 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 SelectPrompt
- type TextOptions
- type ValidationError
- type Writer
Constants ¶
const ( CursorHide = "\x1b[?25l" CursorShow = "\x1b[?25h" EraseLine = "\x1b[K" CursorUp = "\x1b[A" EraseDown = "\x1b[J" )
Variables ¶
This section is empty.
Functions ¶
func Confirm ¶
func Confirm(opts ConfirmOptions) bool
func Password ¶
func Password(opts PasswordOptions) string
Password implements an unstyled password prompt that masks user input
func Text ¶
func Text(opts TextOptions) string
Types ¶
type ClackState ¶
type ClackState string
const ( StateInitial ClackState = "initial" StateActive ClackState = "active" StateCancel ClackState = "cancel" StateSubmit ClackState = "submit" StateError ClackState = "error" )
type ConfirmOptions ¶
type EventHandler ¶
type EventHandler any
type MockReadable ¶
type MockReadable struct {
// contains filtered or unexported fields
}
func NewMockReadable ¶
func NewMockReadable() *MockReadable
func (*MockReadable) Close ¶
func (m *MockReadable) Close() error
func (*MockReadable) EmitKeypress ¶
func (m *MockReadable) EmitKeypress(char string, key Key)
func (*MockReadable) SendKey ¶
func (m *MockReadable) SendKey(char string, key Key)
SendKey is a convenience method for testing
type MockWritable ¶
type MockWritable struct {
Buffer []string
// contains filtered or unexported fields
}
func NewMockWritable ¶
func NewMockWritable() *MockWritable
func (*MockWritable) Emit ¶
func (m *MockWritable) Emit(event string)
func (*MockWritable) GetFrames ¶
func (m *MockWritable) GetFrames() []string
GetFrames returns all written frames for testing
func (*MockWritable) On ¶
func (m *MockWritable) On(event string, handler func())
type PasswordOptions ¶
type PasswordOptions struct {
Message string
Placeholder string
DefaultValue string
InitialValue string
Input Reader
Output Writer
Validate func(string) error
}
PasswordOptions defines options for the unstyled password input prompt Behavior mirrors TextOptions but rendering masks user input.
type Prompt ¶
type Prompt struct {
// contains filtered or unexported fields
}
func NewPrompt ¶
func NewPrompt(options PromptOptions) *Prompt
NewPrompt creates a new prompt instance with default tracking
func NewPromptWithTracking ¶
func NewPromptWithTracking(options PromptOptions, trackValue bool) *Prompt
NewPromptWithTracking creates a new prompt instance with specified tracking
func (*Prompt) CursorSnapshot ¶
func (*Prompt) ErrorSnapshot ¶
func (*Prompt) SetImmediateValue ¶
SetImmediateValue updates the value in the current event-loop tick if possible. Falls back to enqueuing when called outside the loop.
func (*Prompt) SetValue ¶
SetValue schedules a value update (for tests or programmatic flows). In the event-loop refactor, this will post to the loop; for now, set under lock.
func (*Prompt) StateSnapshot ¶
func (p *Prompt) StateSnapshot() ClackState
func (*Prompt) UserInputSnapshot ¶
func (*Prompt) ValueSnapshot ¶
type PromptOptions ¶
type SelectOption ¶
SelectOption represents an option in a select prompt
type SelectOptions ¶
type SelectOptions[T any] struct { Message string Options []SelectOption[T] InitialValue *T Input Reader Output Writer Validate func(T) error }
SelectOptions holds the configuration for a select prompt
type SelectPrompt ¶
SelectPrompt is the core select prompt implementation
func NewSelectPrompt ¶
func NewSelectPrompt[T any](opts SelectOptions[T]) *SelectPrompt[T]
NewSelectPrompt creates a new select prompt
type TextOptions ¶
type ValidationError ¶
type ValidationError struct {
Message string
}
func NewValidationError ¶
func NewValidationError(message string) *ValidationError
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string