prompter

package module
v0.0.0-...-15789d5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 13 Imported by: 0

README

prompter

A small Bubble Tea-based prompt helper for building interactive CLI flows.

Install

go get github.com/olimci/prompter

Quick usage

package main

import (
	"context"

	"github.com/olimci/prompter"
)

func main() {
	ctx := context.Background()

	err := prompter.Start(func(ctx context.Context, p *prompter.Prompter) error {
		p.Log("Hello")

		name, err := p.AwaitInput(
			prompter.WithInputPrompt("Name: "),
		)
		if err != nil {
			return err
		}

		p.Logf("Hi %s", name)
		return nil
	}, prompter.WithContext(ctx))

	if err != nil {
		panic(err)
	}
}

Examples

Run any of the examples:

go run ./examples/credit-card
go run ./examples/message-box
go run ./examples/status
go run ./examples/keybinds
go run ./examples/status-keybinds
go run ./examples/noninteractive

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoninteractive = errors.New("prompter requires an interactive terminal")

ErrNoninteractive indicates that prompter could not acquire an interactive terminal.

Functions

func Start

func Start(f func(ctx context.Context, p *Prompter) error, opts ...Option) error

Types

type ConfirmStyles

type ConfirmStyles struct {
	Prompt         lipgloss.Style
	ActiveOption   lipgloss.Style
	InactiveOption lipgloss.Style
	Final          lipgloss.Style
}

type InputOption

type InputOption func(*inputOptions)

func WithInputCharLimit

func WithInputCharLimit(limit int) InputOption

func WithInputPlaceholder

func WithInputPlaceholder(placeholder string) InputOption

func WithInputPrompt

func WithInputPrompt(prompt string) InputOption

func WithInputSuggestions

func WithInputSuggestions(suggestions []string) InputOption

func WithInputValidate

func WithInputValidate(validate func(string) error) InputOption

func WithInputWidth

func WithInputWidth(width int) InputOption

type InputStyles

type InputStyles struct {
	Prompt      lipgloss.Style
	Text        lipgloss.Style
	Placeholder lipgloss.Style
	Cursor      lipgloss.Style
	Error       lipgloss.Style
	Final       lipgloss.Style
}

type Keybind

type Keybind struct {
	Key         string
	Event       string
	Description string
}

type KeybindEvent

type KeybindEvent struct {
	Key   string
	Event string
}

type KeybindHandle

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

func (*KeybindHandle) Clear

func (h *KeybindHandle) Clear() error

func (*KeybindHandle) Events

func (h *KeybindHandle) Events() <-chan KeybindEvent

func (*KeybindHandle) Set

func (h *KeybindHandle) Set(bindings []Keybind) error

type KeybindOption

type KeybindOption func(*keybindOptions)

func WithKeybindPrompt

func WithKeybindPrompt(prompt string) KeybindOption

func WithKeybindSeparator

func WithKeybindSeparator(separator string) KeybindOption

type MessageBoxHandle

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

func (*MessageBoxHandle) Clear

func (h *MessageBoxHandle) Clear() error

func (*MessageBoxHandle) Messages

func (h *MessageBoxHandle) Messages() <-chan string

type Option

type Option func(*options)

func WithContext

func WithContext(ctx context.Context) Option

func WithMaxHistoryLen

func WithMaxHistoryLen(max int) Option

func WithStyles

func WithStyles(styles *Styles) Option

func WithViewFunc

func WithViewFunc(view func(history []string, modal string) string) Option

type Prompter

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

func (*Prompter) AwaitConfirm

func (p *Prompter) AwaitConfirm(prompt string) (bool, error)

func (*Prompter) AwaitInput

func (p *Prompter) AwaitInput(opts ...InputOption) (string, error)

func (*Prompter) AwaitSelect

func (p *Prompter) AwaitSelect(prompt string, options []string) (string, error)

func (*Prompter) AwaitSelectDefault

func (p *Prompter) AwaitSelectDefault(prompt string, options []string, defaultValue string) (string, error)

func (*Prompter) Clear

func (p *Prompter) Clear()

func (*Prompter) Confirm

func (p *Prompter) Confirm(prompt string) (promise.Promise[bool], error)

func (*Prompter) Input

func (p *Prompter) Input(opts ...InputOption) (promise.Promise[string], error)

func (*Prompter) Keybinds

func (p *Prompter) Keybinds(bindings []Keybind, opts ...KeybindOption) (*KeybindHandle, error)

func (*Prompter) Log

func (p *Prompter) Log(msg string)

func (*Prompter) Logf

func (p *Prompter) Logf(format string, args ...any)

func (*Prompter) MessageBox

func (p *Prompter) MessageBox(opts ...InputOption) (*MessageBoxHandle, error)

func (*Prompter) Select

func (p *Prompter) Select(prompt string, options []string) (promise.Promise[string], error)

func (*Prompter) SelectDefault

func (p *Prompter) SelectDefault(prompt string, options []string, defaultValue string) (promise.Promise[string], error)

func (*Prompter) Status

func (p *Prompter) Status(message string) (*StatusHandle, error)

func (*Prompter) StatusKeybinds

func (p *Prompter) StatusKeybinds(message string, bindings []Keybind, opts ...KeybindOption) (*StatusKeybindHandle, error)

type SelectStyles

type SelectStyles struct {
	Prompt         lipgloss.Style
	Cursor         lipgloss.Style
	Option         lipgloss.Style
	SelectedOption lipgloss.Style
	Final          lipgloss.Style
}

type StatusHandle

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

func (*StatusHandle) Clear

func (h *StatusHandle) Clear() error

func (*StatusHandle) Error

func (h *StatusHandle) Error(message string) error

func (*StatusHandle) Idle

func (h *StatusHandle) Idle(message string) error

func (*StatusHandle) Message

func (h *StatusHandle) Message(message string) error

func (*StatusHandle) Progress

func (h *StatusHandle) Progress(message string, percent float64) error

func (*StatusHandle) SetProgress

func (h *StatusHandle) SetProgress(percent float64) error

func (*StatusHandle) Success

func (h *StatusHandle) Success(message string) error

func (*StatusHandle) Working

func (h *StatusHandle) Working(message string) error

type StatusKeybindHandle

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

func (*StatusKeybindHandle) Clear

func (h *StatusKeybindHandle) Clear() error

func (*StatusKeybindHandle) Error

func (h *StatusKeybindHandle) Error(message string) error

func (*StatusKeybindHandle) Events

func (h *StatusKeybindHandle) Events() <-chan KeybindEvent

func (*StatusKeybindHandle) Idle

func (h *StatusKeybindHandle) Idle(message string) error

func (*StatusKeybindHandle) Message

func (h *StatusKeybindHandle) Message(message string) error

func (*StatusKeybindHandle) Progress

func (h *StatusKeybindHandle) Progress(message string, percent float64) error

func (*StatusKeybindHandle) Set

func (h *StatusKeybindHandle) Set(bindings []Keybind) error

func (*StatusKeybindHandle) SetProgress

func (h *StatusKeybindHandle) SetProgress(percent float64) error

func (*StatusKeybindHandle) Success

func (h *StatusKeybindHandle) Success(message string) error

func (*StatusKeybindHandle) Working

func (h *StatusKeybindHandle) Working(message string) error

type StatusStyles

type StatusStyles struct {
	IdleIcon     lipgloss.Style
	Spinner      lipgloss.Style
	Message      lipgloss.Style
	FinalIcon    lipgloss.Style
	FinalMessage lipgloss.Style
	ErrorIcon    lipgloss.Style
	ErrorMessage lipgloss.Style
}

type Styles

type Styles struct {
	Confirm ConfirmStyles
	Input   InputStyles
	Select  SelectStyles
	Status  StatusStyles
}

func DefaultStyles

func DefaultStyles() *Styles

Directories

Path Synopsis
examples
credit-card command
keybinds command
message-box command
noninteractive command
status command
status-keybinds command

Jump to

Keyboard shortcuts

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