presenter

package
v0.3.28-beta Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package presenter provides consistent CLI output functionality for user-facing messages, including success, error, warning, and informational output with color support and quiet mode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(err error, context string)

Error displays an error message using the default presenter instance.

func Info

func Info(message string)

Info displays an informational message using the default presenter instance.

func IsQuiet

func IsQuiet() bool

IsQuiet returns whether quiet mode is enabled for the default presenter instance.

func Prompt

func Prompt(question string, options ...string) string

Prompt displays a prompt and reads user input using the default presenter instance.

func Section

func Section(title string)

Section displays a section header using the default presenter instance.

func Separator

func Separator()

Separator displays a visual separator using the default presenter instance.

func SetQuiet

func SetQuiet(quiet bool)

SetQuiet enables or disables quiet mode for the default presenter instance.

func Stats

func Stats(usage *UsageStats)

Stats displays usage statistics using the default presenter instance.

func Success

func Success(message string)

Success displays a success message using the default presenter instance.

func Warning

func Warning(message string)

Warning displays a warning message using the default presenter instance.

Types

type ColorMode

type ColorMode int

ColorMode represents different color output modes

const (
	// ColorAuto automatically detects whether to use colored output based on terminal capabilities
	ColorAuto ColorMode = iota
	// ColorAlways forces colored output regardless of terminal capabilities
	ColorAlways
	// ColorNever disables colored output regardless of terminal capabilities
	ColorNever
)

type Presenter

type Presenter interface {
	Error(err error, context string)
	Success(message string)
	Warning(message string)
	Info(message string)
	Section(title string)
	Prompt(question string, options ...string) string
	Stats(usage *UsageStats)
	Separator()
	SetQuiet(quiet bool)
	IsQuiet() bool
}

Presenter defines the interface for consistent CLI output

type TerminalPresenter

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

TerminalPresenter implements Presenter for terminal output

func New

func New() *TerminalPresenter

New creates a new TerminalPresenter with default settings

func NewWithOptions

func NewWithOptions(output, errorOutput io.Writer, colorMode ColorMode) *TerminalPresenter

NewWithOptions creates a TerminalPresenter with custom settings

func (*TerminalPresenter) Error

func (p *TerminalPresenter) Error(err error, context string)

Error displays an error message to stderr

func (*TerminalPresenter) Info

func (p *TerminalPresenter) Info(message string)

Info displays an informational message

func (*TerminalPresenter) IsQuiet

func (p *TerminalPresenter) IsQuiet() bool

IsQuiet returns whether quiet mode is enabled

func (*TerminalPresenter) Prompt

func (p *TerminalPresenter) Prompt(question string, options ...string) string

Prompt displays a prompt and reads user input

func (*TerminalPresenter) Section

func (p *TerminalPresenter) Section(title string)

Section displays a section header with consistent formatting

func (*TerminalPresenter) Separator

func (p *TerminalPresenter) Separator()

Separator displays a visual separator

func (*TerminalPresenter) SetQuiet

func (p *TerminalPresenter) SetQuiet(quiet bool)

SetQuiet enables or disables quiet mode

func (*TerminalPresenter) Stats

func (p *TerminalPresenter) Stats(usage *UsageStats)

Stats displays usage statistics in a consistent format

func (*TerminalPresenter) Success

func (p *TerminalPresenter) Success(message string)

Success displays a success message

func (*TerminalPresenter) Warning

func (p *TerminalPresenter) Warning(message string)

Warning displays a warning message

type UsageStats

type UsageStats struct {
	InputTokens          int64
	OutputTokens         int64
	CacheWriteTokens     int64
	CacheReadTokens      int64
	InputCost            float64
	OutputCost           float64
	CacheWriteCost       float64
	CacheReadCost        float64
	CurrentContextWindow int
	MaxContextWindow     int
}

UsageStats represents token usage and cost information

func ConvertUsageStats

func ConvertUsageStats(stats *llmtypes.Usage) *UsageStats

ConvertUsageStats converts llmtypes.Usage to presenter.UsageStats

Jump to

Keyboard shortcuts

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