Documentation
¶
Index ¶
- Variables
- func FormatBytes(bytes int64) string
- func LogOrDisplay(ctx context.Context, level MessageLevel, format string, args ...interface{})
- func SaveConfig(config *Config) error
- func SaveConfigToFile(config *Config, path string) error
- func TruncateString(s string, maxLen int) string
- func WithDisplay(ctx context.Context, display Display) context.Context
- func WithDisplayContext(ctx context.Context, dc *DisplayContext) context.Context
- func WrapText(text string, maxWidth int) []string
- type BorderStyle
- type Color
- type ColorConfig
- type ColorScheme
- type Config
- type Display
- type DisplayContext
- type DisplayImpl
- func (d *DisplayImpl) ApplyConfig(config *Config)
- func (d *DisplayImpl) Confirm(message string) bool
- func (d *DisplayImpl) Error(message string, args ...interface{})
- func (d *DisplayImpl) Info(message string, args ...interface{})
- func (d *DisplayImpl) Input(message string) (string, error)
- func (d *DisplayImpl) Progress(title string) *ProgressBuilder
- func (d *DisplayImpl) Select(message string, options []string) (int, error)
- func (d *DisplayImpl) SetFormat(format OutputFormat) Display
- func (d *DisplayImpl) SetTheme(theme Theme) Display
- func (d *DisplayImpl) Success(message string, args ...interface{})
- func (d *DisplayImpl) Table(data TableData) *TableBuilder
- func (d *DisplayImpl) Warning(message string, args ...interface{})
- type FilterOptions
- type IconSet
- type InteractiveConfig
- type MessageLevel
- type OutputFormat
- type PaginationOptions
- type ProgressBuilder
- type ProgressIndicator
- type Renderer
- type SortOptions
- type TableBuilder
- func (tb *TableBuilder) Render() error
- func (tb *TableBuilder) WithCompactMode() *TableBuilder
- func (tb *TableBuilder) WithFiltering(column, operator string, value interface{}) *TableBuilder
- func (tb *TableBuilder) WithFormat(format OutputFormat) *TableBuilder
- func (tb *TableBuilder) WithMaxWidth(width int) *TableBuilder
- func (tb *TableBuilder) WithPagination(pageSize int) *TableBuilder
- func (tb *TableBuilder) WithRowNumbers() *TableBuilder
- func (tb *TableBuilder) WithSorting(column string, descending bool) *TableBuilder
- func (tb *TableBuilder) WithTheme(theme Theme) *TableBuilder
- func (tb *TableBuilder) WithTitle(title string) *TableBuilder
- type TableConfig
- type TableData
- type TableOptions
- type TableStyle
- type TerminalCapabilities
- type Theme
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTheme = Theme{ Name: "default", Colors: ColorScheme{ Primary: "#0066CC", Secondary: "#6C757D", Success: "#28A745", Warning: "#FFC107", Error: "#DC3545", Info: "#17A2B8", Muted: "#6C757D", }, TableStyle: TableStyle{ HeaderStyle: "bold", RowStyle: "normal", BorderStyle: "rounded", }, Borders: BorderStyle{ Horizontal: "─", Vertical: "│", TopLeft: "┌", TopRight: "┐", BottomLeft: "└", BottomRight: "┘", Cross: "┼", }, Icons: IconSet{ Success: "✅", Warning: "⚠️", Error: "❌", Info: "ℹ️", }, } DarkTheme = Theme{ Name: "dark", Colors: ColorScheme{ Primary: "#4A9EFF", Secondary: "#8E8E93", Success: "#30D158", Warning: "#FF9F0A", Error: "#FF453A", Info: "#64D2FF", Muted: "#8E8E93", }, TableStyle: TableStyle{ HeaderStyle: "bold", RowStyle: "normal", BorderStyle: "rounded", }, Borders: BorderStyle{ Horizontal: "─", Vertical: "│", TopLeft: "┌", TopRight: "┐", BottomLeft: "└", BottomRight: "┘", Cross: "┼", }, Icons: IconSet{ Success: "✅", Warning: "⚠️", Error: "❌", Info: "ℹ️", }, } LightTheme = Theme{ Name: "light", Colors: ColorScheme{ Primary: "#007AFF", Secondary: "#5E5CE6", Success: "#34C759", Warning: "#FF9500", Error: "#FF3B30", Info: "#5AC8FA", Muted: "#C7C7CC", }, TableStyle: TableStyle{ HeaderStyle: "bold", RowStyle: "normal", BorderStyle: "rounded", }, Borders: BorderStyle{ Horizontal: "─", Vertical: "│", TopLeft: "┌", TopRight: "┐", BottomLeft: "└", BottomRight: "┘", Cross: "┼", }, Icons: IconSet{ Success: "✓", Warning: "⚠", Error: "✗", Info: "i", }, } MinimalTheme = Theme{ Name: "minimal", Colors: ColorScheme{ Primary: "", Secondary: "", Success: "", Warning: "", Error: "", Info: "", Muted: "", }, TableStyle: TableStyle{ HeaderStyle: "normal", RowStyle: "normal", BorderStyle: "simple", }, Borders: BorderStyle{ Horizontal: "-", Vertical: "|", TopLeft: "+", TopRight: "+", BottomLeft: "+", BottomRight: "+", Cross: "+", }, Icons: IconSet{ Success: "[OK]", Warning: "[WARN]", Error: "[ERROR]", Info: "[INFO]", }, } )
Predefined themes
Functions ¶
func FormatBytes ¶
formatBytes formats bytes into human-readable format
func LogOrDisplay ¶
func LogOrDisplay(ctx context.Context, level MessageLevel, format string, args ...interface{})
LogOrDisplay logs a message using the display if available, otherwise uses the logger
func SaveConfig ¶
SaveConfig saves configuration to the default location
func SaveConfigToFile ¶
SaveConfigToFile saves configuration to a specific file
func TruncateString ¶
TruncateString truncates a string to maxLen with ellipsis
func WithDisplay ¶
WithDisplay adds a display instance to the context
func WithDisplayContext ¶
func WithDisplayContext(ctx context.Context, dc *DisplayContext) context.Context
WithDisplayContext adds a full display context to the context
Types ¶
type BorderStyle ¶
type BorderStyle struct {
Horizontal string
Vertical string
TopLeft string
TopRight string
BottomLeft string
BottomRight string
Cross string
}
BorderStyle defines border characters
type ColorConfig ¶
type ColorConfig struct {
Enabled string `yaml:"enabled" json:"enabled"` // auto, always, never
}
ColorConfig represents color configuration
type ColorScheme ¶
type ColorScheme struct {
Primary Color
Secondary Color
Success Color
Warning Color
Error Color
Info Color
Muted Color
}
ColorScheme defines colors for different message types
type Config ¶
type Config struct {
Theme string `yaml:"theme" json:"theme"`
Format string `yaml:"format" json:"format"`
Table TableConfig `yaml:"table" json:"table"`
Colors ColorConfig `yaml:"colors" json:"colors"`
Interactive InteractiveConfig `yaml:"interactive" json:"interactive"`
Verbose bool `yaml:"verbose" json:"verbose"`
Timing bool `yaml:"timing" json:"timing"`
}
Config represents the display configuration
func LoadConfig ¶
LoadConfig loads configuration from the default location
func LoadConfigFromFile ¶
LoadConfigFromFile loads configuration from a specific file
type Display ¶
type Display interface {
// Table operations
Table(data TableData) *TableBuilder
// Message operations
Success(message string, args ...interface{})
Error(message string, args ...interface{})
Warning(message string, args ...interface{})
Info(message string, args ...interface{})
// Progress operations
Progress(title string) *ProgressBuilder
// Interactive operations
Confirm(message string) bool
Select(message string, options []string) (int, error)
Input(message string) (string, error)
// Output format control
SetFormat(format OutputFormat) Display
SetTheme(theme Theme) Display
}
Display is the main interface for all display operations
func GetDisplay ¶
GetDisplay retrieves the display instance from context
func GetDisplayOrDefault ¶
GetDisplayOrDefault retrieves the display instance from context or returns a default
type DisplayContext ¶
type DisplayContext struct {
Display Display
Logger *log.Logger
Verbose bool
Format OutputFormat
}
DisplayContext holds display-related context information
func GetDisplayContext ¶
func GetDisplayContext(ctx context.Context) *DisplayContext
GetDisplayContext retrieves the full display context
type DisplayImpl ¶
type DisplayImpl struct {
// contains filtered or unexported fields
}
DisplayImpl is the concrete implementation of Display
func New ¶
func New() *DisplayImpl
New creates a new Display instance with automatic capability detection
func NewWithConfig ¶
func NewWithConfig(config *Config) *DisplayImpl
NewWithConfig creates a new display instance with configuration
func NewWithRenderer ¶
func NewWithRenderer(renderer Renderer) *DisplayImpl
NewWithRenderer creates a new Display instance with a specific renderer
func (*DisplayImpl) ApplyConfig ¶
func (d *DisplayImpl) ApplyConfig(config *Config)
ApplyConfig applies configuration to a display instance
func (*DisplayImpl) Confirm ¶
func (d *DisplayImpl) Confirm(message string) bool
Confirm shows a confirmation prompt
func (*DisplayImpl) Error ¶
func (d *DisplayImpl) Error(message string, args ...interface{})
Error displays an error message
func (*DisplayImpl) Info ¶
func (d *DisplayImpl) Info(message string, args ...interface{})
Info displays an info message
func (*DisplayImpl) Input ¶
func (d *DisplayImpl) Input(message string) (string, error)
Input shows an input prompt
func (*DisplayImpl) Progress ¶
func (d *DisplayImpl) Progress(title string) *ProgressBuilder
Progress creates a new progress builder
func (*DisplayImpl) Select ¶
func (d *DisplayImpl) Select(message string, options []string) (int, error)
Select shows a selection menu
func (*DisplayImpl) SetFormat ¶
func (d *DisplayImpl) SetFormat(format OutputFormat) Display
SetFormat sets the output format
func (*DisplayImpl) SetTheme ¶
func (d *DisplayImpl) SetTheme(theme Theme) Display
SetTheme sets the display theme
func (*DisplayImpl) Success ¶
func (d *DisplayImpl) Success(message string, args ...interface{})
Success displays a success message
func (*DisplayImpl) Table ¶
func (d *DisplayImpl) Table(data TableData) *TableBuilder
Table creates a new table builder
func (*DisplayImpl) Warning ¶
func (d *DisplayImpl) Warning(message string, args ...interface{})
Warning displays a warning message
type FilterOptions ¶
type FilterOptions struct {
Column string
Operator string // =, !=, <, >, <=, >=, contains, starts_with, ends_with
Value interface{}
}
FilterOptions represents filtering configuration
type InteractiveConfig ¶
type InteractiveConfig struct {
ConfirmDestructive bool `yaml:"confirm_destructive" json:"confirm_destructive"`
ShowHints bool `yaml:"show_hints" json:"show_hints"`
}
InteractiveConfig represents interactive feature configuration
type MessageLevel ¶
type MessageLevel int
MessageLevel represents different message types
const ( MessageLevelInfo MessageLevel = iota MessageLevelSuccess MessageLevelWarning MessageLevelError )
type OutputFormat ¶
type OutputFormat int
OutputFormat represents different output formats
const ( FormatTable OutputFormat = iota FormatCSV FormatJSON FormatMarkdown )
type PaginationOptions ¶
PaginationOptions represents pagination configuration
type ProgressBuilder ¶
type ProgressBuilder struct {
// contains filtered or unexported fields
}
ProgressBuilder for building progress indicators
func (*ProgressBuilder) Start ¶
func (pb *ProgressBuilder) Start() *ProgressIndicator
Start starts the progress indicator
type ProgressIndicator ¶
type ProgressIndicator struct {
// contains filtered or unexported fields
}
ProgressIndicator represents an active progress indicator
func (*ProgressIndicator) Finish ¶
func (pi *ProgressIndicator) Finish(message string)
Finish completes the progress
func (*ProgressIndicator) Update ¶
func (pi *ProgressIndicator) Update(message string)
Update updates the progress
type Renderer ¶
type Renderer interface {
// Table rendering
RenderTable(data TableData, options TableOptions) error
// Message rendering
RenderMessage(level MessageLevel, message string)
// Interactive rendering
RenderConfirm(message string) bool
RenderSelect(message string, options []string) (int, error)
RenderInput(message string) (string, error)
// Progress rendering
RenderProgress(title string, current, total int) error
}
Renderer interface that all display renderers must implement
func NewFallbackRenderer ¶
func NewFallbackRenderer() Renderer
NewFallbackRenderer creates a new fallback renderer
func NewPTermRenderer ¶
func NewPTermRenderer() Renderer
NewPTermRenderer creates a new PTerm renderer (placeholder)
type SortOptions ¶
SortOptions represents sorting configuration
type TableBuilder ¶
type TableBuilder struct {
// contains filtered or unexported fields
}
TableBuilder for building tables with fluent API
func (*TableBuilder) WithCompactMode ¶
func (tb *TableBuilder) WithCompactMode() *TableBuilder
WithCompactMode enables compact display mode
func (*TableBuilder) WithFiltering ¶
func (tb *TableBuilder) WithFiltering(column, operator string, value interface{}) *TableBuilder
WithFiltering sets filtering options
func (*TableBuilder) WithFormat ¶
func (tb *TableBuilder) WithFormat(format OutputFormat) *TableBuilder
WithFormat sets the output format
func (*TableBuilder) WithMaxWidth ¶
func (tb *TableBuilder) WithMaxWidth(width int) *TableBuilder
WithMaxWidth sets the maximum table width
func (*TableBuilder) WithPagination ¶
func (tb *TableBuilder) WithPagination(pageSize int) *TableBuilder
WithPagination sets pagination options
func (*TableBuilder) WithRowNumbers ¶
func (tb *TableBuilder) WithRowNumbers() *TableBuilder
WithRowNumbers enables row number display
func (*TableBuilder) WithSorting ¶
func (tb *TableBuilder) WithSorting(column string, descending bool) *TableBuilder
WithSorting sets sorting options
func (*TableBuilder) WithTheme ¶
func (tb *TableBuilder) WithTheme(theme Theme) *TableBuilder
WithTheme sets the theme
func (*TableBuilder) WithTitle ¶
func (tb *TableBuilder) WithTitle(title string) *TableBuilder
WithTitle sets the table title
type TableConfig ¶
type TableConfig struct {
MaxWidth int `yaml:"max_width" json:"max_width"`
Pagination int `yaml:"pagination" json:"pagination"`
UnicodeBorders bool `yaml:"unicode_borders" json:"unicode_borders"`
ShowRowNumbers bool `yaml:"show_row_numbers" json:"show_row_numbers"`
CompactMode bool `yaml:"compact_mode" json:"compact_mode"`
}
TableConfig represents table-specific configuration
type TableData ¶
type TableData struct {
Headers []string
Rows [][]interface{}
}
TableData represents the data for a table
type TableOptions ¶
type TableOptions struct {
Format OutputFormat
MaxWidth int
Pagination *PaginationOptions
Sorting *SortOptions
Filtering *FilterOptions
Theme *Theme
ShowRowNumbers bool
CompactMode bool
Title string
}
TableOptions represents configuration options for table rendering
func DefaultTableOptions ¶
func DefaultTableOptions() TableOptions
DefaultTableOptions returns default table options
type TableStyle ¶
TableStyle defines table appearance
type TerminalCapabilities ¶
type TerminalCapabilities struct {
SupportsColor bool
SupportsUnicode bool
Width int
Height int
IsInteractive bool
IsPiped bool
}
TerminalCapabilities represents what the terminal supports
func DetectCapabilities ¶
func DetectCapabilities() TerminalCapabilities
DetectCapabilities automatically detects terminal capabilities
type Theme ¶
type Theme struct {
Name string
Colors ColorScheme
TableStyle TableStyle
Borders BorderStyle
Icons IconSet
}
Theme represents a visual theme for the display system