summaryrefslogtreecommitdiff
path: root/cli_lolcat
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2022-03-05 12:53:15 -0700
committerCody Hiar <cody@hiar.ca>2022-03-05 12:53:15 -0700
commit90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 (patch)
tree8e2799822b4de29014b86ca708123c1dfc8f45f5 /cli_lolcat
Initial CommitHEADmaster
Diffstat (limited to 'cli_lolcat')
-rw-r--r--cli_lolcat/go.mod8
-rw-r--r--cli_lolcat/go.sum5
-rw-r--r--cli_lolcat/hello.go38
3 files changed, 51 insertions, 0 deletions
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++
+ }
+}