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

Add documentation about Sprint functions.

This commit is contained in:
Fatih Arslan 2014-02-18 03:26:43 -08:00
parent 05210eb369
commit 99c00de6f8
3 changed files with 26 additions and 4 deletions

View File

@ -65,6 +65,18 @@ notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
notice("don't forget this...")
```
### Insert into noncolor strings
```go
// Create SprintXxx functions to mix strings with other non-colorized strings:
yellow := New(FgYellow).SprintFunc()
red := New(FgRed).SprintFunc()
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error"))
info := New(FgWhite, BgGreen).SprintFunc()
fmt.Printf("this %s rocks!\n", info("package"))
```
### Plug into existing code
```go

View File

@ -107,7 +107,7 @@ func TestColor(t *testing.T) {
put := New(FgYellow).SprintFunc()
warn := New(FgRed).SprintFunc()
fmt.Printf("this is a %s and this is %s. Aborting\n", put("warning"), warn("error"))
fmt.Printf("this is a %s and this is %s.\n", put("warning"), warn("error"))
info := New(FgWhite, BgGreen).SprintFunc()
fmt.Printf("this %s rocks!\n", info("package"))

16
doc.go
View File

@ -15,7 +15,6 @@ Use simple and default helper functions with predefined foreground colors:
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
separate color object.
@ -51,8 +50,19 @@ You can create PrintXxx functions to simplify even more:
notice("don't forget this...")
Using with existing color is possible too. Just use the Set() method to set
the standard output to the given parameters. That way a rewrite of an existing
Or create SprintXxx functions to mix strings with other non-colorized strings:
yellow := New(FgYellow).SprintFunc()
red := New(FgRed).SprintFunc()
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error"))
info := New(FgWhite, BgGreen).SprintFunc()
fmt.Printf("this %s rocks!\n", info("package"))
Using with existing code is possible. Just use the Set() method to set the
standard output to the given parameters. That way a rewrite of an existing
code is not required.
// Use handy standard colors.