Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

man page doesn't get colorized if the default theme's changed #2115

Open
icy-comet opened this issue Mar 10, 2022 · 12 comments · May be fixed by #2994
Open

man page doesn't get colorized if the default theme's changed #2115

icy-comet opened this issue Mar 10, 2022 · 12 comments · May be fixed by #2994
Labels
bug Something isn't working help wanted Extra attention is needed syntax-highlighting upstream-error A bug in an upstream component

Comments

@icy-comet
Copy link

icy-comet commented Mar 10, 2022

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
@icy-comet icy-comet added the bug Something isn't working label Mar 10, 2022
@poetaman
Copy link

Yes, I just came here to search for the same problem.

@lucatrv
Copy link

lucatrv commented Mar 13, 2022

I confirm this issue on Arch Linux, bat 0.20.0 (0655ecf2).

@keith-hall
Copy link
Collaborator

keith-hall commented Mar 16, 2022

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.

@keith-hall keith-hall added help wanted Extra attention is needed upstream-error A bug in an upstream component labels Mar 16, 2022
@keith-hall
Copy link
Collaborator

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.

@victor-gp
Copy link
Contributor

@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 😅) 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.

@haizaar
Copy link

haizaar commented Jul 8, 2023

I hit this one as well:

MANPAGER="sh -c 'col -bx | bat -l man -p --paging=always --theme=OneHalfDark'" man bash
image

MANPAGER="sh -c 'col -bx | bat -l man -p --paging=always --theme=OneHalfDark'" man bash
Much better!
image

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
image

But for all command line utils man pages, bat themes do nothing really.

batman is also affected by this: eth-p/bat-extras#102

@lucatrv
Copy link

lucatrv commented Jul 8, 2023

For everyone hitting this issue, this is my workaround:

export MANPAGER="sh -c 'col -bx | bat --theme=default -l man -p'"
man 2 select

@frere-jacques
Copy link

thx. The man 2 select is just an example, I guess.

@lucatrv
Copy link

lucatrv commented Dec 29, 2023

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.

@frere-jacques
Copy link

I see, but also in the instructions it is as far as I understand an example.

@lucatrv
Copy link

lucatrv commented Dec 29, 2023

@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.

@devnoname120
Copy link

devnoname120 commented May 20, 2024

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 just tried and --theme=default seems to correspond to Monokai Extended Light which is unreadable because it uses a dark grey color for text that is very close to the black of my terminal. Using--theme="Monokai Extended" works better for me.


Either way, I'll keep using the colored-man-pages zsh plugin for the foreseeable future because bat -l man coloring is too unreliable for me.

See this comparison for an example:

  • On the left export MANPAGER="sh -c 'col -bx | bat --theme=\"Monokai Extended\" -l man -p'"; man ffmpeg
  • On the right colored man ffmpeg
image

Edit: and this is not a theme issue, here is what I see when I use the default theme with export MANPAGER="sh -c 'col -bx | bat --theme=\"default\" -l man -p'"; man ffmpeg:

image

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working help wanted Extra attention is needed syntax-highlighting upstream-error A bug in an upstream component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants