From 7da2493d6ec6ace74dff0a085ecb74b796d4a6b4 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Tue, 18 Feb 2014 00:38:51 -0800 Subject: Add doc.go to show examples in godoc. --- README.md | 4 ++-- color.go | 7 ++----- doc.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 doc.go diff --git a/README.md b/README.md index 7a5085f..0dddec8 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ color.Magenta("And many others ..") c := color.New(color.FgCyan).Add(color.Underline) c.Println("Prints cyan text with an underline.") -// Another one -d := color.New(color.FgCyan).Add(color.Bold) +// Or just add them to New() +d := color.New(color.FgCyan, color.Bold) d.Printf("This prints bold cyan %s\n", "too!.") diff --git a/color.go b/color.go index d7f9651..87781fa 100644 --- a/color.go +++ b/color.go @@ -1,14 +1,11 @@ -// Package color is an ANSI color package to output colorized or SGR defined -// output to the standard output. package color import ( + "fmt" "io" "os" "strconv" "strings" - - "fmt" ) // Color defines a custom color object which is defined by SGR parameters. @@ -21,7 +18,7 @@ type Parameter int const escape = "\x1b" -// All attributes off +// Base paramaters const ( Reset Parameter = iota Bold diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..0e6da6f --- /dev/null +++ b/doc.go @@ -0,0 +1,57 @@ +/* +Package color is an ANSI color package to output colorized or SGR defined +output to the standard output. The api can be used in several way, pick one +one that suits you. + +Use simple and default helper functions with predefined foreground colors: + + color.Cyan("Prints text in cyan.") + color.Blue("Prints %s in blue.", "text") // a newline will be appended automatically + + // These are using by default foreground colors. + color.Red("We have red") + color.Yellow("Yellow color too!") + color.Magenta("And many others ..") + + +However there are times where custom color mixes are required. Below are some +examples to create custom color objects and use the print functions of each +seperate color object. + + // Create a new color object + c := color.New(color.FgCyan).Add(color.Underline) + c.Println("Prints cyan text with an underline.") + + // Or just add them to New() + d := color.New(color.FgCyan, color.Bold) + d.Printf("This prints bold cyan %s\n", "too!.") + + + // Mix up foreground and background colors, create new mixes! + red := color.New(color.FgRed) + + boldRed := red.Add(color.Bold) + boldRed.Println("This will print text in bold red.") + + whiteBackground := red.Add(color.BgWhite) + whiteBackground.Println("Red text with White background.") + + +Using with existing color is possible too. Just use the Set() method to set +the standart output to the given parameters. That way a rewrite of an existing +code is not required. + + // Use handy standard colors. + color.Set(collor.FgYellow) + 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 mix up parameters + color.Set(color.FgMagenta, color.Bold) + defer color.Unset() // use it in your function + + fmt.Println("All text will be now bold magenta.") +*/ + +package color -- cgit v1.2.3