Documentation
¶
Overview ¶
Package output provides colored output utilities for command-line interface.
Package output provides colored output utilities for command-line interface.
Index ¶
- Variables
- func Debugf(format string, a ...interface{})
- func Fatalf(format string, a ...interface{})
- func IsUserError(err error) bool
- 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 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 Debugf ¶
func Debugf(format string, a ...interface{})
Debugf prints a debug message if debug mode is enabled.
func Fatalf ¶
func Fatalf(format string, a ...interface{})
Fatalf prints an error message and exits with code 1.
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:
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