ui

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlueText added in v0.5.0

func BlueText(s string) string

BlueText renders the provided text in blue.

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 GreenText added in v0.5.0

func GreenText(s string) string

GreenText renders the provided text in green.

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 ReadLineNonTTY added in v0.4.1

func ReadLineNonTTY(in io.Reader) (string, error)

ReadLineNonTTY reads one line from the reader, trimming trailing newline. Useful for non-tty fallbacks.

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 RenderYAMLInPagerTTY added in v0.3.0

func RenderYAMLInPagerTTY(in io.Reader, out io.Writer, yamlContent string, title string) error

RenderYAMLInPagerTTY displays YAML content in a full-screen viewport pager when attached to a TTY. When not connected to a TTY, it falls back to plain output identical to standard printing (ensuring a trailing newline).

func RunWithRollingLog added in v0.4.1

func RunWithRollingLog(ctx context.Context, fn func(ctx context.Context) (string, error)) (string, error)

RunWithRollingLog runs fn while showing a 5-line rolling block fed by the existing logger. The adapter attaches/detaches to the logger automatically when stdout is a TTY. On completion, the rolling block is replaced by the final report in the same view and the area below is cleared. Returns the final report and error.

func SectionTitle

func SectionTitle(title string) string

SectionTitle renders a bold section header for grouped output.

func SelectOneTTY added in v0.4.1

func SelectOneTTY(in io.Reader, out io.Writer, title string, options []string) (int, bool, error)

SelectOneTTY renders a simple Bubble Tea picker to choose one option. It only renders when both in and out are TTY; otherwise returns an error-like false ok. Returns the selected index, whether a selection was made, and an error if Bubble Tea fails.

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.

func YellowText added in v0.5.0

func YellowText(s string) string

YellowText renders the provided text in yellow.

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) SetLabel added in v0.7.0

func (s *Spinner) SetLabel(label string)

SetLabel updates the spinner label while it's running. This allows dynamic updates to show current progress.

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)

type UILogWriter added in v0.4.1

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

UILogWriter buffers bytes and sends complete lines to the UI.

func (*UILogWriter) Fd added in v0.4.1

func (w *UILogWriter) Fd() uintptr

Fd reports a real terminal file descriptor so color libraries treat this writer as a TTY. We reuse stdout's FD because the UI renders to stdout.

func (*UILogWriter) Write added in v0.4.1

func (w *UILogWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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