Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Options is Pretty options
type Options struct {
// Width is an max column width for single line arrays
// Width is a max column width for single line arrays
// Default is 80
Width int
// Prefix is a prefix for all lines
Expand All @@ -27,7 +27,7 @@ type Options struct {
var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: " ", SortKeys: false}

// Pretty converts the input json into a more human readable format where each
// element is on it's own line with clear indentation.
// element is on its own line with clear indentation.
func Pretty(json []byte) []byte { return PrettyOptions(json, nil) }

// PrettyOptions is like Pretty but with customized options.
Expand Down Expand Up @@ -459,7 +459,7 @@ func init() {
}
}

// Color will colorize the json. The style parma is used for customizing
// Color will colorize the json. The style param is used for customizing
// the colors. Passing nil to the style param will use the default
// TerminalStyle.
func Color(src []byte, style *Style) []byte {
Expand Down
14 changes: 14 additions & 0 deletions pretty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,17 @@ func TestNaN(t *testing.T) {
}
}
}

func TestColorCustomStyle(t *testing.T) {
customStyle := &Style{
Key: [2]string{"<k>", "</k>"},
String: [2]string{"<s>", "</s>"},
Number: [2]string{"<n>", "</n>"},
}
res := Color([]byte(`{"a":1,"b":"c"}`), customStyle)
expected := `{<k>"a"</k>:<n>1</n>,<k>"b"</k>:<s>"c"</s>}`
if string(res) != expected {
t.Fatalf("expected %q, got %q", expected, string(res))
}
}