bat icon indicating copy to clipboard operation
bat copied to clipboard

man page display does not work correctly

Open avysk opened this issue 2 years ago • 15 comments

Please notice that is is different from #2563 and different man colorization bugs where escape color codes are not interpreted.

What steps will reproduce the bug?

This is how man ls looks in most: image

Now let's run PAGER="bat --style snip --theme gruvbox-dark" man ls. image

Notice two problems:

  1. ls option line is broken in the middle of color.
  2. Highlighting is broken.

The plain style looks a little bit better: the option line is not broken, but the highlighting is: image

If the --style option is omitted, there is still an erroneous line break. I was not able to get any changes by using a different colorscheme.

Bat was installed via cargo.

❯ bat --style plain --theme gruvbox-dark --diagnostic

Software version

bat 0.23.0

Operating system

freebsd 13.2-RELEASE

Command-line

bat --style plain --theme gruvbox-dark --diagnostic

Environment variables

SHELL=/usr/local/bin/bash
PAGER=most
LESS=<not set>
LANG=ru_RU.UTF-8
LC_ALL=<not set>
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=zenburn
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=<not set>
NO_COLOR=<not set>
MANPAGER=<not set>

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

Could not read contents of '/home/alexey/.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

Could not read contents of '/home/alexey/.cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

'/home/alexey/.cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-freebsd
  • Family: unix
  • OS: freebsd
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-freebsd

Less version

> less --version
less 608 (POSIX regular expressions)
Copyright (C) 1984-2022  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: https://greenwoodsoftware.com/less

avysk avatar Jun 07 '23 08:06 avysk

Thanks for reporting. Does it help to use the -S option or explicitly set the --terminal-width? I think the highlighting goes wrong because it wraps the text in the wrong place, perhaps before it gets highlighted, which confuses it I'd guess.

I see something similar on my Linux Mint 21 system, and -S helps for me, and despite expectations, nothing actually gets chopped that I can see.

keith-hall avatar Jun 20 '23 20:06 keith-hall

Neither -S nor --terminal-width helps.

This is the result of PAGER="bat --style snip --theme gruvbox-dark -S" man ls image

This is the result of PAGER="bat --style snip --theme gruvbox-dark --terminal-width 40" man ls image

avysk avatar Jun 21 '23 10:06 avysk

I do not think that highlighting goes off because of wrapping. As you can see, it goes off after (non-wrapped) "DESCRIPTION" header.

avysk avatar Jun 21 '23 10:06 avysk

If it helps, that's what bat shows with -A image

Surprising thing: setting terminal-width to anything less than 22 causes "DESCRIPTION" header to wrap.

avysk avatar Jun 21 '23 10:06 avysk

Actually, I'm wrong: it looks like the highlighting is broken even before, in ls option line. Does [ do something bad?

avysk avatar Jun 21 '23 10:06 avysk

I do not think that highlighting goes off because of wrapping.

I'm a little bit confused, because in the first bat screenshot, it looks like the line is wrapped at [--colo|r=when], which you pointed out as problem 1, and the r has a different color than colo, so I guess I thought it is one example of what you referred to as problem 2. And I believe that for this specific case, fixing 1 would fix 2.

As for the bat -A output duplicating letters with backspaces between them -- which could also affect wrapping logic, this is why the readme recommends using col -bx I believe.

to be honest, I don't know how gruvbox-dark should look so I find it hard to guess what is wrong...

keith-hall avatar Jun 21 '23 17:06 keith-hall

You are right. The problem with line break seems to go away. I believe I have the same issues with default theme. I will produce screenshots tomorrow; it is nearly 9 pm here.

avysk avatar Jun 21 '23 17:06 avysk

I will also try with col tomorrow.

avysk avatar Jun 21 '23 17:06 avysk

You are right; col solves the problem (even though that resulting highlighting has nothing in common with "proper" highlighting -- I suppose the suggested combination just strips all the formatting from a manual page and then tries to guess what to do). I started to use bat really long time ago, I think col was not in the readme at that time, that's why I missed it.

Probably this issue can be closed -- with col, the formatting of a man page is ignored but nothing is broken.

avysk avatar Jun 23 '23 21:06 avysk

I guess I'm following up here with a related issue. I've been using the MANPAGER-Snippet from the readme for several months now, and since some software updates two days ago, my manpages have some gibberish characters included:

grafik

When investigating, i found that col (included in util-linux) got updated exactly around that time and seems to behave differently, has anyone else experienced that too?

christianhauff avatar Jul 13 '23 11:07 christianhauff

I have the same exact issue with yours, @christianhauff .

❯ col --version
col from util-linux 2.39.1
❯ bat --version
bat 0.23.0 (871abd27)

latipun7 avatar Jul 14 '23 04:07 latipun7

Same problem as @christianhauff. EDIT: Apparently the culprit is groff v1.23, so I added this to .zshrc and .bashrc export MANROFFOPT='-c' I don't know what this actually does, but it seems to work.

mjd-tech avatar Jul 14 '23 21:07 mjd-tech

Thanks @mjd-tech, your workaround works for me !

export MANROFFOPT='-c' I don't know what this actually does, but it seems to work.

$ man groff | grep -e '^\s*-c'
       -c     Start with color output disabled.

ju1ius avatar Jul 16 '23 18:07 ju1ius

@ju1ius , thanks. I found this solution in the gnu groff forum, only to find it was documented in the bat readme all along!

mjd-tech avatar Jul 16 '23 21:07 mjd-tech

For myself, using bat-extras & less, this is how I could get proper coloring:

alias less='batpipe'
export MANPAGER="less -R --use-color -Dd+r -Du+b"
export MANROFFOPT='-c'

ryanmusante avatar Jul 17 '23 00:07 ryanmusante