mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-20 15:14:17 +02:00
feat: allow --width=0 to disable wordwrap (#366)
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
2d5bd3b799
commit
96d2a38e67
1 changed files with 13 additions and 11 deletions
24
main.go
24
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue