You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the color pack to colorize the output in the terminal with custom formatters or create custom colors with RGB and ANSI 256 index.
All formatters are parsed as ANSI Escape Code.
Install
$ go get github.com/bedirhandogan/color
Uses
Single Colorize
// Print all text in one colorfmt.Println(color.String("&Red Print this text in color."))
// Print all text in one color, specifying tonefmt.Println(color.String("&Magenta80 Print this text in magenta 80 shades."))
// Color and print the background of all text by adding bg in front of itfmt.Println(color.String("&BgCyan Color this text with a cyan background and print it."))
fmt.Println(color.String("&BgYellow50 Color this text with a yellow 50 shades background and print it"))
Multiple Colorize
// Print all text with multiple colorsfmt.Println(color.String("&Blue Print this text with &Green multiple colors."))
// Print all text with multiple color, specifying tonefmt.Println(color.String("&Blue70 Print this text with &Green20 multiple colors."))
// Print all text with multiple background colorfmt.Println(color.String("&BgYellow20 Print this text with &BgBlue multiple background colors."))
// Normalize textfmt.Println(color.String("&Blue Print this text in color with reset. &Reset"))
// Bold textfmt.Println(color.String("&Bold &Yellow80 Print this text in color with bold."))
fmt.Println(color.String("&Bold Print this text in bold."))
// Italic textfmt.Println(color.String("&Italic &Cyan50 Print this text in color with italicized."))
fmt.Println(color.String("&Italic Print this text in italicized."))
// You can also format as Blink, Underline, Overline, Invert & Strike.
Native Formatters
// This way you can still use native formattersfmt.Printf(color.String("&Cyan Print this text with &s"), "native formatter")
Create New Color
// Create and use new solid color with ANSI 256 indexcolor.RegisterAnsi("FaintRed", 124)
fmt.Println(color.String("&FaintRed Print this text faint red color."))
// Create and use new background color with ANSI 256 indexcolor.RegisterAnsi("BgFaintRed", 124)
fmt.Println(color.String("&BgFaintRed Print this text faint red background color."))
// Create and use new solid color with RGBcolor.RegisterRgb("LightRed", 255, 192, 203)
fmt.Println(color.String("&FaintRed Print this text light red color."))
// Create and use new background color with RGBcolor.RegisterRgb("BgLightRed", 255, 192, 203)
fmt.Println(color.String("&BgFaintRed Print this text light red background color."))