colorful is a lightweight package for rendering colorful text in terminal with Go . You can use this instead of fmt package for having many features. For seeing usages check this.
go get github.com/erfanmomeniii/colorful/v2
Next, include it in your application:
import "github.com/erfanmomeniii/colorful/v2"
The following example demonstrates how to print text in desired format and color:
package main
import (
"github.com/erfanmomeniii/colorful/v2"
)
func main() {
colorful.WithColor(colorful.RedColor).
WithBackgroundColor(colorful.BlueBackgroundColor).
Println("RedColorBlueBackground")
colorful.WithColor(colorful.GreenColor).
Println("GreenColor")
colorful.WithBackgroundColor(colorful.YellowBackgroundColor).
Println("YellowBackground")
}
You can also print many texts with different colors and background colors only in one operation like below:
package main
import (
"github.com/erfanmomeniii/colorful/v2"
)
func main() {
colorful.WithColor(colorful.RedColor).
Print("Hi ").
WithColor(colorful.BlueColor).
Print("Erfan")
}
output:
You can use the following color codes :
You can use the following background codes :
Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.