Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
neilotoole committed Oct 4, 2021
1 parent a8b485b commit 5c83331
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
Package `neilotoole/jsoncolor` is a drop-in replacement for `encoding/json`
that outputs colorized JSON.

Why? Well, `jq` colorizes its output by default. And at the time this package was
created, I was not aware of any other JSON colorization package that performed
Why? Well, `jq` colorizes its output by default, and color output is desirable for
many Go CLIs. At the time this package was
created, there didn't seem to be any JSON colorization package that performed
colorization inline in the encoder.

From the example [`jc`](./cmd/jc) app:
Expand Down Expand Up @@ -90,16 +91,16 @@ similar to `jq`:
// These colors largely follow jq's default colorization,
// with some deviation.
func DefaultColors() *Colors {
return &Colors{
Null: Color("\x1b[2m"),
Bool: Color("\x1b[1m"),
Number: Color("\x1b[36m"),
String: Color("\x1b[32m"),
Key: Color("\x1b[34;1m"),
Bytes: Color("\x1b[2m"),
Time: Color("\x1b[32;2m"),
Punc: Color{}, // No colorization
}
return &Colors{
Null: Color("\x1b[2m"),
Bool: Color("\x1b[1m"),
Number: Color("\x1b[36m"),
String: Color("\x1b[32m"),
Key: Color("\x1b[34;1m"),
Bytes: Color("\x1b[2m"),
Time: Color("\x1b[32;2m"),
Punc: Color{}, // No colorization
}
}
```

Expand All @@ -114,18 +115,18 @@ A helper package provides an adapter for [`fatih/color`](https://github.com/fati

```go
// import "github.com/neilotoole/jsoncolor/helper/fatihcolor"
// import "github.com/fatih/color"

out := colorable.NewColorable(os.Stdout) // needed for Windows
enc = json.NewEncoder(out)

fclrs := fatihcolor.DefaultColors()
// Change some values, just for fun
fclrs.Number = color.New(color.FgBlue)
fclrs.String = color.New(color.FgCyan)
clrs := fatihcolor.ToCoreColors(fclrs)
enc.SetColors(clrs)
// import "github.com/fatih/color"

out := colorable.NewColorable(os.Stdout) // needed for Windows
enc = json.NewEncoder(out)

fclrs := fatihcolor.DefaultColors()
// Change some values, just for fun
fclrs.Number = color.New(color.FgBlue)
fclrs.String = color.New(color.FgCyan)

clrs := fatihcolor.ToCoreColors(fclrs)
enc.SetColors(clrs)
```

### Drop-in for `encoding/json`
Expand Down

0 comments on commit 5c83331

Please sign in to comment.