github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/cli/banner.go (about) 1 package cli 2 3 import ( 4 "strings" 5 6 "github.com/aybabtme/rgbterm" 7 "github.com/fatih/color" 8 ) 9 10 const ( 11 startColor = 0xffd651 12 endColor = 0xf64d3d 13 ) 14 15 func GradientBanner(banner string) string { 16 if color.NoColor { 17 return banner + "\n" 18 } 19 20 str := "" 21 arr := strings.Split(banner, "\n") 22 l := len(arr) 23 for i, line := range arr { 24 if line == "" { 25 break 26 } 27 progress := float64(i) / float64(l-1) 28 r := gradient(startColor, endColor, 16, progress) 29 g := gradient(startColor, endColor, 8, progress) 30 b := gradient(startColor, endColor, 0, progress) 31 str += rgbterm.FgString(line, r, g, b) + "\n" 32 } 33 return str 34 } 35 36 func gradient(start, end, offset int, progress float64) uint8 { 37 start = (start >> offset) & 0xff 38 end = (end >> offset) & 0xff 39 return uint8(start + int(float64(end-start)*progress)) 40 }