|
Packit Service |
509fd4 |
# Color
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
Style terminal text.
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
## Installation
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```sh
|
|
Packit Service |
509fd4 |
go get github.com/labstack/gommon/color
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
## Windows?
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
Try [cmder](http://bliker.github.io/cmder) or https://github.com/mattn/go-colorable
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
## [Usage](https://github.com/labstack/gommon/blob/master/color/color_test.go)
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```sh
|
|
Packit Service |
509fd4 |
import github.com/labstack/gommon/color
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### Colored text
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
color.Println(color.Black("black"))
|
|
Packit Service |
509fd4 |
color.Println(color.Red("red"))
|
|
Packit Service |
509fd4 |
color.Println(color.Green("green"))
|
|
Packit Service |
509fd4 |
color.Println(color.Yellow("yellow"))
|
|
Packit Service |
509fd4 |
color.Println(color.Blue("blue"))
|
|
Packit Service |
509fd4 |
color.Println(color.Magenta("magenta"))
|
|
Packit Service |
509fd4 |
color.Println(color.Cyan("cyan"))
|
|
Packit Service |
509fd4 |
color.Println(color.White("white"))
|
|
Packit Service |
509fd4 |
color.Println(color.Grey("grey"))
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
![Colored Text](http://i.imgur.com/8RtY1QR.png)
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### Colored background
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
color.Println(color.BlackBg("black background", color.Wht))
|
|
Packit Service |
509fd4 |
color.Println(color.RedBg("red background"))
|
|
Packit Service |
509fd4 |
color.Println(color.GreenBg("green background"))
|
|
Packit Service |
509fd4 |
color.Println(color.YellowBg("yellow background"))
|
|
Packit Service |
509fd4 |
color.Println(color.BlueBg("blue background"))
|
|
Packit Service |
509fd4 |
color.Println(color.MagentaBg("magenta background"))
|
|
Packit Service |
509fd4 |
color.Println(color.CyanBg("cyan background"))
|
|
Packit Service |
509fd4 |
color.Println(color.WhiteBg("white background"))
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
![Colored Background](http://i.imgur.com/SrrS6lw.png)
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### Emphasis
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
color.Println(color.Bold("bold"))
|
|
Packit Service |
509fd4 |
color.Println(color.Dim("dim"))
|
|
Packit Service |
509fd4 |
color.Println(color.Italic("italic"))
|
|
Packit Service |
509fd4 |
color.Println(color.Underline("underline"))
|
|
Packit Service |
509fd4 |
color.Println(color.Inverse("inverse"))
|
|
Packit Service |
509fd4 |
color.Println(color.Hidden("hidden"))
|
|
Packit Service |
509fd4 |
color.Println(color.Strikeout("strikeout"))
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
![Emphasis](http://i.imgur.com/3RSJBbc.png)
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### Mix and match
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
color.Println(color.Green("bold green with white background", color.B, color.WhtBg))
|
|
Packit Service |
509fd4 |
color.Println(color.Red("underline red", color.U))
|
|
Packit Service |
509fd4 |
color.Println(color.Yellow("dim yellow", color.D))
|
|
Packit Service |
509fd4 |
color.Println(color.Cyan("inverse cyan", color.In))
|
|
Packit Service |
509fd4 |
color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D))
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
![Mix and match](http://i.imgur.com/jWGq9Ca.png)
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### Enable/Disable the package
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
color.Disable()
|
|
Packit Service |
509fd4 |
color.Enable()
|
|
Packit Service |
509fd4 |
```
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
### New instance
|
|
Packit Service |
509fd4 |
|
|
Packit Service |
509fd4 |
```go
|
|
Packit Service |
509fd4 |
c := New()
|
|
Packit Service |
509fd4 |
c.Green("green")
|
|
Packit Service |
509fd4 |
```
|