├── .github └── workflows │ ├── ci.yaml │ └── goreleaser.yaml ├── .gitignore ├── assets └── screenshot.png ├── cmd ├── parameters.go └── root.go ├── example └── main.go ├── go.mod ├── go.sum ├── internal ├── joinFiles.go └── root.go ├── license ├── main.go ├── pkg ├── printWithColors.go ├── rbg.go └── rgb_test.go └── readme.md /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | strategy: 8 | matrix: 9 | go: ["1.17"] 10 | name: Go ${{ matrix.go }} sample 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Setup go 14 | uses: actions/setup-go@v2 15 | with: 16 | go-version: ${{ matrix.go }} 17 | - run: | 18 | go build 19 | go test ./... 20 | -------------------------------------------------------------------------------- /.github/workflows/goreleaser.yaml: -------------------------------------------------------------------------------- 1 | name: goreleaser 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | permissions: 9 | contents: write 10 | 11 | jobs: 12 | goreleaser: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | with: 18 | fetch-depth: 0 19 | - name: Set up Go 20 | uses: actions/setup-go@v2 21 | with: 22 | go-version: 1.17 23 | - name: Run GoReleaser 24 | uses: goreleaser/goreleaser-action@v2 25 | with: 26 | distribution: goreleaser 27 | version: latest 28 | args: release --rm-dist 29 | env: 30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | chigo 2 | -------------------------------------------------------------------------------- /assets/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UltiRequiem/chigo/99ec3681962f4fbea980e87ac60eb925bb87e3c3/assets/screenshot.png -------------------------------------------------------------------------------- /cmd/parameters.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/UltiRequiem/chigo/pkg" 8 | ) 9 | 10 | func parametersAndFlags() (bool, bool, []string) { 11 | help := flag.Bool("help", false, "Display Help") 12 | helpShort := flag.Bool("h", false, "Display Help") 13 | 14 | flag.Usage = printHelp 15 | 16 | flag.Parse() 17 | 18 | return *help || *helpShort, flag.NArg() > 0, flag.Args() 19 | } 20 | 21 | func printHelp() { 22 | fmt.Println(chigo.Colorize(fmt.Sprintf(HELP_MESSAGE, VERSION))) 23 | } 24 | 25 | const VERSION = "1.0.0" 26 | 27 | const HELP_MESSAGE = `Chigo %s 28 | Concatenate FILE(s) or standard input to standard output. 29 | When no FILE is passed read standard input. 30 | 31 | Examples: 32 | chigo fOne fTwo # Output fOne and fTwo contents. 33 | chigo # Copy standard input to standard output. 34 | echo "My Message" | chigo # Display "My message". 35 | fortune | chigo # Display a rainbow cookie. 36 | 37 | If you need more help, found a bug or want to suggest a new feature: 38 | https://github.com/UltiRequiem/chigo` 39 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/UltiRequiem/chigo/internal" 6 | 7 | chigo "github.com/UltiRequiem/chigo/pkg" 8 | 9 | "github.com/mattn/go-colorable" 10 | ) 11 | 12 | func Main() { 13 | // Windows Support 14 | defer colorable.EnableColorsStdout(nil)() 15 | 16 | help, fileArguments, files := parametersAndFlags() 17 | 18 | if help { 19 | printHelp() 20 | return 21 | } 22 | 23 | if fileArguments { 24 | data, error := internal.JoinFiles(files) 25 | 26 | if error != nil { 27 | fmt.Println(chigo.Colorize(error.Error())) 28 | return 29 | } 30 | 31 | fmt.Println(chigo.Colorize(data)) 32 | return 33 | } 34 | 35 | internal.StartProcessFromStdin() 36 | } 37 | -------------------------------------------------------------------------------- /example/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | chigo "github.com/UltiRequiem/chigo/pkg" 7 | ) 8 | 9 | func main() { 10 | fmt.Println(chigo.Colorize("Hello, World!")) 11 | } 12 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/UltiRequiem/chigo 2 | 3 | go 1.17 4 | 5 | require github.com/mattn/go-colorable v0.1.12 6 | 7 | require ( 8 | github.com/mattn/go-isatty v0.0.14 // indirect 9 | golang.org/x/sys v0.1.0 // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= 2 | github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 3 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 4 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 5 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 6 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 7 | golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= 8 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 9 | -------------------------------------------------------------------------------- /internal/joinFiles.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import "os" 4 | 5 | func JoinFiles(files []string) (string, error) { 6 | text := "" 7 | 8 | for _, file := range files { 9 | fileText, err := os.ReadFile(file) 10 | 11 | if err != nil { 12 | return "", err 13 | } 14 | 15 | text += string(fileText) + "\n" 16 | } 17 | 18 | return text, nil 19 | } 20 | -------------------------------------------------------------------------------- /internal/root.go: -------------------------------------------------------------------------------- 1 | // Internal Chigo Utils 2 | package internal 3 | 4 | import ( 5 | "bufio" 6 | "fmt" 7 | "os" 8 | 9 | chigo "github.com/UltiRequiem/chigo/pkg" 10 | ) 11 | 12 | func StartProcessFromStdin() { 13 | reader := bufio.NewReader(os.Stdin) 14 | 15 | for i := 1.0; true; i++ { 16 | input, _, err := reader.ReadRune() 17 | 18 | if err != nil { 19 | fmt.Println(chigo.Colorize(err.Error())) 20 | break 21 | } 22 | 23 | rgb := chigo.NewRGB(i) 24 | 25 | fmt.Printf("\033[38;2;%d;%d;%dm%s\033[0m", rgb.Red, rgb.Green, rgb.Blue, string(input)) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Eliaz Bobadilla (https://ultirequiem.xyz) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/UltiRequiem/chigo/cmd" 4 | 5 | func main() { 6 | cmd.Main() 7 | } 8 | -------------------------------------------------------------------------------- /pkg/printWithColors.go: -------------------------------------------------------------------------------- 1 | package chigo 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func Colorize(text string) string { 10 | scanner := bufio.NewScanner(strings.NewReader(text)) 11 | 12 | result := "" 13 | 14 | for i := 1.0; scanner.Scan(); i++ { 15 | rgb := NewRGB(i) 16 | 17 | result += fmt.Sprintf("\033[38;2;%d;%d;%dm%s\033[0m\n", rgb.Red, rgb.Green, rgb.Blue, scanner.Text()) 18 | } 19 | 20 | return result 21 | } 22 | -------------------------------------------------------------------------------- /pkg/rbg.go: -------------------------------------------------------------------------------- 1 | package chigo 2 | 3 | import "math" 4 | 5 | type RGB struct { 6 | Red, Green, Blue int 7 | } 8 | 9 | func NewRGB(i float64) RGB { 10 | return RGB{ 11 | int(math.Sin(0.1*i)*127 + 128), 12 | int(math.Sin(0.1*i+2*math.Pi/3)*127 + 128), 13 | int(math.Sin(0.1*i+4*math.Pi/3)*127 + 128), 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pkg/rgb_test.go: -------------------------------------------------------------------------------- 1 | package chigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNewRGB(t *testing.T) { 8 | rgb := NewRGB(0) 9 | 10 | if rgb.Red != 128 || rgb.Green != 237 || rgb.Blue != 18 { 11 | t.Errorf("NewRGB(0, 0, 0) failed") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Chigo 🦄 2 | 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/UltiRequiem/chigo)](https://goreportcard.com/report/github.com/UltiRequiem/chigo) 4 | [![Go Reference](https://pkg.go.dev/badge/github.com/UltiRequiem/chigo/pkg.svg)](https://pkg.go.dev/github.com/UltiRequiem/chigo/pkg) 5 | 6 | [Lolcat](https://github.com/busyloop/lolcat) port for Golang 🌈 7 | 8 | ## Showcase 9 | 10 | ![Screenshot](./assets/screenshot.png) 11 | 12 | [Video](https://youtu.be/4Bc-aBfjxwY) 📹 13 | 14 | ## Installation 15 | 16 | ```sh 17 | go install github.com/UltiRequiem/chigo@latest 18 | ``` 19 | 20 | Or use a binary from 21 | [releases](https://github.com/UltiRequiem/chigo/releases/latest). 22 | 23 | ## Documentation 24 | 25 | It also exports utils to output with colors in your own CLI Tools. 26 | 27 | ```go 28 | package main 29 | 30 | import ( 31 | "fmt" 32 | chigo "github.com/UltiRequiem/chigo/pkg" 33 | ) 34 | 35 | func main() { 36 | fmt.Println(chigo.Colorize("Hello, World!")) 37 | } 38 | ``` 39 | 40 | > [A more complete example](https://github.com/UltiRequiem/lorelai/tree/main/cmd/utils.go) 41 | > 🕵️‍♂️ 42 | 43 | [Autogenerated docs](https://pkg.go.dev/github.com/UltiRequiem/chigo/pkg) 📑 44 | 45 | [I also made a blog about this project](https://blog.ultirequiem.com/chigo) 🚀 46 | 47 | ## Support 48 | 49 | Open an Issue, I will check it a soon as possible 👀 50 | 51 | If you want to hurry me up a bit 52 | [send me a tweet](https://twitter.com/UltiRequiem) 😆 53 | 54 | Consider [supporting me on Patreon](https://patreon.com/UltiRequiem) if you like 55 | my work 🚀 56 | 57 | Don't forget to star the repo ⭐ 58 | 59 | ## Versioning 60 | 61 | We use [Semantic Versioning](http://semver.org). For the versions available, see 62 | the [tags](https://github.com/UltiRequiem/chigo/tags) 🏷️ 63 | 64 | ## Authors 65 | 66 | [Eliaz Bobadilla (a.k.a UltiRequiem)](https://ultirequiem.com) - Creator and 67 | Maintainer 💪 68 | 69 | See also the full list of 70 | [contributors](https://github.com/UltiRequiem/chigo/contributors) who 71 | participated in this project. 72 | 73 | ## Licence 74 | 75 | Licensed under the MIT License 📄 76 | --------------------------------------------------------------------------------