Enhance pmg outputs by adding colors and removing markdown notions

This commit is contained in:
Sahilb315
2025-05-04 23:47:25 +05:30
parent 53afbaf2ce
commit e48ba6ba3d
5 changed files with 44 additions and 5 deletions
+10 -4
View File
@@ -10,14 +10,20 @@ import (
)
func ConfirmInstallation(maliciousPkgs map[string]string) bool {
fmt.Printf("\nWARNING: %d potentially malicious packages detected!\n", len(maliciousPkgs))
fmt.Println("The following packages have been flagged:")
colors := NewTerminalColors()
fmt.Printf("\n%s\n", colors.Red("⚠️ WARNING: %d potentially malicious packages detected!", len(maliciousPkgs)))
fmt.Println(colors.Yellow("The following packages have been flagged:"))
for name, reason := range maliciousPkgs {
fmt.Printf("- %s: %s\n", name, reason)
fmt.Printf("%s %s: %s\n",
colors.Cyan("•"), // bullet point
colors.Yellow(name),
removeMarkdown(reason),
)
}
fmt.Print("\nDo you want to continue with installation? (y/N): ")
fmt.Print("\n", colors.Green("Do you want to continue with installation? (y/N): "))
reader := bufio.NewReader(os.Stdin)
response, err := reader.ReadString('\n')
if err != nil {
+20
View File
@@ -0,0 +1,20 @@
package utils
import "github.com/fatih/color"
type TerminalColors struct {
Red func(format string, a ...interface{}) string
Yellow func(format string, a ...interface{}) string
Cyan func(format string, a ...interface{}) string
Green func(format string, a ...interface{}) string
}
// NewTerminalColors initializes and returns TerminalColors
func NewTerminalColors() *TerminalColors {
return &TerminalColors{
Red: color.New(color.FgRed, color.Bold).SprintfFunc(),
Yellow: color.New(color.FgYellow).SprintfFunc(),
Cyan: color.New(color.FgCyan).SprintfFunc(),
Green: color.New(color.FgGreen).SprintfFunc(),
}
}
+10
View File
@@ -76,3 +76,13 @@ func IsInstallCommand(pkgManager, cmd string) bool {
}
return false
}
func removeMarkdown(text string) string {
// Remove bold asterisks
text = strings.ReplaceAll(text, "**", "")
// Remove italic asterisks
text = strings.ReplaceAll(text, "*", "")
// Remove backticks
text = strings.ReplaceAll(text, "`", "")
return text
}
+3 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/fatih/color"
"github.com/safedep/dry/log"
"github.com/safedep/pmg/internal/ui"
"github.com/safedep/pmg/pkg/analyser"
@@ -133,7 +134,8 @@ func (pmw *PackageManagerWrapper) analyzeDependencies(ctx context.Context, deps
log.Infof("Installation canceled due to security concerns")
return fmt.Errorf("installation canceled")
}
log.Warnf("Continuing installation despite security warnings...")
yellow := color.New(color.FgYellow, color.Bold).SprintfFunc()
log.Warnf(yellow("Continuing installation despite security warnings..."))
}
return nil