bat
bat copied to clipboard
`man` page doesn't get colorized if the default theme's changed
Describe the bug you encountered:
I tried playing with multiple options, but as soon as I change the default theme to anything else, colorization on man pages break.
I tried setting theme to ansi, base16, base16-256, OneHalfDark, and 1337. I also set --color=always, but that didn't help either even though I explicitly specify the language as man while piping into bat.
This can be reproduced by invoking bat on bat's help itself: bat --help | bat -l man. Highlighting works with the default theme, but not with others -- only a few words get highlighted.
...
What did you expect to happen instead?
Syntax highlighting on the man page just as it functions with the default theme.
...
How did you install bat?
I used Scoop to install bat.
bat version and environment
I use PowerShell 7.2.1 that supports Unicode by default and Windows Terminal that has xterm-256 terminal capabilities.
This the output on running bat --help | bat -l man --diagnostic:
Software version
bat 0.20.0 (0655ecf)
Operating system
Windows 6.2.9200
Command-line
C:\Users\anike\scoop\apps\bat\current\bat.exe -l man --diagnostic
Environment variables
SHELL=<not set>
PAGER=<not set>
LESS=<not set>
LANG=<not set>
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=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=<not set>
NO_COLOR=<not set>
MANPAGER=<not set>
Config file
# This is `bat`s configuration file. Each line either contains a comment or
# a command-line option that you want to pass to `bat` by default. You can
# run `bat --help` to get a list of all possible configuration options.
# Specify desired highlighting theme (e.g. "TwoDark"). Run `bat --list-themes`
# for a list of all available themes
# --theme="ansi"
# Enable this to use italic text on the terminal. This is not supported on all
# terminal emulators (like tmux, by default):
--italic-text=always
# Uncomment the following line to disable automatic paging:
#--paging=never
# Uncomment the following line if you are using less version >= 551 and want to
# enable mouse scrolling support in `bat` when running inside tmux. This might
# disable text selection, unless you press shift.
--pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse"
# Syntax mappings: map a certain filename pattern to a language.
# Example 1: use the C++ syntax for Arduino .ino files
# Example 2: Use ".gitignore"-style highlighting for ".ignore" files
#--map-syntax "*.ino:C++"
#--map-syntax ".ignore:Git Ignore"
--style=changes,header,header-filesize
--color=always
Compile time information
- Profile: release
- Target triple: x86_64-pc-windows-msvc
- Family: windows
- OS: windows
- Architecture: x86_64
- Pointer width: 64
- Endian: little
- CPU features: fxsr,sse,sse2
- Host: x86_64-pc-windows-msvc
Less version
> C:\Users\anike\scoop\shims\less.exe --version
less 590 (Spencer V8 regular expressions)
Copyright (C) 1984-2021 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
Yes, I just came here to search for the same problem.
I confirm this issue on Arch Linux, bat 0.20.0 (0655ecf2).
Thanks for reporting. It seems these other color schemes are not targeting the minimum viable scopes as recommended by ST. For example, our man syntax definition is using entity.name.command-line-option, and the guidelines say color schemes should target entity.name. But "TwoDark", (to take a specific example,) only targets entity.name.function, entity.name.class and a few other "3 atom scopes" starting with entity.name but not entity.name itself and not entity.name.command-line-option.
The solution will be to get the third party color schemes updated - either by patching them in this repository, or by making fixes in the upstream repositories and then updating bat's submodule dependencies. Therefore I am marking this as an upstream error and help-wanted.
Having said that, it could be that I'm biased because I chose to use those scopes for our Manpage syntax highlighting. I understand that it would likely take less effort to adjust the scopes we use to those which are more commonly targeted by color schemes. So it is conceivable that we might accept a PR adjusting the scopes in the Manpage syntax definition to resolve this issue.
@icy-comet, could it be that what you're trying to colorize is a --help message rather than a man page? If that's the case, I've been working on a sublime syntax to scope help messages. It's still a work in progress but you may find it useful.
I plan to stabilize it over the next week and PR it to bat in 1-2 weeks.
@keith-hall, I tackled theme coverage by multi-scoping, with mostly unrelated scopes. You may think it a sacrilege (it is :sweat_smile:) but if you're willing to ignore scope meaning, here's a couple of changes that improve theme coverage by a bit: command options from entity.name to entity.name.function and multi-scoping headings as entity.name.section. The commits' stat shows a list of the themes that changed (usually for the best).
Of course, there are surely better combinations of (totally unrelated) scopes, to cover the themes built into bat. Mine is just a quick & dirty assignation I may revisit later on.
I hit this one as well:
MANPAGER="sh -c 'col -bx | bat -l man -p --paging=always --theme=OneHalfDark'" man bash
MANPAGER="sh -c 'col -bx | bat -l man -p --paging=always --theme=OneHalfDark'" man bash
Much better!
With man pages containing code snippets its not too bad:
MANPAGER="sh -c 'col -bx | bat -l man -p --paging=always --theme=OneHalfDark'" man 2 open
But for all command line utils man pages, bat themes do nothing really.
batman is also affected by this: https://github.com/eth-p/bat-extras/issues/102
For everyone hitting this issue, this is my workaround:
export MANPAGER="sh -c 'col -bx | bat --theme=default -l man -p'"
man 2 select
thx. The man 2 select is just an example, I guess.
thx. The man 2 select is just an example, I guess.
These are the official instructions on how to use bat as a colorizing pager for man, I just added --theme=default as a workaround to this issue.
I see, but also in the instructions it is as far as I understand an example.
@8FordPrefect8 yes sure, it is just an example to see a colorized man page, and actually I think it should be a more straightforward example, such as man cp or similar. On my Arch Linux system, if I issue man 2 select I get the following message No manual entry for select in section 2.