bat icon indicating copy to clipboard operation
bat copied to clipboard

broken highlighting of manpage references `page(section)`

Open LunarLambda opened this issue 2 years ago • 8 comments

How did you install bat?

Archlinux repositories


man 1 ls image man 1 zshall image man 1 ls, with MANPAGER="sh -c 'col -bx | bat -plman'" image

bat version and environment

Software version

bat 0.23.0 (871abd27)

Operating system

Linux 6.4.11-arch2-1

Command-line

bat --diagnostic 

Environment variables

SHELL=/bin/zsh
PAGER=less
LESS=<not set>
LANG=de_DE.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=<not set>
XDG_CONFIG_HOME=/home/lambda/cfg
XDG_CACHE_HOME=/home/lambda/.cache
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=bat -plman

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/lambda/cfg/bat/config': No such file or directory (os error 2).

Custom assets metadata

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

Custom assets

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

Compile time information

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

Less version

> less --version 
less 643 (PCRE2 regular expressions)
Copyright (C) 1984-2023  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

Terminal is xfce4-terminal (VTE_VERSION 7202, TERM xterm-256color)

LunarLambda avatar Sep 13 '23 19:09 LunarLambda

I've also had this issue for a while now

LevitatingBusinessMan avatar Sep 22 '23 20:09 LevitatingBusinessMan

it occured to me that it may be conflicting with the LESS_TERMCAP_* environment variables that can be used to do colorization in less without needing to use an external highlighter

however even after unsetting them, the result is exactly identical, so it doesn't appear to be the issue.

I tried getting less to not do any of its own highlighting (bold/underline) but none of the options I tried had any effect either.

LunarLambda avatar Sep 22 '23 21:09 LunarLambda

I don't have set any LESS_TERMCAP_ environment variables, but I'm having the issue too.

MarkusNaeher avatar Sep 25 '23 03:09 MarkusNaeher

Looks like someone found a workaround here https://github.com/sharkdp/bat/issues/2593#issuecomment-1636468711

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.

This has fixed the problem for me.

cannonpalms avatar Sep 26 '23 15:09 cannonpalms

I've the same problem :

bat

even if I export the option MANROFFOPT='-c' (or GROFF_NO_SGR=1) :

bat+manroffopt

on the contrary, ^H appear in every corner. most doesn't seem to be affected :

most

regards, lacsaP.

patatetom avatar Nov 13 '23 08:11 patatetom

the joint use of the omitted col in my MANPAGER definition (eg. export MANPAGER='sh -c "col -bx | bat -l man -p"') and the MANROFFOPT option (eg. export MANROFFOPT='-c') solves the ^H problem :

bat

however, bat doesn't seem to honor the PAGER environment variable : PAGER='most' man man has no effect because bat continues to use less as pager (nb. BAT_PAGER=most man man uses most as pager as requested).

I don't know if it's a bug, but coloring is discontinuous when accented characters are encountered :

french (LANG="fr_FR.UTF-8" man man)

regards, lacsaP.

patatetom avatar Nov 13 '23 10:11 patatetom

The workaround seems to work for me for man pages. (setting MANROFFOPT to -c, and removing decorations with col -bx in MANPAGER).

Unfortunately, some programs respect MANPAGER but not not MANROFFOPT. For example, aws help. In that case, the output is all messed up. See screenshot image

arenevier avatar Dec 10 '23 23:12 arenevier

I might be wrong, but if my understanding is correct, the problem is that by default (without nroff default output), bat feeds text with ansi escape characters to HighlightLines. HighlightLines tries to parse Manpages content, but does not expect the content to contain ansi and get confused. Actually, if I remove the function-call include and rebuild the assets and rebuild bat, the initial garbage does not appear.

I found a workaround that works with man, and with aws help: I leave MANROFFOPT empty. So nroff outputs content with ansi espace sequences. And I remove them in the MANPAGER step with MANPAGER="sh -c \"sed -e 's/\x1b\[[0-9;]*m//g'

It does the trick. But it seems to me that in ideal world, bat should accept content with ansi escape sequences, and remove them before passing the string to HighlightLines

arenevier avatar Dec 10 '23 23:12 arenevier