prompts

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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 = "○"
)

Unicode symbols for drawing styled prompts

View Source
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"
	Inverse       = "\033[7m"
	Strikethrough = "\033[9m"
)

ANSI color codes

Variables

This section is empty.

Functions

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(opts ConfirmOptions) any

Confirm creates a styled confirm prompt

func CyanBorder

func CyanBorder(s string) string

func GrayBorder

func GrayBorder(s string) string

Common border formatters for examples

func Intro

func Intro(title string, opts ...MessageOptions)

Intro prints an intro title (bar start + title).

func Outro

func Outro(message string, opts ...MessageOptions)

Outro prints a final outro (bar line, then bar end + message).

func Password added in v0.2.0

func Password(opts PasswordOptions) any

Password creates a styled password input prompt that masks user input

func Select

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

Select creates a styled select prompt

func Symbol

func Symbol(state core.ClackState) string

Symbol returns the appropriate symbol for a given state with color

func Text

func Text(opts TextOptions) any

Text creates a styled text input prompt

Types

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 ConfirmOptions

type ConfirmOptions struct {
	Message      string
	Active       string
	Inactive     string
	InitialValue bool
	Input        core.Reader
	Output       core.Writer
}

ConfirmOptions defines options for styled confirm prompt

type MessageOptions

type MessageOptions struct {
	Output Writer
}

MessageOptions configures simple message helpers output. If Output is nil, the helper functions are no-ops.

type PasswordOptions added in v0.2.0

type PasswordOptions struct {
	Message      string
	DefaultValue string
	InitialValue string
	Validate     func(string) error
	Input        core.Reader
	Output       core.Writer
}

PasswordOptions defines options for styled password prompt

type Progress

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

func (p *Progress) Advance(step int, msg string)

Advance updates progress by the given step and optionally updates message

func (*Progress) Message

func (p *Progress) Message(msg string)

Message updates the message without advancing progress

func (*Progress) Start

func (p *Progress) Start(msg string)

Start begins the progress bar animation

func (*Progress) Stop

func (p *Progress) Stop(msg string, code int)

Stop halts the progress bar and shows final state

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 Reader

type Reader = core.Reader

type SelectOption

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

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        core.Reader
	Output       core.Writer
}

SelectOptions defines options for styled select prompt

type Spinner added in v0.2.0

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner represents an animated spinner

func NewSpinner added in v0.2.0

func NewSpinner(opts SpinnerOptions) *Spinner

NewSpinner creates a new Spinner with defaults

func (*Spinner) IsCancelled added in v0.2.0

func (s *Spinner) IsCancelled() bool

IsCancelled reports whether Stop was called with cancel code (1)

func (*Spinner) Message added in v0.2.0

func (s *Spinner) Message(msg string)

Message updates the spinner message for next frame

func (*Spinner) Start added in v0.2.0

func (s *Spinner) Start(msg string)

Start begins the spinner animation

func (*Spinner) Stop added in v0.2.0

func (s *Spinner) Stop(msg string, code int)

Stop halts the spinner and prints a final line with a status symbol code: 0 submit, 1 cancel, >1 error

type SpinnerOptions added in v0.2.0

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 TextOptions

type TextOptions struct {
	Message      string
	Placeholder  string
	DefaultValue string
	InitialValue string
	Validate     func(string) error
	Input        core.Reader
	Output       core.Writer
}

TextOptions defines options for styled text prompt

type Writer

type Writer = core.Writer

Jump to

Keyboard shortcuts

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