diff --git a/main.go b/main.go index 6915dae6..703d67a9 100644 --- a/main.go +++ b/main.go @@ -156,6 +156,7 @@ func validateStyle(style string) error { func validateOptions(cmd *cobra.Command) error { // grab config values from Viper + width_in_config := viper.InConfig("width") width = viper.GetUint("width") mouse = viper.GetBool("mouse") pager = viper.GetBool("pager") @@ -177,18 +178,24 @@ func validateOptions(cmd *cobra.Command) error { // Detect terminal width if !cmd.Flags().Changed("width") { - if isTerminal && width == 0 { - w, _, err := term.GetSize(int(os.Stdout.Fd())) + w := -1 + if isTerminal { + var err error + w, _, err = term.GetSize(int(os.Stdout.Fd())) if err == nil { - width = uint(w) - } - - if width > 120 { - width = 120 + if w > 120 { + w = 120 + } + } else { + w = -1 } } - if width == 0 { - width = 80 + if w == -1 { + if !width_in_config { + width = 80 + } + } else { + width = uint(w) } } return nil