update dependencies

This commit is contained in:
Cory Bennett
2017-09-06 11:35:00 -07:00
parent 9453179251
commit aa876cd588
308 changed files with 46154 additions and 33733 deletions
+15 -13
View File
@@ -4,10 +4,10 @@ Package ansi is a small, fast library to create ANSI colored strings and codes.
## Install
This install the color viewer and the package itself
Get it
```sh
go get -u github.com/mgutz/ansi/cmd/ansi-mgutz
go get -u github.com/mgutz/ansi
```
## Example
@@ -18,7 +18,7 @@ import "github.com/mgutz/ansi"
// colorize a string, SLOW
msg := ansi.Color("foo", "red+b:white")
// create a closure to avoid recalculating ANSI code compilation
// create a FAST closure function to avoid computation of ANSI code
phosphorize := ansi.ColorFunc("green+h:black")
msg = phosphorize("Bring back the 80s!")
msg2 := phospohorize("Look, I'm a CRT!")
@@ -44,10 +44,10 @@ Color(s, "red+B:white+h") // red blink on white bright
Color(s, "off") // turn off ansi codes
```
To view color combinations, from terminal.
To view color combinations, from project directory in terminal.
```sh
ansi-mgutz
go test
```
## Style format
@@ -68,15 +68,18 @@ Colors
* white
* 0...255 (256 colors)
Attributes
Foreground Attributes
* b = bold foreground
* B = Blink foreground
* u = underline foreground
* i = inverse
* h = high intensity (bright) foreground, background
* B = Blink
* b = bold
* h = high intensity (bright)
* i = inverse
* s = strikethrough
* u = underline
does not work with 256 colors
Background Attributes
* h = high intensity (bright)
## Constants
@@ -100,7 +103,6 @@ Attributes
* ansi.LightCyan
* ansi.LightWhite
## References
Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
+46 -7
View File
@@ -23,11 +23,12 @@ const (
normalIntensityBG = 40
highIntensityBG = 100
start = "\033["
bold = "1;"
blink = "5;"
underline = "4;"
inverse = "7;"
start = "\033["
bold = "1;"
blink = "5;"
underline = "4;"
inverse = "7;"
strikethrough = "9;"
// Reset is the ANSI reset escape sequence
Reset = "\033[0m"
@@ -176,6 +177,9 @@ func colorCode(style string) *bytes.Buffer {
if strings.Contains(fgStyle, "i") {
buf.WriteString(inverse)
}
if strings.Contains(fgStyle, "s") {
buf.WriteString(strikethrough)
}
if strings.Contains(fgStyle, "h") {
base = highIntensityFG
}
@@ -220,7 +224,7 @@ func Color(s, style string) string {
return buf.String()
}
// ColorFunc creates a closureto avoid ANSI color code calculation.
// ColorFunc creates a closure to avoid computation ANSI color code.
func ColorFunc(style string) func(string) string {
if style == "" {
return func(s string) string {
@@ -240,7 +244,42 @@ func ColorFunc(style string) func(string) string {
}
}
// DisableColors disables ANSI color codes. On by default.
// DisableColors disables ANSI color codes. The default is false (colors are on).
func DisableColors(disable bool) {
plain = disable
if plain {
Black = ""
Red = ""
Green = ""
Yellow = ""
Blue = ""
Magenta = ""
Cyan = ""
White = ""
LightBlack = ""
LightRed = ""
LightGreen = ""
LightYellow = ""
LightBlue = ""
LightMagenta = ""
LightCyan = ""
LightWhite = ""
} else {
Black = ColorCode("black")
Red = ColorCode("red")
Green = ColorCode("green")
Yellow = ColorCode("yellow")
Blue = ColorCode("blue")
Magenta = ColorCode("magenta")
Cyan = ColorCode("cyan")
White = ColorCode("white")
LightBlack = ColorCode("black+h")
LightRed = ColorCode("red+h")
LightGreen = ColorCode("green+h")
LightYellow = ColorCode("yellow+h")
LightBlue = ColorCode("blue+h")
LightMagenta = ColorCode("magenta+h")
LightCyan = ColorCode("cyan+h")
LightWhite = ColorCode("white+h")
}
}
+34 -24
View File
@@ -1,42 +1,52 @@
package ansi
import (
"fmt"
"strings"
"testing"
)
func TestPlain(t *testing.T) {
DisableColors(true)
bgColors := []string{
"",
":black",
":red",
":green",
":yellow",
":blue",
":magenta",
":cyan",
":white",
}
for fg := range Colors {
for _, bg := range bgColors {
println(padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg}))
println(padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"}))
println(padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"}))
}
}
PrintStyles()
}
func TestStyles(t *testing.T) {
PrintStyles()
DisableColors(false)
PrintStyles()
}
func TestDisableColors(t *testing.T) {
fn := ColorFunc("red")
buf := colorCode("off")
if buf.String() != "" {
t.Fail()
}
}
func ExampleColorFunc() {
brightGreen := ColorFunc("green+h")
fmt.Println(brightGreen("lime"))
DisableColors(true)
if Black != "" {
t.Fail()
}
code := ColorCode("red")
if code != "" {
t.Fail()
}
s := fn("foo")
if s != "foo" {
t.Fail()
}
DisableColors(false)
if Black == "" {
t.Fail()
}
code = ColorCode("red")
if code == "" {
t.Fail()
}
// will have escape codes around it
index := strings.Index(fn("foo"), "foo")
if index <= 0 {
t.Fail()
}
}
+2 -2
View File
@@ -80,7 +80,7 @@ func printColors() {
for _, fg := range keys {
for _, bg := range bgColors {
fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"}))
fmt.Fprintln(stdout, padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h", "+s" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"}))
}
}
@@ -108,7 +108,7 @@ func print256Colors() {
for _, fg := range keys {
for _, bg := range bgColors {
fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+u" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+B" + bg, "+Bb" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+B" + bg, "+Bb" + bg, "+s" + bg}))
}
}
}
+24 -9
View File
@@ -1,9 +1,16 @@
package ansi
import (
"fmt"
"sort"
colorable "github.com/mattn/go-colorable"
)
// PrintStyles prints all style combinations to the terminal.
func PrintStyles() {
oldPlain := plain
plain = false
// for compatibility with Windows, not needed for *nix
stdout := colorable.NewColorableStdout()
bgColors := []string{
"",
@@ -16,14 +23,22 @@ func PrintStyles() {
":cyan",
":white",
}
for fg := range Colors {
keys := make([]string, 0, len(Colors))
for k := range Colors {
keys = append(keys, k)
}
sort.Sort(sort.StringSlice(keys))
for _, fg := range keys {
for _, bg := range bgColors {
println(padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg}))
println(padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"}))
println(padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"}))
fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+s" + bg, "+i" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"}))
fmt.Fprintln(stdout, padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"}))
}
}
plain = oldPlain
}
func pad(s string, length int) string {
@@ -33,10 +48,10 @@ func pad(s string, length int) string {
return s
}
func padColor(s string, styles []string) string {
func padColor(color string, styles []string) string {
buffer := ""
for _, style := range styles {
buffer += Color(pad(s+style, 20), s+style)
buffer += Color(pad(color+style, 20), color+style)
}
return buffer
}