Skip to content

Instantly share code, notes, and snippets.

@Yariya
Created March 10, 2021 19:55
Show Gist options
  • Save Yariya/6a2e67d76a57ec6dc5193b7a96459ad6 to your computer and use it in GitHub Desktop.
Save Yariya/6a2e67d76a57ec6dc5193b7a96459ad6 to your computer and use it in GitHub Desktop.
golang rainbow console text
package main
import (
"fmt"
"math/rand"
"os"
"time"
)
func rainbow(i string, timeout int) {
colors := []string{
"\033[;31m",
"\033[;34m",
"\033[;32m",
"\033[;35m",
//Add more if needed
}
for {
n := rand.Int() % len(colors)
fmt.Printf("\r%s%s", colors[n], i)
os.Stdout.Sync()
time.Sleep(time.Millisecond * time.Duration(timeout))
}
}
func main() {
rainbow("Text", 300) // Text | Timeout
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment