diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md index acf019e..4d07505 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,25 @@ [![GoDoc](https://godoc.org/github.com/soluble-ai/go-colorize?status.svg)](https://godoc.org/github.com/soluble-ai/go-colorize) [![Go Report Card](https://goreportcard.com/badge/github.com/soluble-ai/go-colorize)](https://goreportcard.com/report/github.com/soluble-ai/go-colorize) +With: + +```go +$ go get github.com/soluble-ai/go-colorize +``` + Go from this: ```go -Colorize("\n{primary:%s} eat {bg-success:pizza :pizza:}{bg-primary: and drink }{warning:beer} %s, but not {bg-danger:%s}\n\n", - "Most folks like to", ":beer:", "everyone") + Colorize("{info:[INFO]} {secondary:%s} {primary:%s}\n", + time.Now().Format(time.RFC3339), "hello, world") ``` To this: ![Screenshot](screenshot.png) -Works with https://github.com/kyokomi/emoji and https://github.com/fatih/color. +Default colors are: -Default styles are: +![Colors](colors.png) -![Default Styles](default_styles.png) +Works with https://github.com/kyokomi/emoji and https://github.com/fatih/color. diff --git a/colorize.go b/colorize.go index 1cbff53..adbb4f6 100644 --- a/colorize.go +++ b/colorize.go @@ -64,17 +64,18 @@ func NewStyle(attributes ...color.Attribute) *Style { // Styles maps style names to styles var Styles = map[string]*Style{ - "primary": NewStyle(color.FgBlue), - "secondary": NewStyle(color.FgMagenta), - "light": NewStyle(color.BgHiBlack), - "info": nil, + "primary": NewStyle(color.FgCyan, color.Bold), + "bg-primary": NewStyle(color.FgHiWhite, color.BgCyan), + "secondary": NewStyle(color.FgHiBlack, color.Bold), + "bg-secondary": NewStyle(color.FgHiWhite, color.BgHiBlack), + "light": NewStyle(color.FgHiBlack), + "info": NewStyle(color.FgBlue, color.Bold), + "bg-info": NewStyle(color.FgWhite, color.BgBlue), "success": NewStyle(color.FgGreen), - "warning": NewStyle(color.FgYellow), - "danger": NewStyle(color.FgHiRed), - "bg-primary": NewStyle(color.FgHiWhite, color.BgBlue), - "bg-secondary": NewStyle(color.FgHiWhite, color.BgMagenta), "bg-success": NewStyle(color.FgHiWhite, color.BgGreen), + "warning": NewStyle(color.FgYellow), "bg-warning": NewStyle(color.FgBlack, color.BgYellow), + "danger": NewStyle(color.FgHiRed), "bg-danger": NewStyle(color.FgBlack, color.BgHiRed), } var reset = NewStyle(color.Reset) diff --git a/colorize_test.go b/colorize_test.go index 0ddd352..63423ce 100644 --- a/colorize_test.go +++ b/colorize_test.go @@ -16,28 +16,36 @@ package colorize import ( "fmt" - "github.com/fatih/color" - "sort" "strings" "testing" + "time" + + "github.com/fatih/color" ) func TestDemoDefaults(t *testing.T) { - t.SkipNow() + //t.SkipNow() var template strings.Builder params := make([]interface{}, 0, len(Styles)) - names := make([]string, 0, len(Styles)) - for k := range Styles { - names = append(names, k) + names := []string{ + "primary", "secondary", "info", "light", "success", "warning", "danger", } - sort.Strings(names) for _, k := range names { - template.WriteString(fmt.Sprintf("{%s: %%12s }\n", k)) + template.WriteString(fmt.Sprintf("{%s: %%12s } ", k)) params = append(params, k) + k = "bg-" + k + if _, ok := Styles[k]; ok { + template.WriteString(fmt.Sprintf("{%s: %%12s }", k)) + params = append(params, k) + } + template.WriteString("\n") } + fmt.Println() Colorize(template.String(), params...) - Colorize("\n{primary:%s} eat {bg-success:pizza :pizza:}{bg-primary: and drink }{warning:beer} %s, but not {bg-danger:%s}\n\n", - "Most folks like to", ":beer:", "everyone") + fmt.Println() + Colorize("{info:[INFO]} {secondary:%s} {primary:%s}\n", + time.Now().Format(time.RFC3339), "hello, world") + fmt.Println() } func TestBasic(t *testing.T) { diff --git a/colors.png b/colors.png new file mode 100644 index 0000000..b5d3efc Binary files /dev/null and b/colors.png differ diff --git a/default_styles.png b/default_styles.png deleted file mode 100644 index 4cdcfa8..0000000 Binary files a/default_styles.png and /dev/null differ diff --git a/go.sum b/go.sum index 15f1067..d8d38b5 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY= github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/kyokomi/emoji v2.1.0+incompatible h1:+DYU2RgpI6OHG4oQkM5KlqD3Wd3UPEsX8jamTo1Mp6o= diff --git a/screenshot.png b/screenshot.png index 799a353..76fc06c 100644 Binary files a/screenshot.png and b/screenshot.png differ