-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
man
syntax doesn't highlight bold functions correctly
#652
Comments
Thank you for the detailed bug report! I'm going to assume that you are using To figure out what's going on in detail, we can actually use MANPAGER="bat -A" man sprintf After finding the corresponding section, we can take a look at how
for a bold On todays terminal emulators, that doesn't actually work. If you use printf "p\bpr\bri\bin\bnt\btf\bf\n" which will just print Interestingly, printf "p\bpr\bri\bin\bnt\btf\bf\n" | less There is also a similar feature for underlined text: printf "p\b_r\b_i\b_n\b_t\b_f\b_\n" | less Back to int printf(const char* format, ...); in a man page and the whole line is printed in bold (beginning of For this reason, I originally used
Unfortunately, I missed that The following works for me: MANPAGER="sh -c 'col -bx | bat -p -lman'" man sprintf I think we should update the instructions in the README to suggest Unfortunately, it looks like your
|
In this case, it does not seem like set -x
bat --version
bat --config-file
bat --cache-dir
less --version
bat "$(bat --config-file)"
ls "$(bat --cache-dir)"
set +x
echo "BAT_PAGER = '$BAT_PAGER'"
echo "BAT_CONFIG_PATH = '$BAT_CONFIG_PATH'"
echo "BAT_STYLE = '$BAT_STYLE'"
echo "BAT_THEME = '$BAT_THEME'"
echo "BAT_TABS = '$BAT_TABS'"
echo "PAGER = '$PAGER'"
echo "LESS = '$LESS'" |
|
Hm, nothing unusual there. It would be great if you could show two other screenshots: One for: MANPAGER='sh -c "col -bx | bat -plman --color=never"' man sprintf and one for MANPAGER='sh -c "col -bx | bat -Ap"' man sprintf |
I've got an idea. What does |
I'm using Zsh, but little to no configuration (no oh-my-zsh, any aliases replacing commands, etc...)
|
Okay. So the output is definitely already messed up when it reaches If MANPAGER="bat -Ap" man sprintf directly. It should contain plenty of backspace characters, but no ANSI escape sequences. Thank you very much for following along! |
Ok. It looks like your version of It might be worth going through |
Perhaps just being able to pass |
Hm. We could try to remove ANSI codes from the output (instead of using Might make sense to move this to a separate script that can be used as In the future, we could potentially also try to find a proper/better solution by pre-processing within |
Well.
While this presents a working solution for now, I'd suggest either keeping this issue open, or opening a new one, as this is rather hacky. (although it was fun learning experience about the joys of old unix tech!) |
I'd like to close this. It is now described in the README, and I currently don't see a better solution. |
Understandable ^^ |
You should mention in the README that bold highlighting is unsupported - I was quite confused, and this issue doesn't really go into that. |
Seriously? This issue "doesn't really go into that"? We have spent hours to debug this and have written extremely detailed comments that document everything.
Nobody "should" do anything here, but I agree that it's probably a good idea to add that. Contributions to the documentation are always welcome. |
Hey, sorry if that was phrased unappreciative. I did read the comments and it was quite informative, but to me seemed mostly concerned with the problems of the control characters used for boldness messing up the output. What I was wondering is whether this could actually be changed to interpret boldness. I am writing a man page myself and would like to see it as the end users see it, so I currently have to use less, but much prefer the overall look of bat :) |
I'm going to reopen this, as there might actually be a way to solve this, if we write a |
I ran into this as well using Windows Terminal with |
Program versionsArch Linux Comparison
Neither ConclusionAdding colors is nice, but since |
for me, working on fedora 35 |
You need to set additional option when man already uses ANSI escape sequences. Providing `-c` option via environment variables `MANROFFOPT` fixes wrong rendering of man pages via bat. See sharkdp/bat#652 (comment).
Same here, maybe could be added to README? |
Backspace formatting for bold characters, done by relics such as man or less (bless them anyways). Graciously explained in [1]. Presents the same zebra-coloring problem as delta, ditto the previous commit message. Maybe I should re-think my approach to these, try to scope everything with a token themed with the default fg color... But not today. [1] sharkdp/bat#652 (comment)
I've done a little more digging into this, as I have one Linux system and macOS where I'm running into this. Ideally, both color and bold/underline would be output as ANSI codes and It seems that in Debian it might be possible to achieve with So far I have not found a working option for macOS or the CentOS system where I'm still seeing the issue, but I'm working on trying an option to "dumb replace" them, something like # doesn't work quite right...
MANPAGER="sed -r 's/(.)\x08\1/\033[1m\1\033[0m/g' | bat -plman" This StackExchange also seems to have lots of relevant details here, which makes it seem like lots of the options here are distro-dependent unfortunately... Maybe preprocessing in Edit: one more resource explaining some different behavior on Arch (where everything seems to work... better? differently? for me at least) and Debian |
update from my side: Using nvim/emacs as man viewer now as these can follow links as well ;) |
Okay, phew! I dug in a little more and got a usable Here's the command I'm using: sed=gsed # needed on macOS it seemzs
# sed=sed # linux
export MANPAGER="$sed -E 's/(.)\x08\1/\x1b[1m\1\x1b[22m/g' |
$sed -E 's/_\x08(.)/\x1b[4m\1\x1b[24m/g' |
bat -p"
man sprintf This displays non-colored but correctly decorated pages, as you might expect! However, when using export MANPAGER="$sed -E 's/(.)\x08\1/\x1b[1m\1\x1b[22m/g' |
$sed -E 's/_\x08(.)/\x1b[4m\1\x1b[24m/g' |
bat -plman"
man sprintf Is it expected that |
On macOS this happens if you use the Not sure if that's viable for anybody else, but removing it was a huge QoL improvement for me (back to Example of what the brokenness looked like, since it doesn't quite seem the same as the others, although it's basically the same problem.(Before)
(After)
Both had some amount of |
See problem and solution on bat's [github issue #652](sharkdp/bat#652 (comment))
See problem and solution on bat's [github issue #652](sharkdp/bat#652 (comment))
do we have to use |
As piping function m --wraps man
man $argv | bat -pl man
end In case it helps someone |
I'm using fish too and adding this line to the fish config file worked as well. set -x MANROFFOPT "-c You also need the line below to use bat as stated in the doc, I'm putting it here in case it didn't come with your initial config and you missed it in the docs. set -x MANPAGER "sh -c 'col -bx | bat -l man -p'" |
Terminals tested: alacritty, mate-terminal, urxvt
bat --version
: 0.12.0 (Installed viacargo install bat
)$MANPAGER
: bat --paging=never -pl man [1] [2][1]: I disabled paging to make sure it's not a problem with
less(1)
.[2]: The documentation suggests setting MANPAGER to
sh -c "col -b | bat -pl man"
however I found usingcol
actually just garbled the output even more, see screenshot further down.Output with
MANPAGER='bat -pl man'
Output with
MANPAGER=''
orMANPAGER='less'
The issue seems to be with highlighting functions / page references (foo(...)) when bold output is used.
When using
col -b
as suggested, it becomes even worse:Output with
MANPAGER='sh -c "col -b | bat -pl man"'
The text was updated successfully, but these errors were encountered: