From de91f6ae537ca40676046b9e5591ef8d6c05838d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 6 Dec 2019 19:22:34 +0100 Subject: [PATCH] Automatically use the notty style when stdout is no terminal If the user provided a style flag, this still takes precedence. --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 6e59fb1..2b8c8a2 100644 --- a/main.go +++ b/main.go @@ -106,12 +106,13 @@ func execute(cmd *cobra.Command, args []string) error { return err } - r := gold.NewPlainTermRenderer() - if isatty.IsTerminal(os.Stdout.Fd()) { - r, err = gold.NewTermRenderer(style) - if err != nil { - return err - } + if !isatty.IsTerminal(os.Stdout.Fd()) && + !cmd.Flags().Changed("style") { + style = "notty" + } + r, err := gold.NewTermRenderer(style) + if err != nil { + return err } r.WordWrap = int(width)