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. ")
|
2014-02-17 12:40:02 +03:00
|
|
|
|
|
|
|
// 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")
|
2014-02-17 12:40:02 +03:00
|
|
|
|
|
|
|
// 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.")
|
2014-02-17 12:40:02 +03:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-02-17 12:40:02 +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")
|
2014-02-17 12:40:02 +03:00
|
|
|
fmt.Printf("This one %s\n", "too")
|
|
|
|
Unset() // don't forget to unset
|
2014-02-17 12:12:32 +03:00
|
|
|
|
2014-02-17 12:40:02 +03:00
|
|
|
// You can use set custom objects too
|
2014-02-17 12:47:15 +03:00
|
|
|
New(FgMagenta, Bold).Set()
|
2014-02-17 12:40:02 +03:00
|
|
|
defer Unset() // use it in your function
|
2014-02-17 12:12:32 +03:00
|
|
|
|
2014-02-17 12:40:02 +03:00
|
|
|
fmt.Println("All text will be now bold red with white background.")
|
2014-02-17 12:12:32 +03:00
|
|
|
|
|
|
|
}
|