From d008b82eab12c69452f2ddc24c739dfc57397fd5 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Sat, 21 Dec 2024 03:01:08 +0100 Subject: [PATCH] fix: adjust validateOptions to handle preconfigured width fixes #666 Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- main.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 6915dae6..13955a4b 100644 --- a/main.go +++ b/main.go @@ -175,22 +175,26 @@ func validateOptions(cmd *cobra.Command) error { style = "notty" } - // Detect terminal width - if !cmd.Flags().Changed("width") { - if isTerminal && width == 0 { - w, _, err := term.GetSize(int(os.Stdout.Fd())) - if err == nil { - width = uint(w) - } + // Determining width - if width > 120 { - width = 120 - } - } - if width == 0 { - width = 80 + // accept the value of width if it comes from commandline + if cmd.Flags().Changed("width") { + return nil + } + // trying to set width to terminal width + if isTerminal { + w, _, err := term.GetSize(int(os.Stdout.Fd())) + if err == nil { + width = uint(min(w, 120)) + return nil } } + // accept the value of width if it comes from config + if viper.InConfig("width") { + return nil + } + // fall back to a hard-coded sane value + width = 80 return nil }