bat icon indicating copy to clipboard operation
bat copied to clipboard

Bat hard-wraps if any decorations are enabled even if they don't affect line layout

Open lilyball opened this issue 2 years ago • 3 comments

Describe the bug you encountered:

bat will soft-wrap text if I use --style=plain, meaning resizing the window works, copying wrapped lines works correctly, and jumping to a specific line in less works. But it hard-wraps if I enable any decorations, even if the decorations don't affect the horizontal layout. This is really frustrating. Even if I don't want to resize the window, the fact that it breaks copying of wrapped lines (by inserting a newline) is a problem, and the fact that I can't jump to a given line (taking header height into account) in less is annoying too.

This happens even if the decoration in question isn't affecting output, such as bat --style=snip without setting line ranges. Or if the decoration is completely unaffected by window width, such as bat --style=header

What did you expect to happen instead?

Bat should soft-wrap any line whose layout is not dependent upon decorations. I believe right now that means it should soft-wrap as long as I did not enable the numbers or changes decorations. Or to put it another way, if there's no gutter, or equivalently if the grid decoration would not draw a vertical line, then it should soft-wrap.

How annoying is this?

It's annoying enough that I have --style=plain in my config, even though I'd really prefer to have something like --style=header,grid,snip. But copying of wrapped lines and jumping to line numbers in less are both so important that I have no choice.

How did you install bat?

Nix


bat version and environment

Software version

bat 0.18.0

Operating system

Darwin 20.5.0

Command-line

/Users/lily/.nix-profile/bin/bat --style=header some_file --diagnostic 

Environment variables

SHELL=/Users/lily/.local/share/home-manager/bin/fish
PAGER='less -R'
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=<not set>
NO_COLOR=<not set>
MANPAGER=<not set>

Config file

#--theme base16
--italic-text always
--map-syntax *.jenkinsfile:Groovy
--style=plain

Compile time information

  • Profile: release
  • Target triple: x86_64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2,sse3,ssse3
  • Host: x86_64-apple-darwin

Less version

> less --version 
less 563 (POSIX regular expressions)
Copyright (C) 1984-2020  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: http://www.greenwoodsoftware.com/less

lilyball avatar Jul 20 '21 21:07 lilyball

Thank you for reporting this.

Just to make sure: did you see the --wrap option? The following should hopefully work fine:

--style=header,grid,snip --wrap=never

sharkdp avatar Jul 23 '21 21:07 sharkdp

I did notice that option after filing this issue I set it in my config because it disables soft wrapping in less as well (though I can re-enable it interactively with -S). And if I work around that, then this will probably confuse me the next time I try bat --style=full.

lilyball avatar Jul 24 '21 02:07 lilyball

Just wanted to add that this same issue bothers me.

My issue with --wrap=never is that it triggers the pager interactively when lines are too long, whereas without it, the paging is only activated automatically when there are enough lines.

The reason I want to disable wrapping without this side-effect is because I don't like having to remove the newlines when copy-pasting (or having to switch to cat once I realize they're there).

Ex: Using --style="rule,snip" in my config when running bat .ssh/id_rsa.pub causes hard wrapping, whereas --style="plain" works perfectly even though rule and snip aren't even applicable for that invocation of the command, since it's only one file with no given line range.

Arian04 avatar May 05 '24 21:05 Arian04