2025-08-21 23:01:30 +05:30
|
|
|
package ui
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2026-01-18 19:46:23 +05:30
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
2025-08-21 23:01:30 +05:30
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2026-01-18 19:46:23 +05:30
|
|
|
brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink
|
|
|
|
|
whiteDim = color.New(color.Faint).SprintFunc()
|
|
|
|
|
pseudoPattern = regexp.MustCompile(`^(v?\d+\.\d+\.\d+)-0\.\d{14}-[a-f0-9]{12}$`)
|
2025-08-21 23:01:30 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GeneratePMGBanner(version, commit string) string {
|
2026-01-18 19:46:23 +05:30
|
|
|
// Build the first line with a differently colored URL segment
|
|
|
|
|
line1 := fmt.Sprintf("%s\tFrom SafeDep %s", brandPinkRed("█▀█ █▀▄▀█ █▀▀"), whiteDim("(github.com/safedep/pmg)"))
|
|
|
|
|
line2 := brandPinkRed("█▀▀ █░▀░█ █▄█")
|
|
|
|
|
|
|
|
|
|
pmgASCIIText := "\n" + line1 + "\n" + line2 // It should end here no \n
|
2025-08-21 23:01:30 +05:30
|
|
|
|
|
|
|
|
if len(commit) >= 6 {
|
|
|
|
|
commit = commit[:6]
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-18 19:46:23 +05:30
|
|
|
// Clean version to remove pseudo-version complexity
|
|
|
|
|
version = cleanVersion(version)
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s %s: %s %s: %s\n\n", pmgASCIIText,
|
2026-01-11 19:25:13 +05:30
|
|
|
whiteDim("version"), Colors.Bold(version),
|
|
|
|
|
whiteDim("commit"), Colors.Bold(commit),
|
2025-08-21 23:01:30 +05:30
|
|
|
)
|
|
|
|
|
}
|
2026-01-18 19:46:23 +05:30
|
|
|
|
|
|
|
|
// cleanVersion removes ugly pseudo-version timestamps and dirty flags
|
|
|
|
|
// Keeps clean versions like v1.2.3-alpha.1 and v0.3.5-edfdd54 as-is
|
|
|
|
|
func cleanVersion(version string) string {
|
|
|
|
|
if version == "" {
|
|
|
|
|
return version
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove build metadata (+dirty, +build.1, etc.)
|
|
|
|
|
version = strings.Split(version, "+")[0]
|
|
|
|
|
|
|
|
|
|
// Only clean pseudo-versions with timestamps
|
|
|
|
|
// Pattern: v1.2.3-0.20220101123456-abcdef123456
|
|
|
|
|
if matches := pseudoPattern.FindStringSubmatch(version); len(matches) > 1 {
|
|
|
|
|
return matches[1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return version
|
|
|
|
|
}
|