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 ¶
- type Console
- func (c *Console) Error(msg string)
- func (c *Console) Info(msg string)
- func (c *Console) Print(text string)
- func (c *Console) PrintStyled(text string, style func(string) string)
- func (c *Console) Run(session Session) (any, error)
- func (c *Console) RunInline(session Session) (any, error)
- func (c *Console) Styles() *Styles
- func (c *Console) Success(msg string)
- func (c *Console) Warning(msg string)
- func (c *Console) WithInput(r io.Reader) *Console
- func (c *Console) WithOutput(w io.Writer) *Console
- func (c *Console) WithStyles(s *Styles) *Console
- type Model
- type Option
- type Session
- type Step
- type StepType
- type Styles
- type Theme
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 (*Console) PrintStyled ¶
PrintStyled outputs text with the given style.
func (*Console) Run ¶
Run executes an interactive session. Returns the session's result after completion, or an error.
func (*Console) RunInline ¶
RunInline executes a session without alternate screen. Useful for simpler interactions that don't need full-screen mode.
func (*Console) WithOutput ¶
WithOutput sets the output writer.
func (*Console) WithStyles ¶
WithStyles sets custom styles.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the Bubble Tea model for interactive sessions.
func (*Model) BorderedBox ¶
BorderedBox creates a bordered box with the given title and content.
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
// 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.