cli

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cli provides interactive CLI primitives for tools that need more than plain stdout but less than a full Bubble Tea TUI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(prompt string, defaultYes bool) bool

Confirm prints a yes/no prompt and returns the user's choice. Default value is used when the user presses Enter without typing. Shows Y/n if defaultYes is true, y/N otherwise.

func Dim

func Dim(msg string)

Dim prints dimmed/muted text.

func Error

func Error(msg string)

Error prints a red error message with an X mark.

func Errorf

func Errorf(format string, a ...any)

Errorf prints a formatted red error message.

func Info

func Info(msg string)

Info prints a blue informational message with an info icon.

func Infof

func Infof(format string, a ...any)

Infof prints a formatted blue informational message.

func Input

func Input(prompt string, validate func(string) error) (string, error)

Input prompts for text input with optional validation. If validate is non-nil, the input is re-prompted on validation failure. Returns an error only if the user cancels with Ctrl+C.

func KeyValue

func KeyValue(key, value string)

KeyValue prints a key-value pair with the key dimmed and value normal.

func MultiSelect

func MultiSelect(prompt string, items []string) ([]string, []int, error)

MultiSelect presents a list of options with checkboxes and returns the selected items. Uses space/x to toggle, a to toggle all, arrow keys or j/k for navigation, Enter to confirm. Returns an error if the user cancels with Esc or Ctrl+C.

func Password

func Password(prompt string, validate func(string) error) (string, error)

Password prompts for masked text input with optional validation. Characters are displayed as bullet points (•). Returns an error only if the user cancels with Ctrl+C.

func Section

func Section(msg string)

Section prints a bold colored section header.

func SelectOne

func SelectOne(prompt string, items []string) (string, int, error)

SelectOne presents a list of options and returns the selected item and its index. Uses arrow keys or j/k for navigation, Enter to confirm. Supports type-to-filter when there are more than 10 items. Returns an error if the user cancels with Esc or Ctrl+C.

func Separator

func Separator()

Separator prints a horizontal divider line.

func Step

func Step(current, total int, msg string)

Step prints a numbered step indicator. Useful for multi-step CLI flows. Example: Step(1, 3, "Installing dependencies") → " 1/3 Installing dependencies"

func Success

func Success(msg string)

Success prints a green success message with a checkmark.

func Successf

func Successf(format string, a ...any)

Successf prints a formatted green success message.

func Title

func Title(msg string)

Title prints a bold underlined title.

func Warning

func Warning(msg string)

Warning prints a yellow warning message with an exclamation mark.

func Warningf

func Warningf(format string, a ...any)

Warningf prints a formatted yellow warning message.

Types

type Progress

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

Progress shows a progress bar that updates as work completes.

func NewProgress

func NewProgress(total int, label string) *Progress

NewProgress creates a progress bar with the given total and label.

func (*Progress) Done

func (p *Progress) Done()

Done completes the progress bar and moves to the next line.

func (*Progress) Increment

func (p *Progress) Increment(n int)

Increment advances the progress bar by n.

type SpinnerResult

type SpinnerResult struct {
	// Stop halts the spinner and clears the line.
	Stop func()
}

SpinnerResult is returned by Spin to stop the animation.

func Spin

func Spin(message string) *SpinnerResult

Spin shows an animated spinner with a message. Call Stop() on the returned SpinnerResult when done. The spinner runs in a background goroutine and clears the line on stop.

Jump to

Keyboard shortcuts

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