Files
gh-action-readme/internal/output.go
Ismo Vuorinen 7a8dc8d2ba feat: implement progress indicators and status updates
- Enhanced dependency analyzer with AnalyzeActionFileWithProgress() method supporting optional progress callbacks
- Added progress bars to analyzeDependencies() and analyzeSecurityDeps() functions for batch operations
- Added IsQuiet() method to ColoredOutput for proper quiet mode handling
- Progress bars automatically show for multi-file operations (>1 file) and respect quiet mode
- Refactored analyzer code to reduce cyclomatic complexity from 14 to under 10
- Updated TODO.md to mark progress indicators task and all security tasks as completed
- All tests passing, 0 linting issues, maintains backward compatibility

Provides professional user experience with clear progress feedback for long-running operations.
2025-08-04 00:49:22 +03:00

110 lines
2.4 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package internal
import (
"fmt"
"os"
"github.com/fatih/color"
)
// ColoredOutput provides methods for colored terminal output.
type ColoredOutput struct {
NoColor bool
Quiet bool
}
// NewColoredOutput creates a new colored output instance.
func NewColoredOutput(quiet bool) *ColoredOutput {
return &ColoredOutput{
NoColor: color.NoColor || os.Getenv("NO_COLOR") != "",
Quiet: quiet,
}
}
// IsQuiet returns whether the output is in quiet mode.
func (co *ColoredOutput) IsQuiet() bool {
return co.Quiet
}
// Success prints a success message in green.
func (co *ColoredOutput) Success(format string, args ...any) {
if co.Quiet {
return
}
if co.NoColor {
fmt.Printf("✅ "+format+"\n", args...)
} else {
color.Green("✅ "+format, args...)
}
}
// Error prints an error message in red to stderr.
func (co *ColoredOutput) Error(format string, args ...any) {
if co.NoColor {
fmt.Fprintf(os.Stderr, "❌ "+format+"\n", args...)
} else {
_, _ = color.New(color.FgRed).Fprintf(os.Stderr, "❌ "+format+"\n", args...)
}
}
// Warning prints a warning message in yellow.
func (co *ColoredOutput) Warning(format string, args ...any) {
if co.Quiet {
return
}
if co.NoColor {
fmt.Printf("⚠️ "+format+"\n", args...)
} else {
color.Yellow("⚠️ "+format, args...)
}
}
// Info prints an info message in blue.
func (co *ColoredOutput) Info(format string, args ...any) {
if co.Quiet {
return
}
if co.NoColor {
fmt.Printf(" "+format+"\n", args...)
} else {
color.Blue(" "+format, args...)
}
}
// Progress prints a progress message in cyan.
func (co *ColoredOutput) Progress(format string, args ...any) {
if co.Quiet {
return
}
if co.NoColor {
fmt.Printf("🔄 "+format+"\n", args...)
} else {
color.Cyan("🔄 "+format, args...)
}
}
// Bold prints text in bold.
func (co *ColoredOutput) Bold(format string, args ...any) {
if co.Quiet {
return
}
if co.NoColor {
fmt.Printf(format+"\n", args...)
} else {
_, _ = color.New(color.Bold).Printf(format+"\n", args...)
}
}
// Printf prints without color formatting (respects quiet mode).
func (co *ColoredOutput) Printf(format string, args ...any) {
if co.Quiet {
return
}
fmt.Printf(format, args...)
}
// Fprintf prints to specified writer without color formatting.
func (co *ColoredOutput) Fprintf(w *os.File, format string, args ...any) {
_, _ = fmt.Fprintf(w, format, args...)
}