Skip to content

Commit

Permalink
Allow --width=0 to disable wordwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
applejag committed Aug 11, 2022
1 parent e078953 commit f1e1875
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 @@ -161,18 +161,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 @@ -379,7 +381,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", fmt.Sprintf("config file (default %s)", defaultConfigFile))
rootCmd.Flags().BoolVarP(&pager, "pager", "p", false, "display with pager")
rootCmd.Flags().StringVarP(&style, "style", "s", "auto", "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(&localOnly, "local", "l", false, "show local files only; no network (TUI-mode only)")
rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)")
Expand Down

0 comments on commit f1e1875

Please sign in to comment.