console

package
v0.1.0-dev.20260219203536 Latest Latest
Warning

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

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

Documentation

Overview

Package console provides an interactive terminal UI for guided workflows. It uses Bubble Tea for the TUI framework and supports session-based state machines that present information and collect user responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Console

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

Console manages interactive terminal sessions.

func New

func New() *Console

New creates a new Console with default settings.

func (*Console) Error

func (c *Console) Error(msg string)

Error prints an error message.

func (*Console) Info

func (c *Console) Info(msg string)

Info prints an info message.

func (*Console) Print

func (c *Console) Print(text string)

Print outputs styled text without a session.

func (*Console) PrintStyled

func (c *Console) PrintStyled(text string, style func(string) string)

PrintStyled outputs text with the given style.

func (*Console) Run

func (c *Console) Run(session Session) (any, error)

Run executes an interactive session. Returns the session's result after completion, or an error.

func (*Console) RunInline

func (c *Console) RunInline(session Session) (any, error)

RunInline executes a session without alternate screen. Useful for simpler interactions that don't need full-screen mode.

func (*Console) Styles

func (c *Console) Styles() *Styles

Styles returns the console's styles.

func (*Console) Success

func (c *Console) Success(msg string)

Success prints a success message.

func (*Console) Warning

func (c *Console) Warning(msg string)

Warning prints a warning message.

func (*Console) WithInput

func (c *Console) WithInput(r io.Reader) *Console

WithInput sets the input reader.

func (*Console) WithOutput

func (c *Console) WithOutput(w io.Writer) *Console

WithOutput sets the output writer.

func (*Console) WithStyles

func (c *Console) WithStyles(s *Styles) *Console

WithStyles sets custom styles.

type Model

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

Model is the Bubble Tea model for interactive sessions.

func NewModel

func NewModel(session Session) *Model

NewModel creates a new console model for the given session.

func (*Model) BorderedBox

func (m *Model) BorderedBox(title, content string) string

BorderedBox creates a bordered box with the given title and content.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init initializes the model.

func (*Model) SetStyles

func (m *Model) SetStyles(styles *Styles)

SetStyles sets custom styles.

func (*Model) Styles

func (m *Model) Styles() *Styles

Styles returns the model's styles for customization.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages.

func (*Model) View

func (m *Model) View() string

View renders the model.

func (*Model) WithWidth

func (m *Model) WithWidth(width int) *Model

WithWidth sets the terminal width.

type Option

type Option struct {
	// Label is the display text.
	Label string

	// Description provides additional context.
	Description string

	// Value is the underlying value returned when selected.
	Value string
}

Option represents a selectable choice.

type Session

type Session interface {
	// Next advances the session and returns the next step to display.
	// Returns nil when the session is complete.
	Next() *Step

	// Respond processes the user's response to the current step.
	// The response format depends on the step type:
	//   - Confirm: "yes" or "no"
	//   - Select: index of selected option (as string)
	//   - Input: the text entered
	Respond(response string) error

	// Current returns the current step, or nil if not started.
	Current() *Step

	// Complete returns true if the session has finished.
	Complete() bool

	// Result returns the session's final result after completion.
	// The type depends on the session implementation.
	Result() any

	// Error returns any error that terminated the session.
	Error() error
}

Session defines the interface for interactive workflows. A Session is a state machine that presents content and collects responses.

type Step

type Step struct {
	// Type determines how the step is rendered and what input is expected.
	Type StepType

	// Title is a short heading for the step.
	Title string

	// Content is the main body, rendered as markdown.
	Content string

	// Options are the choices for StepSelect.
	Options []Option

	// Default is the default value for StepInput or StepConfirm.
	Default string

	// Progress is the completion percentage (0-100) for StepProgress.
	Progress int

	// Error contains the error for StepError.
	Error error
}

Step represents a single interaction in the session.

type StepType

type StepType int

StepType identifies the kind of user interaction expected.

const (
	// StepInfo displays information without requiring a response.
	StepInfo StepType = iota

	// StepConfirm asks for yes/no confirmation.
	StepConfirm

	// StepSelect presents options for the user to choose from.
	StepSelect

	// StepInput requests free-form text input.
	StepInput

	// StepProgress shows progress during a long-running operation.
	StepProgress

	// StepComplete signals the session has finished successfully.
	StepComplete

	// StepError signals the session terminated with an error.
	StepError
)

type Styles

type Styles struct {

	// Layout styles
	Container lipgloss.Style
	Header    lipgloss.Style
	Content   lipgloss.Style
	Footer    lipgloss.Style

	// Text styles
	Title       lipgloss.Style
	Subtitle    lipgloss.Style
	Body        lipgloss.Style
	Muted       lipgloss.Style
	Highlighted lipgloss.Style

	// Status styles
	Success lipgloss.Style
	Warning lipgloss.Style
	Error   lipgloss.Style

	// Interactive styles
	Prompt         lipgloss.Style
	SelectedOption lipgloss.Style
	Option         lipgloss.Style
	Input          lipgloss.Style

	// Progress styles
	ProgressBar     lipgloss.Style
	ProgressFilled  lipgloss.Style
	ProgressEmpty   lipgloss.Style
	ProgressPercent lipgloss.Style
	// contains filtered or unexported fields
}

Styles holds the lipgloss styles for console rendering.

func DefaultStyles

func DefaultStyles() *Styles

DefaultStyles returns styles with the default theme.

func NewStyles

func NewStyles(theme Theme) *Styles

NewStyles creates styles with the given theme.

type Theme

type Theme struct {
	Primary   lipgloss.Color
	Secondary lipgloss.Color
	Success   lipgloss.Color
	Warning   lipgloss.Color
	Error     lipgloss.Color
	Muted     lipgloss.Color
	Text      lipgloss.Color
}

Theme holds the color scheme for the console UI.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme returns the default color scheme.

Jump to

Keyboard shortcuts

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