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
John Olheiser 5e1722bd43 Update colors (#2)
Simplify example

Update colors

Add wrapping

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/beaver/pulls/2
2020-02-26 20:01:20 +00:00
..
README.md Update colors (#2) 2020-02-26 20:01:20 +00:00
attribute.go Update colors (#2) 2020-02-26 20:01:20 +00:00
color.go Update colors (#2) 2020-02-26 20:01:20 +00:00
color_test.go Initial commit 2020-01-29 20:38:15 -06: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")