Documentation
¶
Index ¶
- Constants
- Variables
- func Bold(text string) string
- func CommandList(cmds []CommandEntry) string
- func Confirm(label string, defaultYes bool) (bool, error)
- func Cyan(text string) string
- func Dim(text string) string
- func ErrBold(text string) string
- func ErrDim(text string) string
- func ErrError(msg string) string
- func ErrGreen(text string) string
- func ErrRed(text string) string
- func ErrSuccess(msg string) string
- func ErrWarning(msg string) string
- func ErrYellow(text string) string
- func FormatDuration(d time.Duration) string
- func FormatError(brief string, detail string, suggestion string) string
- func Gray(text string) string
- func Green(text string) string
- func Label(text string, width int) string
- func PromptHidden(label string) (string, error)
- func PromptText(label, defaultVal string) (string, error)
- func Red(text string) string
- func RequireStdoutTTY() error
- func SelectFromList(label string, items []string) (int, error)
- func SetColorEnabled(enabled bool)
- func Step(current, total int, title string) string
- func Success(msg string) string
- func Warning(msg string) string
- func Yellow(text string) string
- type CommandEntry
- type Spinner
Constants ¶
const ( IconOK = "✓" IconWarn = "⚠" IconFail = "✗" )
Status icons. Keep these in one place so prompts, results, and plain-text fallbacks all use the same glyph.
Variables ¶
var ( // SuccessStyle is for completed actions and passing status glyphs. SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("2")) // WarningStyle is for warnings and cautionary prompts. WarningStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("3")) // ErrorStyle is for failures and error glyphs. ErrorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("1")) // TitleStyle is for prompt headings and emphasized labels. TitleStyle = lipgloss.NewStyle().Bold(true) // HelperStyle is for de-emphasized hint text and secondary labels. HelperStyle = lipgloss.NewStyle().Foreground(_ld(lipgloss.Color("252"), lipgloss.Color("250"))) // NoColorStyle is the fallback when color output is disabled. NoColorStyle = lipgloss.NewStyle().Foreground(lipgloss.NoColor{}) )
var ErrCancelled = errors.New("cancelled")
ErrCancelled is returned when the user cancels input (Ctrl+C or Esc).
var ErrNoTTY = errors.New("no interactive terminal available")
ErrNoTTY is returned when a TUI prompt is called without an interactive terminal.
Functions ¶
func CommandList ¶
func CommandList(cmds []CommandEntry) string
CommandList formats commands in aligned columns.
func Confirm ¶ added in v0.7.169
Confirm presents a y/n prompt and returns the boolean result. Returns ErrCancelled if the user presses Ctrl+C or Esc. Returns ErrNoTTY if stdin is not a terminal.
func ErrSuccess ¶ added in v0.7.51
ErrSuccess formats a success message using stderr color detection.
func ErrWarning ¶ added in v0.7.51
ErrWarning formats a warning message using stderr color detection.
func FormatDuration ¶ added in v0.7.136
FormatDuration formats a duration for display in status messages.
func FormatError ¶
FormatError formats a red error with optional detail and suggestion.
func PromptHidden ¶ added in v0.7.169
PromptHidden prompts the user for hidden input (e.g. API keys). Returns ErrCancelled if the user presses Ctrl+C or Esc. Returns ErrNoTTY if stdin is not a terminal.
func PromptText ¶ added in v0.7.169
PromptText prompts for text input with an optional default value shown as placeholder. If the user enters nothing and presses Enter, the default value is returned. Returns ErrCancelled if the user presses Ctrl+C or Esc. Returns ErrNoTTY if stdin is not a terminal or CI is set.
func RequireStdoutTTY ¶ added in v0.7.169
func RequireStdoutTTY() error
RequireStdoutTTY returns ErrNoTTY if stdout is not an interactive terminal. Use this for full-screen TUI programs that write to stdout.
func SelectFromList ¶ added in v0.7.169
SelectFromList presents a list of items and returns the selected index. Returns ErrCancelled if the user presses Ctrl+C or Esc. Returns ErrNoTTY if stdin is not a terminal.
func SetColorEnabled ¶
func SetColorEnabled(enabled bool)
SetColorEnabled overrides automatic color detection for both stdout and stderr.
Types ¶
type CommandEntry ¶
CommandEntry describes a command for list formatting.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner shows a braille dot animation on stderr during long operations. No-op when stderr is not a TTY.