├── .gitignore ├── samples ├── sample1.png ├── sample2.png ├── sample3.png └── sample4.png ├── go.mod ├── LICENSE ├── README.md ├── main.go └── go.sum /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /samples/sample1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inancgumus/godocc/HEAD/samples/sample1.png -------------------------------------------------------------------------------- /samples/sample2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inancgumus/godocc/HEAD/samples/sample2.png -------------------------------------------------------------------------------- /samples/sample3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inancgumus/godocc/HEAD/samples/sample3.png -------------------------------------------------------------------------------- /samples/sample4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inancgumus/godocc/HEAD/samples/sample4.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/inancgumus/godocc 2 | 3 | require ( 4 | github.com/alecthomas/chroma v0.6.2 5 | github.com/mattn/go-colorable v0.1.0 6 | ) 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Inanc Gumus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # godocc 2 | 3 | Like `go doc` but with colors. 4 | 5 | ## Installation 6 | 7 | ``` 8 | $ go install github.com/inancgumus/godocc@latest 9 | ``` 10 | 11 | ## Usage 12 | 13 | Accepts all the arguments and flags `go doc` works with. Godocc is just a simple wrapper around the go doc tool. 14 | 15 | Example: 16 | 17 | ``` 18 | $ godocc io Writer 19 | ``` 20 | ![godocc sample 1](samples/sample3.png) 21 | 22 | ``` 23 | $ godocc ioutil 24 | ``` 25 | 26 | ![godocc sample 2](samples/sample4.png) 27 | 28 | ## Styling 29 | 30 | godocc comes with many colors! Configure the color of the output by setting the following env variable: 31 | 32 | ``` 33 | $ GODOCC_STYLE="dracula" 34 | ``` 35 | 36 | **My favorite styles:** dracula, monokai, fruity, native, paraiso-dark, pygments, rainbow_dash, rrt, solarized-dark, swapoff, vim. 37 | 38 | **Other styles:** abap, algol, arduino, autumn, borland, bw, colorful, emacs, friendly, github, igor, lovelace, manni, monokailight, murphy, paraiso-light, pastie, perldoc, solarized-light256, solarized-light, tango, trac, vs, xcode. 39 | 40 | _NOTE: Godocc uses the awesome [Chroma](https://github.com/alecthomas/chroma) package underneath._ 41 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | 7 | "github.com/alecthomas/chroma/quick" 8 | colorable "github.com/mattn/go-colorable" 9 | ) 10 | 11 | func main() { 12 | // capture the input, output and args of `go doc`. 13 | args := []string{"doc"} 14 | args = append(args, os.Args[1:]...) 15 | cmd := exec.Command("go", args...) 16 | cmd.Env = os.Environ() 17 | 18 | // ignore the error for now. 19 | // output contains the error as well. 20 | // so the error will be printed eventually. 21 | output, _ := cmd.CombinedOutput() 22 | 23 | // remove the newline first. 24 | // reprint it later on: after turning off the coloring. 25 | if output[len(output)-1] == '\n' { 26 | output = output[:len(output)-1] 27 | } 28 | 29 | // default style is dracula 30 | var style = "dracula" 31 | if v := os.Getenv("GODOCC_STYLE"); v != "" { 32 | style = v 33 | } 34 | 35 | // get a cross-platform bash escape sequences emulator 36 | stdout := colorable.NewColorableStdout() 37 | 38 | // colorize and print the documentation 39 | if err := quick.Highlight(stdout, string(output), "go", "terminal256", style); err != nil { 40 | panic(err) 41 | } 42 | 43 | // turn off the coloring and reprint a newline 44 | stdout.Write([]byte("\033[0m\n")) 45 | } 46 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U= 2 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= 3 | github.com/alecthomas/chroma v0.6.2 h1:aV6n3C/Womqo1zPZ7eyI0viybDslfbgqTUqxMMyCrDM= 4 | github.com/alecthomas/chroma v0.6.2/go.mod h1:quT2EpvJNqkuPi6DmBHB+E33FXBgBBPzyH5++Dn1LPc= 5 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= 6 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= 7 | github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU= 8 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY= 9 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= 10 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= 11 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= 12 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 13 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 14 | github.com/dlclark/regexp2 v1.1.6 h1:CqB4MjHw0MFCDj+PHHjiESmHX+N7t0tJzKvC6M97BRg= 15 | github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= 16 | github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= 17 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 18 | github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o= 19 | github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 20 | github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= 21 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 22 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 23 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 24 | github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= 25 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 26 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= 27 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 28 | golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35 h1:YAFjXN64LMvktoUZH9zgY4lGc/msGN7HQfoSuKCgaDU= 29 | golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 30 | --------------------------------------------------------------------------------