1
0
mirror of https://github.com/fatih/color.git synced 2024-11-24 08:02:14 +02:00
color/color_test.go

58 lines
1.4 KiB
Go
Raw Normal View History

2014-02-17 12:12:32 +03:00
package color
import (
"fmt"
"testing"
)
2014-02-17 12:47:15 +03:00
// The example from the standart library doesn't work unfortunaly.
2014-02-17 12:12:32 +03:00
func TestColor(t *testing.T) {
2014-02-17 12:58:08 +03:00
fmt.Printf("black")
New(BgBlack).Println(" ")
fmt.Printf("red\t")
New(BgRed).Println(" ")
fmt.Printf("green\t")
New(BgGreen).Println(" ")
fmt.Printf("yellow\t")
New(BgYellow).Println(" ")
fmt.Printf("blue\t")
New(BgBlue).Println(" ")
fmt.Printf("magenta\t")
New(BgMagenta).Println(" ")
fmt.Printf("cyan\t")
New(BgCyan).Println(" ")
fmt.Printf("white\t")
New(BgWhite).Println(" ")
fmt.Println("")
Cyan.Print("Prints text in cyan. ")
Blue.Print("Prints text in blue. ")
// Chain SGR paramaters
Green.Add(Bold).Println("Green with bold")
2014-02-17 12:58:08 +03:00
Red.Add(BgWhite, Underline).Println("Red with White background and underscore")
// Create and reuse color objects
2014-02-17 12:58:08 +03:00
c := Red.Add(Underline)
fmt.Println(c.params)
2014-02-17 12:47:15 +03:00
c.Println("Prints cyan text with an underline.")
// Create custom color objects:
2014-02-17 12:47:15 +03:00
d := New(FgWhite, BgGreen)
d.Println("White with green backround")
2014-02-17 12:12:32 +03:00
// You can use set custom objects too
2014-02-17 12:47:15 +03:00
Yellow.Set()
fmt.Println("Existing text in your codebase will be now in Yellow")
fmt.Printf("This one %s\n", "too")
Unset() // don't forget to unset
2014-02-17 12:12:32 +03:00
// You can use set custom objects too
2014-02-17 12:47:15 +03:00
New(FgMagenta, Bold).Set()
defer Unset() // use it in your function
2014-02-17 12:12:32 +03:00
fmt.Println("All text will be now bold red with white background.")
2014-02-17 12:12:32 +03:00
}