-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
40 lines (30 loc) · 1.22 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package color_test
import (
"fmt"
"github.com/x-ethr/color"
)
func Example() {
color.Unset() // forcefully unset the package [atomic.Value] so example tests can pass
// --> Write the content "Default" out to stdout without color
color.Color().Default("Default").Print()
// --> Write the content "red", "blue", "green" out to stdout with color escapes
color.Color().Red("Red").Print()
color.Color().Blue("Blue").Print()
color.Color().Green("Green").Print()
// --> Wrap color(s) with bold color escapes and write to stdout
color.Color().Bold(color.Color().Cyan("Cyan")).Print()
// --> Customize how newlines and spaces are added to the formatted output
color.Color().Red("Color-1").Print(func(o *color.Options) { o.Line = false; o.Space = true })
color.Color().Red("Color-2").Print(func(o *color.Options) { o.Line = false; o.Space = true })
color.Color().Red("Color-3").Print()
// --> Store the ANSI-modified string to a variable and then format, write the value to stdout
v := color.Color().Italic(color.Color().Magenta("Magenta")).String()
fmt.Printf("Example Magenta Color Output: %s\n", v)
// Output: Default
// Red
// Blue
// Green
// Cyan
// Color-1 Color-2 Color-3
// Example Magenta Color Output: Magenta
}