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 Fatalf(format string, a ...interface{})
- func HandleError(err error) bool
- func HandleFatalError(err error)
- func LogAndPrintError(log logger.Logger, err error, message string)
- func PrintError(err error)
- func PrintErrorf(format string, a ...interface{})
- func PrintInfof(format string, a ...interface{})
- func PrintSuccessf(format string, a ...interface{})
- func PrintWarningf(format string, a ...interface{})
- func Printf(format string, a ...interface{})
- func Prompt(prompt string) string
- type ProgressBar
- type Spinner
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 Fatalf ¶
func Fatalf(format string, a ...interface{})
Fatalf prints an error message and exits with code 1.
func HandleError ¶
HandleError is a convenience function to handle errors with output
func HandleFatalError ¶
func HandleFatalError(err error)
HandleFatalError handles a fatal error and exits
func LogAndPrintError ¶
LogAndPrintError logs an error with context and outputs to user
func PrintError ¶
func PrintError(err error)
PrintError prints an error to the user in appropriate format
Example ¶
package main
import (
"errors"
ccmderrors "github.com/gifflet/ccmd/pkg/errors"
"github.com/gifflet/ccmd/pkg/output"
)
func main() {
// Printing errors with appropriate formatting
err := errors.New("file not found")
output.PrintError(err)
// Using pkg/errors for better error handling
err2 := ccmderrors.NotFound("command unknown-cmd")
output.PrintError(err2)
}
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 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/pkg/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/pkg/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/pkg/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