Skip to content

Commit

Permalink
feat: allow --width=0 to disable wordwrap (#366)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
applejag and caarlos0 authored Jul 11, 2024
1 parent 2d5bd3b commit 96d2a38
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,20 @@ func validateOptions(cmd *cobra.Command) error {
}

// Detect terminal width
if isTerminal && width == 0 && !cmd.Flags().Changed("width") {
w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err == nil {
width = uint(w)
}
if !cmd.Flags().Changed("width") {
if isTerminal && width == 0 {
w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err == nil {
width = uint(w)
}

if width > 120 {
width = 120
if width > 120 {
width = 120
}
}
if width == 0 {
width = 80
}
}
if width == 0 {
width = 80
}
return nil
}
Expand Down Expand Up @@ -368,7 +370,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", fmt.Sprintf("config file (default %s)", viper.GetViper().ConfigFileUsed()))
rootCmd.Flags().BoolVarP(&pager, "pager", "p", false, "display with pager")
rootCmd.Flags().StringVarP(&style, "style", "s", glamour.AutoStyle, "style name or JSON path")
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width")
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width (set to 0 to disable)")
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
rootCmd.Flags().BoolVarP(&showLineNumbers, "line-numbers", "l", false, "show line numbers (TUI-mode only)")
rootCmd.Flags().BoolVarP(&preserveNewLines, "preserve-new-lines", "n", false, "preserve newlines in the output")
Expand Down

0 comments on commit 96d2a38

Please sign in to comment.