Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiline option to Pretty.ColorizeJSON #484

Merged
merged 5 commits into from
Sep 21, 2018
Merged
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
4 changes: 2 additions & 2 deletions commands/service_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ loop:
case e := <-listenEventsC:
fmt.Printf("Receive event %s: %s\n",
pretty.Success(e.EventKey),
pretty.ColorizeJSON(pretty.FgCyan, nil, []byte(e.EventData)),
pretty.ColorizeJSON(pretty.FgCyan, nil, false, []byte(e.EventData)),
)
case err := <-eventsErrC:
fmt.Fprintf(os.Stderr, "%s Listening events error: %s", pretty.FailSign, err)
case r := <-listenResultsC:
fmt.Printf("Receive result %s %s: %s\n",
pretty.Success(r.TaskKey),
pretty.Colorize(color.New(color.FgCyan), r.OutputKey),
pretty.ColorizeJSON(pretty.FgCyan, nil, []byte(r.OutputData)),
pretty.ColorizeJSON(pretty.FgCyan, nil, false, []byte(r.OutputData)),
)
case err := <-resultsErrC:
fmt.Fprintf(os.Stderr, "%s Listening results error: %s", pretty.FailSign, err)
Expand Down
12 changes: 7 additions & 5 deletions utils/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,16 @@ func (p *Pretty) Colorize(c *color.Color, msg string) string {

// ColorizeJSON colors keys and values of stringified JSON. On errors the original string is returned.
// If color is nil then key/value won't be colorize.
func (p *Pretty) ColorizeJSON(keyColor *color.Color, valueColor *color.Color, data []byte) []byte {
func (p *Pretty) ColorizeJSON(keyColor *color.Color, valueColor *color.Color, multiline bool, data []byte) []byte {
if p.noColor {
return data
}

f := prettyjson.NewFormatter()
f.Indent = 0
f.Newline = ""
if !multiline {
f.Indent = 0
f.Newline = ""
}

f.KeyColor = keyColor
f.StringColor = valueColor
Expand Down Expand Up @@ -358,8 +360,8 @@ func Progress(message string, fn func()) { pg.Progress(message, fn) }

// ColorizeJSON colors keys and values of stringified JSON. On errors the original string is returned.
// If color is nil then key/value won't be colorize.
func ColorizeJSON(keyColor *color.Color, valueColor *color.Color, data []byte) []byte {
return pg.ColorizeJSON(keyColor, valueColor, data)
func ColorizeJSON(keyColor *color.Color, valueColor *color.Color, multiline bool, data []byte) []byte {
return pg.ColorizeJSON(keyColor, valueColor, multiline, data)
}

// FgColors returns a slice with predefiend foreground color.
Expand Down