output

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package output defines events for the event/sink system

MessageEvent (use via EmitInfo, EmitSuccess, EmitNote, EmitWarning):

  • SeverityInfo: Transient status ("Connecting...", "Validating...")
  • SeveritySuccess: Positive outcome ("Login successful")
  • SeverityNote: Informational outcome ("Not currently logged in")
  • SeverityWarning: Cautionary message ("Token expires soon")

SpinnerEvent (use via EmitSpinnerStart, EmitSpinnerStop):

  • Show loading indicator during async operations
  • Always pair Start with Stop

ErrorEvent (use via EmitError):

  • Structured errors with title, summary, detail, and recovery actions
  • Use for errors that need more than a single line

Index

Constants

View Source
const (
	LogSourceEmulator = "emulator"
	LogSourceBrew     = "brew"
	LogSourceNPM      = "npm"
)
View Source
const DefaultSpinnerMinDuration = 400 * time.Millisecond
View Source
const ErrorActionPrefix = "==> "

Variables

This section is empty.

Functions

func Emit

func Emit[E Event](sink Sink, event E)

Emit sends an event to the sink with compile-time type safety via generics.

func EmitAuth added in v0.2.0

func EmitAuth(sink Sink, event AuthEvent)

func EmitError added in v0.2.0

func EmitError(sink Sink, event ErrorEvent)

func EmitInfo added in v0.2.0

func EmitInfo(sink Sink, text string)

func EmitInstanceInfo added in v0.5.0

func EmitInstanceInfo(sink Sink, event InstanceInfoEvent)

func EmitLogLine added in v0.4.0

func EmitLogLine(sink Sink, source, line string)

func EmitNote added in v0.2.0

func EmitNote(sink Sink, text string)

func EmitProgress

func EmitProgress(sink Sink, container, layerID, status string, current, total int64)

func EmitResourceSummary added in v0.5.0

func EmitResourceSummary(sink Sink, resources, services int)

func EmitSecondary added in v0.5.1

func EmitSecondary(sink Sink, text string)

func EmitSpinnerStart added in v0.2.0

func EmitSpinnerStart(sink Sink, text string)

EmitSpinnerStart starts spinner with default min duration (400ms)

func EmitSpinnerStartWithDuration added in v0.2.0

func EmitSpinnerStartWithDuration(sink Sink, text string, minDuration time.Duration)

EmitSpinnerStartWithDuration starts spinner with custom min duration (0 = no minimum)

func EmitSpinnerStop added in v0.2.0

func EmitSpinnerStop(sink Sink)

func EmitStatus

func EmitStatus(sink Sink, phase, container, detail string)

func EmitSuccess added in v0.2.0

func EmitSuccess(sink Sink, text string)

func EmitTable added in v0.5.0

func EmitTable(sink Sink, event TableEvent)

func EmitUserInputRequest

func EmitUserInputRequest(sink Sink, event UserInputRequestEvent)

func EmitWarning

func EmitWarning(sink Sink, text string)

func FormatEventLine

func FormatEventLine(event any) (string, bool)

FormatEventLine converts an output event into a single display line.

func FormatPrompt added in v0.2.0

func FormatPrompt(prompt string, options []InputOption) string

FormatPrompt formats a prompt string with its options into a display line.

func FormatPromptLabels added in v0.4.0

func FormatPromptLabels(options []InputOption) string

FormatPromptLabels formats option labels into a suffix string. Returns " (label)" for a single option, " a/b" for multiple, or "" for none.

func IsSilent added in v0.2.0

func IsSilent(err error) bool

IsSilent returns true if the error (or any error in its chain) is a SilentError.

Types

type AuthEvent added in v0.2.0

type AuthEvent struct {
	Preamble string
	Code     string
	URL      string
}

type ContainerStatusEvent

type ContainerStatusEvent struct {
	Phase     string // e.g., "pulling", "starting", "waiting", "ready"
	Container string
	Detail    string // optional extra info (e.g., container ID)
}

type ErrorAction added in v0.2.0

type ErrorAction struct {
	Label string
	Value string
}

type ErrorEvent added in v0.2.0

type ErrorEvent struct {
	Title   string
	Summary string
	Detail  string
	Actions []ErrorAction
}

type InputOption

type InputOption struct {
	Key   string
	Label string
}

type InputResponse

type InputResponse struct {
	SelectedKey string
	Cancelled   bool
}

type InstanceInfoEvent added in v0.5.0

type InstanceInfoEvent struct {
	EmulatorName  string
	Version       string
	Host          string
	ContainerName string
	Uptime        time.Duration
}

type LogLineEvent added in v0.4.0

type LogLineEvent struct {
	Source string // use LogSource* constants
	Line   string
}

type MessageEvent added in v0.2.0

type MessageEvent struct {
	Severity MessageSeverity
	Text     string
}

type MessageSeverity added in v0.2.0

type MessageSeverity int
const (
	SeverityInfo      MessageSeverity = iota
	SeveritySuccess                   // positive outcome
	SeverityNote                      // informational
	SeverityWarning                   // cautionary
	SeveritySecondary                 // subdued/decorative text
)

type PlainSink

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

func NewPlainSink

func NewPlainSink(out io.Writer) *PlainSink

func (*PlainSink) Err

func (s *PlainSink) Err() error

Err returns the first write error encountered, if any.

type ProgressEvent

type ProgressEvent struct {
	Container string
	LayerID   string
	Status    string
	Current   int64
	Total     int64
}

type ResourceSummaryEvent added in v0.5.0

type ResourceSummaryEvent struct {
	Resources int
	Services  int
}

type Sender

type Sender interface {
	Send(msg any)
}

Sender abstracts Bubble Tea's Program.Send to keep TUISink decoupled and testable.

type SilentError added in v0.2.0

type SilentError struct {
	Err error
}

SilentError wraps an error that has already been displayed to the user through the sink mechanism. Callers should check for this type and skip printing the error again.

func NewSilentError added in v0.2.0

func NewSilentError(err error) *SilentError

func (*SilentError) Error added in v0.2.0

func (e *SilentError) Error() string

func (*SilentError) Unwrap added in v0.2.0

func (e *SilentError) Unwrap() error

type Sink

type Sink interface {
	// contains filtered or unexported methods
}

type SinkFunc

type SinkFunc func(event any)

type SpinnerEvent added in v0.2.0

type SpinnerEvent struct {
	Active      bool
	Text        string
	MinDuration time.Duration // Minimum time spinner should display (0 = use default)
}

type TUISink

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

func NewTUISink

func NewTUISink(sender Sender) *TUISink

type TableEvent added in v0.5.0

type TableEvent struct {
	Headers []string
	Rows    [][]string
}

type UserInputRequestEvent

type UserInputRequestEvent struct {
	Prompt     string
	Options    []InputOption
	ResponseCh chan<- InputResponse
}

Jump to

Keyboard shortcuts

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