ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmIdentifierTTY added in v0.2.0

func ConfirmIdentifierTTY(in io.Reader, out io.Writer, identifier string) (bool, string, error)

ConfirmIdentifierTTY runs a Bubble Tea prompt that asks the user to type the provided identifier to confirm a destroy operation. It renders only when attached to a TTY via tea.WithInput/WithOutput provided by the caller. It returns whether the user confirmed and the raw value that was entered.

func ConfirmToken added in v0.2.0

func ConfirmToken(s string) string

ConfirmToken renders a confirmation token (like "yes" or an identifier) in green, bold, italic.

func ConfirmYesTTY

func ConfirmYesTTY(in io.Reader, out io.Writer) (bool, string, error)

ConfirmYesTTY runs a Bubble Tea prompt that asks the user to type "yes" to confirm. It renders only when attached to a TTY via tea.WithInput/WithOutput provided by the caller. It returns whether the user confirmed and the raw value that was entered.

func FormatPlanSummary added in v0.1.1

func FormatPlanSummary(createCount, changeCount, destroyCount int) string

FormatPlanSummary renders a plan summary with bold "Plan:" prefix.

func Italic added in v0.2.0

func Italic(s string) string

Italic renders the given string in italic style (used for resource and file names).

func RedText added in v0.2.0

func RedText(s string) string

RedText renders the provided text in red.

func RenderNestedSections added in v0.1.1

func RenderNestedSections(sections []NestedSection) string

RenderNestedSections renders sections that can contain nested subsections.

func RenderSectionedList

func RenderSectionedList(sections []Section) string

RenderSectionedList renders sections with simple headers and two-space indented items.

func SectionTitle

func SectionTitle(title string) string

SectionTitle renders a bold section header for grouped output.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI color codes for snapshot testing when needed.

func StripRedundantPrefixes added in v0.1.1

func StripRedundantPrefixes(message, sectionType string) string

StripRedundantPrefixes removes redundant "volume " and "network " prefixes from messages when they appear under their respective sections.

func SuccessMark added in v0.2.0

func SuccessMark() string

SuccessMark returns a green check mark for confirmations.

Types

type ChangeType

type ChangeType int
const (
	Info ChangeType = iota
	Noop ChangeType = iota
	Add
	Remove
	Change
)

type DiffLine

type DiffLine struct {
	Type    ChangeType
	Message string
}

func Line

func Line(t ChangeType, format string, a ...any) DiffLine

func (DiffLine) String

func (d DiffLine) String() string

type NestedSection added in v0.1.1

type NestedSection struct {
	Title    string
	Items    []DiffLine
	Sections []NestedSection
}

NestedSection represents a section that can contain nested subsections.

type NoopPrinter

type NoopPrinter struct{}

NoopPrinter discards all output; useful as a default or in tests.

func (NoopPrinter) Error

func (NoopPrinter) Error(string, ...any)

func (NoopPrinter) Info

func (NoopPrinter) Info(string, ...any)

func (NoopPrinter) Plain

func (NoopPrinter) Plain(string, ...any)

func (NoopPrinter) Warn

func (NoopPrinter) Warn(string, ...any)

type Printer

type Printer interface {
	// Plain writes to stdout without any prefix or styling.
	Plain(format string, a ...any)
	// Info writes to stdout with an [info] prefix.
	Info(format string, a ...any)
	// Warn writes to stderr with a [warn] prefix.
	Warn(format string, a ...any)
	// Error writes to stderr with an [error] prefix.
	Error(format string, a ...any)
}

Printer centralizes user-facing output. It routes informational messages to stdout and warnings/errors to stderr, ready for future styling via lipgloss.

type Progress

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

Progress renders a simple in-place progress bar to a TTY. When the output is not a terminal, it is disabled and all methods become no-ops.

func NewProgress

func NewProgress(out io.Writer, label string) *Progress

NewProgress creates a new progress bar writer targeting out with a label. The bar only renders if out is a TTY.

func (*Progress) AdjustTotal

func (p *Progress) AdjustTotal(delta int)

AdjustTotal changes the total by delta (can be negative) and re-renders.

func (*Progress) Increment

func (p *Progress) Increment()

Increment adds one to the current progress and re-renders.

func (*Progress) SetAction

func (p *Progress) SetAction(text string)

SetAction sets the action text shown under the progress bar and re-renders.

func (*Progress) Start

func (p *Progress) Start(total int)

Start sets the total and renders the initial bar.

func (*Progress) Stop

func (p *Progress) Stop()

Stop clears the action line and moves cursor back to the spinner/bar line.

type Section

type Section struct {
	Title string
	Items []DiffLine
}

Section represents a header and its list of items for rendering.

type Spinner

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

Spinner renders a simple TTY spinner with an optional label. It is disabled automatically when the writer is not a terminal.

func NewSpinner

func NewSpinner(out io.Writer, label string) *Spinner

NewSpinner creates a new spinner that writes to out with the given label. The spinner only animates if out is a TTY; otherwise Start/Stop are no-ops.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins rendering the spinner. Calling Start multiple times is safe.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

type StdPrinter

type StdPrinter struct {
	Out io.Writer
	Err io.Writer
}

StdPrinter writes Info to Out and Warn/Error to Err.

func (StdPrinter) Error

func (p StdPrinter) Error(format string, a ...any)

func (StdPrinter) Info

func (p StdPrinter) Info(format string, a ...any)

func (StdPrinter) Plain

func (p StdPrinter) Plain(format string, a ...any)

func (StdPrinter) Warn

func (p StdPrinter) Warn(format string, a ...any)

Jump to

Keyboard shortcuts

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