sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.36k stars 1.25k forks source link

broken highlighting of manpage references `page(section)` #2668

Open LunarLambda opened 1 year ago

LunarLambda commented 1 year ago

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

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)

LevitatingBusinessMan commented 1 year ago

I've also had this issue for a while now

LunarLambda commented 1 year ago

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.

MarkusNaeher commented 1 year ago

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

cannonpalms commented 1 year ago

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.

patatetom commented 11 months ago

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 commented 11 months ago

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.

arenevier commented 10 months ago

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 commented 10 months ago

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