Created
March 10, 2021 19:55
-
-
Save Yariya/6a2e67d76a57ec6dc5193b7a96459ad6 to your computer and use it in GitHub Desktop.
golang rainbow console text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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