Skip to content

Instantly share code, notes, and snippets.

@kemokemo
Last active August 7, 2020 04:49
Show Gist options
  • Save kemokemo/b679591791c9e79ce47d60270e09a879 to your computer and use it in GitHub Desktop.
Save kemokemo/b679591791c9e79ce47d60270e09a879 to your computer and use it in GitHub Desktop.
A golang sample with colored terminal output. Cross-platform support, of course.
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
)
var out = colorable.NewColorableStdout()
func main() {
fmt.Println("hoge normal color")
iColor := color.New(color.FgHiGreen)
fI := iColor.FprintFunc()
fI(out, "hoge green color\n")
wColor := color.New(color.FgHiYellow)
fW := wColor.FprintFunc()
fW(out, "hoge yellow color\n")
eColor := color.New(color.FgHiRed)
fE := eColor.FprintFunc()
fE(out, "hoge red color\n")
}
@kemokemo
Copy link
Author

kemokemo commented Aug 7, 2020

git clone https://gist.github.com/kemokemo/b679591791c9e79ce47d60270e09a879 colored-out
cd colored-out
go run colored-out.go

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment