From 90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Sat, 5 Mar 2022 12:53:15 -0700 Subject: Initial Commit --- cli_lolcat/go.mod | 8 ++++++++ cli_lolcat/go.sum | 5 +++++ cli_lolcat/hello.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 cli_lolcat/go.mod create mode 100644 cli_lolcat/go.sum create mode 100644 cli_lolcat/hello.go (limited to 'cli_lolcat') diff --git a/cli_lolcat/go.mod b/cli_lolcat/go.mod new file mode 100644 index 0000000..5f0c3bf --- /dev/null +++ b/cli_lolcat/go.mod @@ -0,0 +1,8 @@ +module hello + +go 1.15 + +require ( + rsc.io/quote v1.5.2 + syreclabs.com/go/faker v1.2.3 +) diff --git a/cli_lolcat/go.sum b/cli_lolcat/go.sum new file mode 100644 index 0000000..ab09410 --- /dev/null +++ b/cli_lolcat/go.sum @@ -0,0 +1,5 @@ +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +syreclabs.com/go/faker v1.2.3 h1:HPrWtnHazIf0/bVuPZJLFrtHlBHk10hS0SB+mV8v6R4= +syreclabs.com/go/faker v1.2.3/go.mod h1:NAXInmkPsC2xuO5MKZFe80PUXX5LU8cFdJIHGs+nSBE= diff --git a/cli_lolcat/hello.go b/cli_lolcat/hello.go new file mode 100644 index 0000000..1a46da8 --- /dev/null +++ b/cli_lolcat/hello.go @@ -0,0 +1,38 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "math" + "os" +) + +func rgb(i int) (int, int, int) { + var f = 0.1 + return int(math.Sin(f*float64(i)+0)*127 + 128), + int(math.Sin(f*float64(i)+2*math.Pi/3)*127 + 128), + int(math.Sin(f*float64(i)+4*math.Pi/3)*127 + 128) +} + + +func main() { + info, _ := os.Stdin.Stat() + + if info.Mode()&os.ModeCharDevice != 0 { + fmt.Println("The command is intended to work with pipes.") + fmt.Println("Usage: command | gorainbow") + } + + reader := bufio.NewReader(os.Stdin) + j := 0 + for { + input, _, err := reader.ReadRune() + if err != nil && err == io.EOF { + break + } + r, g, b := rgb(j) + fmt.Printf("\033[38;2;%d;%d;%dm%c\033[0m", r, g, b, input) + j++ + } +} -- cgit v1.2.3