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:
parent
05210eb369
commit
99c00de6f8
12
README.md
12
README.md
@ -65,6 +65,18 @@ notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
|
|||||||
notice("don't forget this...")
|
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
|
### Plug into existing code
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -107,7 +107,7 @@ func TestColor(t *testing.T) {
|
|||||||
put := New(FgYellow).SprintFunc()
|
put := New(FgYellow).SprintFunc()
|
||||||
warn := New(FgRed).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()
|
info := New(FgWhite, BgGreen).SprintFunc()
|
||||||
fmt.Printf("this %s rocks!\n", info("package"))
|
fmt.Printf("this %s rocks!\n", info("package"))
|
||||||
|
16
doc.go
16
doc.go
@ -15,7 +15,6 @@ Use simple and default helper functions with predefined foreground colors:
|
|||||||
color.Yellow("Yellow color too!")
|
color.Yellow("Yellow color too!")
|
||||||
color.Magenta("And many others ..")
|
color.Magenta("And many others ..")
|
||||||
|
|
||||||
|
|
||||||
However there are times where custom color mixes are required. Below are some
|
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
|
examples to create custom color objects and use the print functions of each
|
||||||
separate color object.
|
separate color object.
|
||||||
@ -51,8 +50,19 @@ You can create PrintXxx functions to simplify even more:
|
|||||||
notice("don't forget this...")
|
notice("don't forget this...")
|
||||||
|
|
||||||
|
|
||||||
Using with existing color is possible too. Just use the Set() method to set
|
Or create SprintXxx functions to mix strings with other non-colorized strings:
|
||||||
the standard output to the given parameters. That way a rewrite of an existing
|
|
||||||
|
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.
|
code is not required.
|
||||||
|
|
||||||
// Use handy standard colors.
|
// Use handy standard colors.
|
||||||
|
Loading…
Reference in New Issue
Block a user