Skip to content

Commit

Permalink
fixed broken color output on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado committed Nov 13, 2017
1 parent 7205a4b commit c60f2d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/main/color_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ package main

import (
"fmt"
"io"
"os"

"github.com/fatih/color"
"github.com/mattn/go-colorable"
)

const (
Expand Down Expand Up @@ -45,6 +48,12 @@ func (s ColorPrinter) GetFuncMap() map[string]interface{} {
"KeyColor": s.Key}
}

// NewColorableWriter returns a colorable writer for the given file (e.g
// os.Stdout). Needed for on windows platform.
func NewColorableWriter(file *os.File) io.Writer {
return colorable.NewColorable(file)
}

// NewColorPrinter returns a ColorPrinter used to color the console
// output. If noColor is set to true, a no-op color printer is returned.
func NewColorPrinter(noColor bool) ColorPrinter {
Expand Down
4 changes: 2 additions & 2 deletions app/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func startInfoMode(rootNode string, client *rabtap.RabbitHTTPClient,
brokerInfo, err := NewBrokerInfo(client)
failOnError(err, "failed retrieving info from rabbitmq REST api", os.Exit)
brokerInfoPrinter := NewBrokerInfoPrinter(printBrokerInfoConfig)
brokerInfoPrinter.Print(brokerInfo, rootNode, os.Stdout)
brokerInfoPrinter.Print(brokerInfo, rootNode, NewColorableWriter(os.Stdout))
}

// piblishMessage publishes a message on the given exchange with the provided
Expand Down Expand Up @@ -264,7 +264,7 @@ func main() {
signalChannel := make(chan os.Signal, 1)
// messageReceiveFunc receives the tapped messages, prints
// and optionally saves them.
messageReceiveFunc := createMessageReceiveFunc(os.Stdout,
messageReceiveFunc := createMessageReceiveFunc(NewColorableWriter(os.Stdout),
args.JSONFormat, args.SaveDir, args.NoColor)
startTapMode(args.TapConfig, args.InsecureTLS, messageReceiveFunc, signalChannel)

Expand Down

0 comments on commit c60f2d7

Please sign in to comment.