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

Updates and cosmetic changes.

This commit is contained in:
Fatih Arslan 2014-02-17 01:47:15 -08:00
parent 8653b308b1
commit 823f4ed20f
3 changed files with 28 additions and 28 deletions

View File

@ -13,7 +13,7 @@ go get github.com/fatih/color
## Examples
# Standard colors
### Standard colors
```go
// Print with default foreground colors
@ -25,34 +25,33 @@ color.Green.Add(color.Bold).Println("Green with bold")
color.Red.Add(color.BgWhite, color.Underline).Printf("Red with Black background and underscore: %s\n", "format too!")
```
# Custom colors
### Custom colors
```go
// Create and reuse color objects
c := color.Cyan.Add(color.Underline)
c.Println("Prints bold cyan.")
c.Println("Prints cyan text with an underline.")
c.Printf("Thir prints bold cyan %s\n", "too!.")
// Create custom color objects:
c := color.New(color.FgGreen, color.BgCyan, color.Italic)
c.Print("Italic green with cyan backround")
d := color.New(color.FgWhite, color.BgGreen)
d.Println("White with green backround")
```
# Plug into your existing code
### Plug into your existing code
```go
// Use handy standard colors.
color.Yello.Set()
fmt.Println("Existing text in your codebase will be now in Cyan")
color.Yellow.Set()
fmt.Println("Existing text in your codebase will be now in Yellow")
fmt.Printf("This one %s\n", "too")
color.Unset() // don't forget to unset
// You can use set custom objects too
color.New(color.FgBlack, color.BgWhite, color.Bold).Set()
// You can set custom objects too
color.New(color.FgMagenta, color.Bold).Set()
defer color.Unset() // use it in your function
fmt.Println("All text will be now bold red with white background.")
fmt.Println("All text will be now bold magenta.")
```
## Credits

View File

@ -20,7 +20,7 @@ const (
FgGreen
FgYellow
FgBlue
FgMagent
FgMagenta
FgCyan
FgWhite
)
@ -31,7 +31,7 @@ const (
BgGreen
BgYellow
BgBlue
BgMagent
BgMagenta
BgCyan
BgWhite
)
@ -50,14 +50,14 @@ const (
)
var (
Black = &Color{params: []Parameter{FgBlack}}
Red = &Color{params: []Parameter{FgRed}}
Green = &Color{params: []Parameter{FgGreen}}
Yellow = &Color{params: []Parameter{FgYellow}}
Blue = &Color{params: []Parameter{FgBlue}}
Magent = &Color{params: []Parameter{FgMagent}}
Cyan = &Color{params: []Parameter{FgCyan}}
White = &Color{params: []Parameter{FgWhite}}
Black = &Color{params: []Parameter{FgBlack}}
Red = &Color{params: []Parameter{FgRed}}
Green = &Color{params: []Parameter{FgGreen}}
Yellow = &Color{params: []Parameter{FgYellow}}
Blue = &Color{params: []Parameter{FgBlue}}
Magenta = &Color{params: []Parameter{FgMagenta}}
Cyan = &Color{params: []Parameter{FgCyan}}
White = &Color{params: []Parameter{FgWhite}}
)
func New(value ...Parameter) *Color {

View File

@ -5,6 +5,7 @@ import (
"testing"
)
// The example from the standart library doesn't work unfortunaly.
func TestColor(t *testing.T) {
Cyan.Print("Prints text in cyan.")
Blue.Print("Prints text in blue.")
@ -15,21 +16,21 @@ func TestColor(t *testing.T) {
// Create and reuse color objects
c := Cyan.Add(Underline)
c.Println("Prints bold cyan.")
c.Println("Prints cyan text with an underline.")
c.Printf("Thir prints bold cyan %s\n", "too!.")
// Create custom color objects:
d := New(FgGreen, BgCyan, Italic)
d.Print("Italic green with cyan backround")
d := New(FgWhite, BgGreen)
d.Println("White with green backround")
// You can use set custom objects too
Cyan.Set()
fmt.Println("Existing text in your codebase will be now in Cyan")
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
// You can use set custom objects too
New(FgBlack, BgWhite, Bold).Set()
New(FgMagenta, Bold).Set()
defer Unset() // use it in your function
fmt.Println("All text will be now bold red with white background.")