Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust validateOptions to handle preconfigured width #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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