Skip to content

Commit

Permalink
Merge pull request #5 from soluble-ai/update-colors
Browse files Browse the repository at this point in the history
Update colors.
  • Loading branch information
slshen authored Jan 6, 2020
2 parents 0b12cb4 + 6d7b9f8 commit 2110494
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 9 additions & 8 deletions colorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 18 additions & 10 deletions colorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Binary file added colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed default_styles.png
Binary file not shown.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2110494

Please sign in to comment.