Documentation
¶
Overview ¶
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information.
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information.
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information.
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information. Package output provides colored output utilities for command-line interface.
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information.
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information. Package output provides colored output utilities for command-line interface.
Index ¶
- Variables
- func DebugError(err error, context string)
- func Debugf(format string, a ...interface{})
- func ErrorToOutput(err error)
- func Fatalf(format string, a ...interface{})
- func HandleError(err error) bool
- func HandleFatalError(err error)
- func InitializeErrorHandler()
- func IsUserError(err error) bool
- func LogAndPrintf(level, format string, args ...interface{})
- func PrintErrorf(format string, a ...interface{})
- func PrintInfof(format string, a ...interface{})
- func PrintSuccessf(format string, a ...interface{})
- func PrintUserError(err error)
- func PrintWarningf(format string, a ...interface{})
- func Printf(format string, a ...interface{})
- func Prompt(prompt string) string
- func WithLogger(log logger.Logger) func(string, ...interface{})
- func WrapError(err error, message string) error
- type ProgressBar
- type Spinner
- type UserError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( Success = color.New(color.FgGreen).SprintFunc() Error = color.New(color.FgRed).SprintFunc() Warning = color.New(color.FgYellow).SprintFunc() Info = color.New(color.FgBlue).SprintFunc() Bold = color.New(color.Bold).SprintFunc() )
Color functions for different message types
Functions ¶
func DebugError ¶ added in v1.0.0
DebugError logs an error at debug level with context
func Debugf ¶
func Debugf(format string, a ...interface{})
Debugf prints a debug message if debug mode is enabled.
func ErrorToOutput ¶ added in v1.0.0
func ErrorToOutput(err error)
ErrorToOutput converts an error to appropriate output format
func Fatalf ¶
func Fatalf(format string, a ...interface{})
Fatalf prints an error message and exits with code 1.
func HandleError ¶ added in v1.0.0
HandleError is a convenience function to handle errors with output
func HandleFatalError ¶ added in v1.0.0
func HandleFatalError(err error)
HandleFatalError handles a fatal error and exits
func InitializeErrorHandler ¶ added in v1.0.0
func InitializeErrorHandler()
InitializeErrorHandler sets up the error handler with output functions
func LogAndPrintf ¶ added in v1.0.0
func LogAndPrintf(level, format string, args ...interface{})
LogAndPrintf logs at the appropriate level and prints to output
func PrintErrorf ¶
func PrintErrorf(format string, a ...interface{})
PrintErrorf prints a formatted error message.
func PrintInfof ¶
func PrintInfof(format string, a ...interface{})
PrintInfof prints a formatted info message.
func PrintSuccessf ¶
func PrintSuccessf(format string, a ...interface{})
PrintSuccessf prints a formatted success message.
func PrintUserError ¶
func PrintUserError(err error)
PrintUserError prints a UserError in a friendly format
func PrintWarningf ¶
func PrintWarningf(format string, a ...interface{})
PrintWarningf prints a formatted warning message.
func Printf ¶
func Printf(format string, a ...interface{})
Printf prints a formatted message.
Example ¶
package main
import (
"github.com/gifflet/ccmd/internal/output"
)
func main() {
// Basic output examples
output.Printf("Regular message")
output.PrintInfof("Information message")
output.PrintSuccessf("Operation completed successfully")
output.PrintWarningf("This is a warning")
output.PrintErrorf("Something went wrong")
}
Output:
func WithLogger ¶ added in v1.0.0
WithLogger creates a context-aware output function
Types ¶
type ProgressBar ¶
type ProgressBar struct {
// contains filtered or unexported fields
}
ProgressBar provides a simple progress indicator
Example ¶
package main
import (
"time"
"github.com/gifflet/ccmd/internal/output"
)
func main() {
// Using progress bar for measurable operations
items := []string{"file1.txt", "file2.txt", "file3.txt"}
progress := output.NewProgressBar(len(items), "Processing files")
for _, item := range items {
// Process item
_ = item
time.Sleep(500 * time.Millisecond)
progress.Increment()
}
progress.Complete()
}
Output:
func NewProgressBar ¶
func NewProgressBar(total int, message string) *ProgressBar
NewProgressBar creates a new progress bar
func (*ProgressBar) Complete ¶
func (p *ProgressBar) Complete()
Complete marks the progress as complete
func (*ProgressBar) Increment ¶
func (p *ProgressBar) Increment()
Increment increments the progress by 1
func (*ProgressBar) Update ¶
func (p *ProgressBar) Update(current int)
Update updates the progress bar with the current value
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides a simple loading indicator
Example ¶
package main
import (
"time"
"github.com/gifflet/ccmd/internal/output"
)
func main() {
// Using spinner for long operations
spinner := output.NewSpinner("Processing files...")
spinner.Start()
// Simulate work
time.Sleep(2 * time.Second)
spinner.Success("Files processed successfully")
// Or show error
spinner2 := output.NewSpinner("Downloading...")
spinner2.Start()
time.Sleep(1 * time.Second)
spinner2.Error("Download failed")
}
Output:
func NewSpinner ¶
NewSpinner creates a new spinner with the given message
type UserError ¶
UserError represents an error that should be displayed to the user with a friendly message
Example ¶
package main
import (
"errors"
"github.com/gifflet/ccmd/internal/output"
)
func main() {
// Creating user-friendly errors
err := output.NewUserError("Failed to load configuration", errors.New("file not found"))
output.PrintUserError(err)
// Using formatted error
err2 := output.NewUserErrorf("Invalid command: %s", "unknown-cmd")
output.PrintUserError(err2)
}
Output:
func NewUserError ¶
NewUserError creates a new user-friendly error
func NewUserErrorf ¶
NewUserErrorf creates a new user-friendly error with formatted message