@@ -2,26 +2,53 @@ package ui
22
33import (
44 "fmt"
5+ "regexp"
6+ "strings"
57
68 "github.com/fatih/color"
79)
810
911var (
10- brandPinkRed = color .RGB (219 , 39 , 119 ).Add (color .Bold ).SprintFunc () // #DB2777 Brand Pink
11- whiteDim = color .New (color .Faint ).SprintFunc ()
12+ brandPinkRed = color .RGB (219 , 39 , 119 ).Add (color .Bold ).SprintFunc () // #DB2777 Brand Pink
13+ whiteDim = color .New (color .Faint ).SprintFunc ()
14+ pseudoPattern = regexp .MustCompile (`^(v?\d+\.\d+\.\d+)-0\.\d{14}-[a-f0-9]{12}$` )
1215)
1316
1417func GeneratePMGBanner (version , commit string ) string {
15- var pmgASCIIText = `
16- █▀█ █▀▄▀█ █▀▀ From SafeDep
17- █▀▀ █░▀░█ █▄█` // It should end here no \n
18+ // Build the first line with a differently colored URL segment
19+ line1 := fmt .Sprintf ("%s\t From SafeDep %s" , brandPinkRed ("█▀█ █▀▄▀█ █▀▀" ), whiteDim ("(github.com/safedep/pmg)" ))
20+ line2 := brandPinkRed ("█▀▀ █░▀░█ █▄█" )
21+
22+ pmgASCIIText := "\n " + line1 + "\n " + line2 // It should end here no \n
1823
1924 if len (commit ) >= 6 {
2025 commit = commit [:6 ]
2126 }
2227
23- return fmt .Sprintf ("%s %s: %s %s: %s\n \n " , brandPinkRed (pmgASCIIText ),
28+ // Clean version to remove pseudo-version complexity
29+ version = cleanVersion (version )
30+
31+ return fmt .Sprintf ("%s %s: %s %s: %s\n \n " , pmgASCIIText ,
2432 whiteDim ("version" ), Colors .Bold (version ),
2533 whiteDim ("commit" ), Colors .Bold (commit ),
2634 )
2735}
36+
37+ // cleanVersion removes ugly pseudo-version timestamps and dirty flags
38+ // Keeps clean versions like v1.2.3-alpha.1 and v0.3.5-edfdd54 as-is
39+ func cleanVersion (version string ) string {
40+ if version == "" {
41+ return version
42+ }
43+
44+ // Remove build metadata (+dirty, +build.1, etc.)
45+ version = strings .Split (version , "+" )[0 ]
46+
47+ // Only clean pseudo-versions with timestamps
48+ // Pattern: v1.2.3-0.20220101123456-abcdef123456
49+ if matches := pseudoPattern .FindStringSubmatch (version ); len (matches ) > 1 {
50+ return matches [1 ]
51+ }
52+
53+ return version
54+ }
0 commit comments