From 823f4ed20f31e9aebfc545e1f4e2be6677686c44 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Mon, 17 Feb 2014 01:47:15 -0800 Subject: [PATCH] Updates and cosmetic changes. --- README.md | 23 +++++++++++------------ color.go | 20 ++++++++++---------- color_test.go | 13 +++++++------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a2d7809..d5ab69c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/color.go b/color.go index d1a8e45..739f2eb 100644 --- a/color.go +++ b/color.go @@ -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 { diff --git a/color_test.go b/color_test.go index ccca678..cdd023a 100644 --- a/color_test.go +++ b/color_test.go @@ -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.")