Documentation
¶
Overview ¶
Package ui provides user interface formatting and interaction utilities.
Index ¶
- Constants
- func Alert(message string, alertType PromptType)
- func AlertError(message string)
- func AlertInfo(message string)
- func AlertSuccess(message string)
- func AlertWarning(message string)
- func BoldText(text string) string
- func ClearLine()
- func Colorize(color, text string) string
- func DimText(text string) string
- func Error(text string) string
- func ForceColor(force bool)
- func FormatDuration(seconds int) string
- func FormatSize(size int64) string
- func FormatSpeed(bytesPerSecond int64) string
- func HideCursor()
- func Highlight(text string) string
- func Info(text string) string
- func IsColorSupported() bool
- func IsTerminalInteractive() bool
- func MoveCursorDown(n int)
- func MoveCursorUp(n int)
- func PrintHeader(text string)
- func PrintKeyValue(key, value string)
- func PrintSection(text string)
- func Prompt(message string, promptType PromptType) string
- func PromptChoice(message string, choices []string, defaultChoice int) int
- func PromptPassword(message string) string
- func PromptYesNo(message string, defaultYes bool) bool
- func SetColorEnabled(enabled bool)
- func ShowCursor()
- func ShowProgress(current, total int64, message string)
- func Success(text string) string
- func Warning(text string) string
- type ColorConfig
- type ErrorFormatOptions
- type Formatter
- func (f *Formatter) ClearLine()
- func (f *Formatter) ConfirmPrompt(message string, defaultValue bool) (bool, error)
- func (f *Formatter) CreateLoadingAnimation(message string) func()
- func (f *Formatter) FormatError(err error, options *ErrorFormatOptions) string
- func (f *Formatter) FormatMessage(msgType MessageType, format string, args ...interface{}) string
- func (f *Formatter) FormatProgressBar(current, total uint64, options *ProgressBarOptions) string
- func (f *Formatter) FormatStatusIndicator(status StatusIndicator, message string) string
- func (f *Formatter) NewTableFormatter(headers []string) *TableFormatter
- func (f *Formatter) PrintMessage(msgType MessageType, format string, args ...interface{})
- func (f *Formatter) Prompt(message string) (string, error)
- func (f *Formatter) SelectPrompt(message string, options []string, defaultIndex int) (int, error)
- func (f *Formatter) WithColor(enabled bool) *Formatter
- func (f *Formatter) WithInteractive(interactive bool) *Formatter
- func (f *Formatter) WithLanguage(lang Language) *Formatter
- func (f *Formatter) WithWriter(w io.Writer) *Formatter
- type Language
- type MessageType
- type ProgressBarOptions
- type PromptType
- type Spinner
- func (s *Spinner) SetInterval(interval time.Duration)
- func (s *Spinner) SetMessage(message string)
- func (s *Spinner) Start()
- func (s *Spinner) Stop()
- func (s *Spinner) StopWithError(message string)
- func (s *Spinner) StopWithMessage(message string)
- func (s *Spinner) StopWithSuccess(message string)
- func (s *Spinner) StopWithWarning(message string)
- type SpinnerStyle
- type StatusIndicator
- type TableFormatter
Constants ¶
const ( Reset = "\033[0m" Bold = "\033[1m" Dim = "\033[2m" Italic = "\033[3m" Under = "\033[4m" // Foreground colors. Black = "\033[30m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" // Bright foreground colors. BrightBlack = "\033[90m" BrightRed = "\033[91m" BrightGreen = "\033[92m" BrightYellow = "\033[93m" BrightBlue = "\033[94m" BrightMagenta = "\033[95m" BrightCyan = "\033[96m" BrightWhite = "\033[97m" // Background colors. BgBlack = "\033[40m" BgRed = "\033[41m" BgGreen = "\033[42m" BgYellow = "\033[43m" BgBlue = "\033[44m" BgMagenta = "\033[45m" BgCyan = "\033[46m" BgWhite = "\033[47m" )
Color codes.
const ( // ColorReset resets all colors and styles. ColorReset = "\033[0m" // ColorBlack is black color. ColorBlack = "\033[30m" // ColorRed is red color. ColorRed = "\033[31m" // ColorGreen is green color. ColorGreen = "\033[32m" // ColorYellow is yellow color. ColorYellow = "\033[33m" // ColorBlue is blue color. ColorBlue = "\033[34m" // ColorMagenta is magenta color. ColorMagenta = "\033[35m" // ColorCyan is cyan color. ColorCyan = "\033[36m" // ColorWhite is white color. ColorWhite = "\033[37m" )
Color constants for terminal output.
Variables ¶
This section is empty.
Functions ¶
func ForceColor ¶
func ForceColor(force bool)
ForceColor forces color output even if not in a terminal.
func FormatDuration ¶
FormatDuration formats duration with colors.
func FormatSize ¶
FormatSize formats a file size with appropriate units and colors.
func FormatSpeed ¶
FormatSpeed formats download speed with colors.
func IsColorSupported ¶
func IsColorSupported() bool
IsColorSupported checks if the terminal supports color output.
func IsTerminalInteractive ¶
func IsTerminalInteractive() bool
IsTerminalInteractive checks if the current session is interactive.
func PrintKeyValue ¶
func PrintKeyValue(key, value string)
PrintKeyValue prints a key-value pair with formatting.
func Prompt ¶
func Prompt(message string, promptType PromptType) string
Prompt displays a prompt and waits for user input.
func PromptChoice ¶
PromptChoice presents multiple choices to the user.
func PromptPassword ¶
PromptPassword prompts for a password (input is hidden).
func PromptYesNo ¶
PromptYesNo asks a yes/no question.
func SetColorEnabled ¶
func SetColorEnabled(enabled bool)
SetColorEnabled enables or disables color output.
func ShowProgress ¶
ShowProgress displays a simple text progress indicator.
Types ¶
type ColorConfig ¶
ColorConfig manages color output settings.
type ErrorFormatOptions ¶
type ErrorFormatOptions struct {
ShowErrorCode bool // Show error codes
ShowSuggestions bool // Show recovery suggestions
ShowTimestamp bool // Show timestamp
Compact bool // Use compact format
MultiLine bool // Use multi-line format for complex errors
}
ErrorFormatOptions configures error message formatting.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter provides comprehensive formatting capabilities for various output types.
func NewFormatter ¶
func NewFormatter() *Formatter
NewFormatter creates a new formatter with default settings.
func (*Formatter) ClearLine ¶
func (f *Formatter) ClearLine()
ClearLine clears the current line in the terminal.
func (*Formatter) ConfirmPrompt ¶
ConfirmPrompt displays a yes/no confirmation prompt.
func (*Formatter) CreateLoadingAnimation ¶
CreateLoadingAnimation creates a simple loading animation.
func (*Formatter) FormatError ¶
func (f *Formatter) FormatError(err error, options *ErrorFormatOptions) string
FormatError formats an error message with optional error details.
func (*Formatter) FormatMessage ¶
func (f *Formatter) FormatMessage(msgType MessageType, format string, args ...interface{}) string
FormatMessage formats a message with appropriate styling based on type.
func (*Formatter) FormatProgressBar ¶
func (f *Formatter) FormatProgressBar(current, total uint64, options *ProgressBarOptions) string
FormatProgressBar creates a formatted progress bar.
func (*Formatter) FormatStatusIndicator ¶
func (f *Formatter) FormatStatusIndicator(status StatusIndicator, message string) string
FormatStatusIndicator formats a status indicator with appropriate styling.
func (*Formatter) NewTableFormatter ¶
func (f *Formatter) NewTableFormatter(headers []string) *TableFormatter
NewTableFormatter creates a new table formatter.
func (*Formatter) PrintMessage ¶
func (f *Formatter) PrintMessage(msgType MessageType, format string, args ...interface{})
PrintMessage prints a formatted message to the output writer.
func (*Formatter) SelectPrompt ¶
SelectPrompt displays a selection prompt with multiple options.
func (*Formatter) WithInteractive ¶
WithInteractive enables or disables interactive mode.
func (*Formatter) WithLanguage ¶
WithLanguage sets the language for localized messages.
type MessageType ¶
type MessageType int
MessageType represents different types of messages.
const ( // MessageInfo for informational messages. MessageInfo MessageType = iota // MessageSuccess for success messages. MessageSuccess // MessageWarning for warning messages. MessageWarning // MessageError for error messages. MessageError // MessageDebug for debug messages. MessageDebug // MessagePrompt for interactive prompts. MessagePrompt )
type ProgressBarOptions ¶
type ProgressBarOptions struct {
Width int // Width of the progress bar
ShowPercentage bool // Show percentage
ShowSpeed bool // Show download speed
ShowETA bool // Show estimated time remaining
ShowSize bool // Show downloaded/total size
RefreshInterval time.Duration // How often to refresh
Template string // Custom template for progress display
}
ProgressBarOptions configures progress bar appearance and behavior.
type PromptType ¶
type PromptType int
PromptType represents the type of prompt.
const ( PromptTypeInfo PromptType = iota PromptTypeWarning PromptTypeError PromptTypeSuccess PromptTypeQuestion )
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner represents a console spinner.
func NewSpinner ¶
func NewSpinner(style SpinnerStyle, message string) *Spinner
NewSpinner creates a new spinner with the specified style.
func (*Spinner) SetInterval ¶
SetInterval sets the spinner interval.
func (*Spinner) SetMessage ¶
SetMessage updates the spinner message.
func (*Spinner) StopWithError ¶
StopWithError stops the spinner with an error message.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner and displays a final message.
func (*Spinner) StopWithSuccess ¶
StopWithSuccess stops the spinner with a success message.
func (*Spinner) StopWithWarning ¶
StopWithWarning stops the spinner with a warning message.
type SpinnerStyle ¶
type SpinnerStyle int
SpinnerStyle represents different spinner styles.
const ( SpinnerStyleDots SpinnerStyle = iota SpinnerStyleLine SpinnerStyleCircle SpinnerStyleSquare SpinnerStyleArrow SpinnerStyleBounce )
type StatusIndicator ¶
type StatusIndicator int
StatusIndicator represents different status states.
const ( // StatusPending for pending operations. StatusPending StatusIndicator = iota // StatusInProgress for ongoing operations. StatusInProgress // StatusCompleted for completed operations. StatusCompleted // StatusFailed for failed operations. StatusFailed // StatusPaused for paused operations. StatusPaused // StatusCancelled for cancelled operations. StatusCancelled )
type TableFormatter ¶
type TableFormatter struct {
Headers []string
Rows [][]string
// contains filtered or unexported fields
}
TableFormatter provides table formatting capabilities.
func (*TableFormatter) AddRow ¶
func (tf *TableFormatter) AddRow(row []string)
AddRow adds a row to the table.
func (*TableFormatter) Format ¶
func (tf *TableFormatter) Format() string
Format formats the table for display.