From 96d2a38e67d03c08cecb89e8317512bc401825d1 Mon Sep 17 00:00:00 2001 From: "kalle (jag)" <2477952+applejag@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:16:12 +0200 Subject: [PATCH] feat: allow --width=0 to disable wordwrap (#366) Co-authored-by: Carlos Alexandro Becker --- main.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 3bd2154..666d919 100644 --- a/main.go +++ b/main.go @@ -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")