Mercurial > mercurial > hgweb_golang.cgi
view src/gomatrix.go @ 60:058fb0a2cda8
fix eraline.
author | pyon@macmini |
---|---|
date | Fri, 14 Aug 2020 03:31:29 +0900 |
parents | 1b293bb0a011 |
children |
line wrap: on
line source
package main import ( "flag" "fmt" "math/rand" "runtime" "time" ) func main() { sw := flag.Int( "w", 40, "screen width" ) sl := flag.Int( "s", 100, "interval" ) flag.Parse() s := "0123456789abcdefghijkemnopqrstuvwxyzABCDEFGHIJKEMNOPQRSTUVWXYZ!@#$%&*|;:.,=+-/" n := len( s ) r := 0 for i := 1 ; ; i++ { r = rand.Intn( n ) fmt.Printf( "%s ", random_color( s[r] ) ) if i == *sw { for t := 0; t < *sl; t++ { time.Sleep( time.Millisecond ) } fmt.Println() i = 0 } } } func random_color( s byte ) string { if runtime.GOOS == "windows" { return string( s ) } // black, red, green yellow, blue, magenta, cyan, white c := [...]int{ 30, 31, 32, 33, 34, 35, 36, 37 } r := rand.Intn( len( c ) ) return fmt.Sprintf( "\x1b[%dm%c\x1b[0m", c[r], s ) }