diff options
| author | Fatih Arslan <ftharsln@gmail.com> | 2014-02-18 08:38:51 +0000 |
|---|---|---|
| committer | Fatih Arslan <ftharsln@gmail.com> | 2014-02-18 08:38:51 +0000 |
| commit | 7da2493d6ec6ace74dff0a085ecb74b796d4a6b4 (patch) | |
| tree | caaee5fd84f740d310f95acd986c8deb841bfa3c | |
| parent | 74148fd1e2b359b140e6f34e496be0f7f7795ecf (diff) | |
| download | colour-7da2493d6ec6ace74dff0a085ecb74b796d4a6b4.tar.gz colour-7da2493d6ec6ace74dff0a085ecb74b796d4a6b4.tar.bz2 | |
Add doc.go to show examples in godoc.
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | color.go | 7 | ||||
| -rw-r--r-- | doc.go | 57 |
3 files changed, 61 insertions, 7 deletions
@@ -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!.") @@ -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 @@ -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 |
