Automatically use the notty style when stdout is no terminal

If the user provided a style flag, this still takes precedence.
This commit is contained in:
Christian Muehlhaeuser 2019-12-06 19:22:34 +01:00
parent 95670866e0
commit de91f6ae53

13
main.go
View file

@ -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)