Skip to content

Commit

Permalink
fix: Correctly print colored text on Windows
Browse files Browse the repository at this point in the history
This commit will fix #40.

Replacing os.Stdout with color.Output will fix the problem on Windows's console.

Internally, `color.Output` is same as `colorable.NewColorableStdout()`, according to https://github.com/fatih/color/blob/acd5f3bb28257af7d3c4817ab6842e39bd0fcf34/color.go#L25-L27

see also: https://godocs.io/github.com/mattn/go-colorable#NewColorableStdout
  • Loading branch information
gaeulbyul authored and mr-karan committed Jul 13, 2022
1 parent 218eb02 commit 2cf9e7b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/doggo/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func renderCustomHelp() {
// should ideally never happen.
panic(err)
}
err = tmpl.Execute(os.Stdout, helpTmplVars)
err = tmpl.Execute(color.Output, helpTmplVars)
if err != nil {
// should ideally never happen.
panic(err)
Expand Down
3 changes: 1 addition & 2 deletions internal/app/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"encoding/json"
"fmt"
"os"

"github.com/fatih/color"
"github.com/miekg/dns"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (app *App) outputTerminal(rsp []resolvers.Response) {
}

// Conditional Time column.
table := tablewriter.NewWriter(os.Stdout)
table := tablewriter.NewWriter(color.Output)
header := []string{"Name", "Type", "Class", "TTL", "Address", "Nameserver"}
if app.QueryFlags.DisplayTimeTaken {
header = append(header, "Time Taken")
Expand Down

0 comments on commit 2cf9e7b

Please sign in to comment.