From 2cf9e7bf2ce445632b68aa47d6e2e5aacea7afc1 Mon Sep 17 00:00:00 2001 From: Gaeulbyul Date: Wed, 13 Jul 2022 20:09:27 +0900 Subject: [PATCH] fix: Correctly print colored text on Windows 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 --- cmd/doggo/help.go | 2 +- internal/app/output.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/doggo/help.go b/cmd/doggo/help.go index c714b7a..abd3f98 100644 --- a/cmd/doggo/help.go +++ b/cmd/doggo/help.go @@ -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) diff --git a/internal/app/output.go b/internal/app/output.go index 1c3415a..6ea0413 100644 --- a/internal/app/output.go +++ b/internal/app/output.go @@ -3,7 +3,6 @@ package app import ( "encoding/json" "fmt" - "os" "github.com/fatih/color" "github.com/miekg/dns" @@ -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")