output

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package output provides unified output adapters for MOPS plugins.

This package enables plugin developers to write business logic once and support multiple output modes automatically:

  • CLI: Command-line interface with colors and formatting
  • UI Static: Buffered output for UI action results
  • UI Streaming: Real-time output for interactive functions

Basic Usage:

// For CLI commands
func (p *MyPlugin) CLICommand(args []string) (string, error) {
	adapter := output.NewCLIAdapter(true) // with colors
	err := p.runBusinessLogic(adapter, parseArgs(args))
	return adapter.GetOutput(), err
}

// For UI streaming
func (p *MyPlugin) StreamingFunction(ctx context.Context, outputChan chan<- string, ...) error {
	adapter := output.NewStreamingAdapter(ctx, outputChan)
	return p.runBusinessLogic(adapter, params)
}

// Business logic (shared across all modes)
func (p *MyPlugin) runBusinessLogic(out output.Adapter, params map[string]interface{}) error {
	out.WriteHeader("🎯 My Plugin Demo")
	out.WriteSection("Processing items...")

	for i, item := range items {
		out.WriteProgress(i+1, len(items), fmt.Sprintf("Processing %s", item))
		// ... business logic
		out.WriteBulletPoint(fmt.Sprintf("✅ Completed %s", item))
	}

	return out.Flush()
}

Advanced Features:

  • Delayed adapters for animated effects
  • Custom styling and theming
  • Helper utilities for common patterns
  • Progress sequences and statistics tables

Package output provides unified output adapters for MOPS plugins. This package enables plugins to write business logic once and support multiple output modes: CLI, UI static display, and real-time streaming.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteWithProgress

func ExecuteWithProgress(adapter Adapter, title string, items []string, processor func(string) error) error

ExecuteWithProgress runs a function with progress feedback. This is a common pattern for plugins that process multiple items.

func RunDemo

func RunDemo(adapter Adapter, title string, steps []DemoStep) error

RunDemo executes a sequence of demo steps with consistent formatting

func ShowResults

func ShowResults(adapter Adapter, title string, results map[string]interface{}, success bool) error

ShowResults displays results in a consistent format across all adapters

func WriteBoxedMessage

func WriteBoxedMessage(adapter Adapter, message string, title string) error

WriteBoxedMessage writes a message surrounded by a box

func WriteMultilineBoxedMessage

func WriteMultilineBoxedMessage(adapter Adapter, lines []string, title string) error

WriteMultilineBoxedMessage writes a multi-line message in a box

func WriteProgressSequence

func WriteProgressSequence(adapter Adapter, title string, items []ProgressItem) error

WriteProgressSequence executes a sequence of items with progress indicators. This is a common pattern for processing multiple items with visual feedback.

func WriteSeparator

func WriteSeparator(adapter Adapter, length int, char string) error

WriteSeparator writes a visual separator line

func WriteStatsTable

func WriteStatsTable(adapter Adapter, title string, stats []StatsEntry) error

WriteStatsTable writes statistics in a formatted table-like structure

func WriteTimedSequence

func WriteTimedSequence(adapter StreamingAdapter, lines []string, delay time.Duration) error

WriteTimedSequence writes a sequence of lines with specific delays between them. Useful for creating dramatic effects in streaming contexts.

Types

type Adapter

type Adapter interface {
	// Basic output methods
	WriteLine(line string) error
	WriteError(err error) error

	// Structured output methods
	WriteHeader(title string) error
	WriteSection(section string) error
	WriteBulletPoint(point string) error
	WriteProgress(current, total int, message string) error
	WriteStats(stats map[string]interface{}) error

	// Control methods
	Flush() error
	SupportsRealTime() bool
}

Adapter defines the unified interface for different output mechanisms. Implementations handle the specifics of outputting to CLI, UI, streaming channels, etc.

func NewDelayedAdapter

func NewDelayedAdapter(adapter Adapter, config DelayConfig, skipDelays bool) Adapter

NewDelayedAdapter creates a new delayed adapter wrapper. Set skipDelays to true for CLI/static contexts where delays are not desired.

func NewDelayedAdapterWithDefaults

func NewDelayedAdapterWithDefaults(adapter Adapter, skipDelays bool) Adapter

NewDelayedAdapterWithDefaults creates a delayed adapter with default timing

func NewForStreamingAnimated

func NewForStreamingAnimated(ctx context.Context, outputChan chan<- string) Adapter

NewForStreamingAnimated creates a streaming adapter with animation delays

type DelayConfig

type DelayConfig struct {
	SimulateDelays bool
	LineDelay      time.Duration
	ProgressDelay  time.Duration
	SectionDelay   time.Duration
}

DelayConfig configures timing behavior for delayed adapters

func DefaultDelayConfig

func DefaultDelayConfig() DelayConfig

DefaultDelayConfig returns sensible defaults for delay configuration

type DemoStep

type DemoStep struct {
	Name        string
	Description string
	Action      func(Adapter) error
}

DemoStep represents a single step in a demonstration

type OutputStyle

type OutputStyle struct {
	EnableColors bool
	EnableEmojis bool
	EnableBold   bool
	Theme        string // "default", "minimal", "rich"
}

OutputStyle configures visual styling for adapters

func DefaultOutputStyle

func DefaultOutputStyle() OutputStyle

DefaultOutputStyle returns sensible defaults for output styling

func MinimalOutputStyle

func MinimalOutputStyle() OutputStyle

MinimalOutputStyle returns a minimal style configuration

func RichOutputStyle

func RichOutputStyle() OutputStyle

RichOutputStyle returns a rich style configuration with all features

type ProgressItem

type ProgressItem struct {
	Name        string
	Description string
	Processor   func() error
}

ProgressItem represents a single item in a progress sequence

type StaticAdapter

type StaticAdapter interface {
	Adapter
	GetOutput() string
	Clear()
}

StaticAdapter extends Adapter for adapters that buffer output. Used for CLI and UI static displays.

func NewCLIAdapter

func NewCLIAdapter(enableColors bool) StaticAdapter

NewCLIAdapter creates a new CLI adapter with color support. This is optimized for command-line interfaces.

func NewForCLI

func NewForCLI(enableColors bool) StaticAdapter

NewForCLI creates an adapter optimized for command-line interfaces

func NewForUI

func NewForUI() StaticAdapter

NewForUI creates an adapter optimized for UI static displays

func NewForUIMinimal

func NewForUIMinimal() StaticAdapter

NewForUIMinimal creates an adapter with minimal styling for UI

func NewStaticAdapter

func NewStaticAdapter() StaticAdapter

NewStaticAdapter creates a new static adapter for buffered output. This is typically used for CLI commands and UI static actions.

func NewStaticAdapterWithStyle

func NewStaticAdapterWithStyle(style OutputStyle) StaticAdapter

NewStaticAdapterWithStyle creates a static adapter with custom styling

type StatsEntry

type StatsEntry struct {
	Key   string
	Value interface{}
	Unit  string // optional unit like "ms", "MB", etc.
}

StatsEntry represents a single statistics entry

type StreamingAdapter

type StreamingAdapter interface {
	Adapter
	WriteRaw(content string) error
	WriteWithDelay(line string, delay time.Duration) error
}

StreamingAdapter extends Adapter for real-time streaming adapters. Used for UI interactive functions and live updates.

func NewForStreaming

func NewForStreaming(ctx context.Context, outputChan chan<- string) StreamingAdapter

NewForStreaming creates an adapter for real-time streaming output

func NewStreamingAdapter

func NewStreamingAdapter(ctx context.Context, outputChan chan<- string) StreamingAdapter

NewStreamingAdapter creates a new streaming adapter for real-time output. This is typically used for UI interactive functions.

func NewStreamingAdapterWithStyle

func NewStreamingAdapterWithStyle(ctx context.Context, outputChan chan<- string, style OutputStyle) StreamingAdapter

NewStreamingAdapterWithStyle creates a streaming adapter with custom styling

Jump to

Keyboard shortcuts

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