Skip to content

Commit

Permalink
fix: adjust validaOptions to handle preconfigured width
Browse files Browse the repository at this point in the history
fixes #666
  • Loading branch information
csabahenk committed Dec 21, 2024
1 parent 7b3bfac commit 8406ada
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 8406ada

Please sign in to comment.