This repository has been archived on 2021-06-21. You can view files and clone it, but cannot push or open issues/pull-requests.
beaver/color
jolheiser a99fb9facd
Extended and true colors
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2020-10-18 16:47:07 -05:00
..
README.md Update colors (#2) 2020-02-26 20:01:20 +00:00
basic.go Extended and true colors 2020-10-18 16:47:07 -05:00
basic_colors.go Extended and true colors 2020-10-18 16:47:07 -05:00
basic_test.go Extended and true colors 2020-10-18 16:47:07 -05:00
color.go Extended and true colors 2020-10-18 16:47:07 -05:00
color_test.go Extended and true colors 2020-10-18 16:47:07 -05:00
extended.go Extended and true colors 2020-10-18 16:47:07 -05:00
extended_colors.go Extended and true colors 2020-10-18 16:47:07 -05:00
rgb.go Extended and true colors 2020-10-18 16:47:07 -05:00
rgb_test.go Extended and true colors 2020-10-18 16:47:07 -05:00
true.go Extended and true colors 2020-10-18 16:47:07 -05:00

README.md

Color

Beaver comes with the color sub-package that can be used even without Beaver calls.

Formatting a string with a single attribute

text := color.FgRed.Format("red")

Formatting a string with a full color

text := color.New(color.BgGreen, color.FgRed, color.Bold).Format("green background, red text, and bold")

Formatting strings with multiple colors

The following are different ways to print This is a color test! where the word color is red while everything else is green.

setup

Assuming each example is preceded by

green := color.New(color.FgGreen)
red := color.New(color.FgRed)

pure fmt.Println

fmt.Println(green.Format("This is a"), red.Format("color"), green.Format("test!"))

color.Wrap

fmt.Println(green.Wrap("This is a #{color} test!", red))

string formatting with fmt.Printf and color.Wrap

fmt.Printf(green.Wrap("This is a #{%s} test!\n", red), "color")

using a different directive prefix

color.DirectivePrefix('$')
fmt.Printf(green.Wrap("This is a ${%s} test!\n", red), "color")