Skip to content

Commit

Permalink
fix: adjust validateOptions to handle preconfigured width
Browse files Browse the repository at this point in the history
fixes #666

Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
  • Loading branch information
csabahenk and ccoVeille committed Dec 21, 2024
1 parent 7b3bfac commit d008b82
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d008b82

Please sign in to comment.