core

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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 Select

func Select[T any](opts SelectOptions[T]) T

Select creates and runs a select prompt

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 ConfirmOptions struct {
	Message      string
	Active       string
	Inactive     string
	InitialValue bool
	Input        Reader
	Output       Writer
}

type EventHandler

type EventHandler any

type Key

type Key struct {
	Name     string
	Sequence string
	Ctrl     bool
	Meta     bool
	Shift    bool
}

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) On

func (m *MockReadable) On(event string, handler func(string, Key))

func (*MockReadable) Read

func (m *MockReadable) Read(p []byte) (int, error)

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())

func (*MockWritable) Write

func (m *MockWritable) Write(p []byte) (int, error)

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 (p *Prompt) CursorSnapshot() int

func (*Prompt) Emit

func (p *Prompt) Emit(event string, args ...any)

Emit emits an event to all subscribers

func (*Prompt) ErrorSnapshot

func (p *Prompt) ErrorSnapshot() string

func (*Prompt) On

func (p *Prompt) On(event string, handler any)

On subscribes to an event

func (*Prompt) Prompt

func (p *Prompt) Prompt() any

Prompt starts the prompt and returns the result

func (*Prompt) SetImmediateValue

func (p *Prompt) SetImmediateValue(v any)

SetImmediateValue updates the value in the current event-loop tick if possible. Falls back to enqueuing when called outside the loop.

func (*Prompt) SetValue

func (p *Prompt) SetValue(v any)

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 (p *Prompt) UserInputSnapshot() string

func (*Prompt) ValueSnapshot

func (p *Prompt) ValueSnapshot() any

type PromptOptions

type PromptOptions struct {
	Render           func(*Prompt) string
	InitialValue     any
	InitialUserInput string
	Validate         func(any) error
	Input            Reader
	Output           Writer
	Debug            bool
	Signal           context.Context
}

type Reader

type Reader interface {
	io.Reader
	On(event string, handler func(string, Key))
}

type SelectOption

type SelectOption[T any] struct {
	Value T
	Label string
	Hint  string
}

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

type SelectPrompt[T any] struct {
	*Prompt
	// contains filtered or unexported fields
}

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 TextOptions struct {
	Message      string
	Placeholder  string
	DefaultValue string
	InitialValue string
	Input        Reader
	Output       Writer
	Validate     func(string) error
}

type ValidationError

type ValidationError struct {
	Message string
}

func NewValidationError

func NewValidationError(message string) *ValidationError

func (*ValidationError) Error

func (e *ValidationError) Error() string

type Writer

type Writer interface {
	io.Writer
	On(event string, handler func())
	Emit(event string)
}

Jump to

Keyboard shortcuts

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