mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
Enhance pmg outputs by adding colors and removing markdown notions
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user