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 ¶
- func ExecuteWithProgress(adapter Adapter, title string, items []string, processor func(string) error) error
- func RunDemo(adapter Adapter, title string, steps []DemoStep) error
- func ShowResults(adapter Adapter, title string, results map[string]interface{}, success bool) error
- func WriteBoxedMessage(adapter Adapter, message string, title string) error
- func WriteMultilineBoxedMessage(adapter Adapter, lines []string, title string) error
- func WriteProgressSequence(adapter Adapter, title string, items []ProgressItem) error
- func WriteSeparator(adapter Adapter, length int, char string) error
- func WriteStatsTable(adapter Adapter, title string, stats []StatsEntry) error
- func WriteTimedSequence(adapter StreamingAdapter, lines []string, delay time.Duration) error
- type Adapter
- type DelayConfig
- type DemoStep
- type OutputStyle
- type ProgressItem
- type StaticAdapter
- type StatsEntry
- type StreamingAdapter
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 ShowResults ¶
ShowResults displays results in a consistent format across all adapters
func WriteBoxedMessage ¶
WriteBoxedMessage writes a message surrounded by a box
func WriteMultilineBoxedMessage ¶
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 ¶
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 ¶
NewDelayedAdapterWithDefaults creates a delayed adapter with default timing
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 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 ¶
ProgressItem represents a single item in a progress sequence
type StaticAdapter ¶
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