feat: allow --width=0 to disable wordwrap (#366)

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
kalle (jag) 2024-07-11 17:16:12 +02:00 committed by GitHub
commit 96d2a38e67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

24
main.go
View file

@ -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
}
@ -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")