1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
package main
import (
"strings"
"github.com/pterm/pterm"
)
func main() {
// Define RGB values for gradient points.
startColor := pterm.NewRGB(0, 255, 255)
firstPoint := pterm.NewRGB(255, 0, 255)
secondPoint := pterm.NewRGB(255, 0, 0)
thirdPoint := pterm.NewRGB(0, 255, 0)
endColor := pterm.NewRGB(255, 255, 255)
// Define the string to be printed.
str := "RGB colors only work in Terminals which support TrueColor."
strs := strings.Split(str, "")
// Initialize an empty string for the faded info.
var fadeInfo string
// Loop over the string length to create a gradient effect.
for i := 0; i < len(str); i++ {
// Append each character of the string with a faded color to the info string.
fadeInfo += startColor.Fade(0, float32(len(str)), float32(i), firstPoint).Sprint(strs[i])
}
// Print the info string with gradient effect.
pterm.Info.Println(fadeInfo)
// Get the terminal height.
terminalHeight := pterm.GetTerminalHeight()
// Loop over the terminal height to print "Hello, World!" with a gradient effect.
for i := 0; i < terminalHeight-2; i++ {
// Print the string with a color that fades from startColor to endColor.
startColor.Fade(0, float32(terminalHeight-2), float32(i), firstPoint, secondPoint, thirdPoint, endColor).Println("Hello, World!")
}
}
|