Skip to content
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

BF: don't force override terminal foreground color for Pygments themes #3582

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aqw
Copy link

@aqw aqw commented Dec 8, 2024

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

This changes the behavior of Pygments Styles without a color to use None (rather than hardcode to black), which instructs Pygments to use the terminal's configured foreground color.

This shows up, for example, with the bw theme. Despite its name, the theme does not specify any colors, and is instead exclusively bold, italics, etc. This is especially useful for providing a default syntax highlighting that will work across all terminal color schemes and possible user color blindness.

IMO, the fix in this PR is the appropriate behavior. However, it is a change in behavior, which I can understand a maintainer not being thrilled about. A less invasive solution would be to add something like the following to PygmentsSyntaxTheme.__init__():

self._foreground_color = getattr(self._pygments_style_class, 'foreground_color', "#000000")

And then use self._foreground_color as the fallback rather than None. Then themes could be defined with an explicit foreground_color = None. This would be similar to what bgcolor does.

I don't like that solution as much, but I'm happy to change this PR to do so if you prefer.

Styles without a color should not hardcode to black, and instead use
None, which instructs Pygments to use the terminal's configured
foreground color.
@aqw aqw changed the title BF: don't override terminal foreground color for Pygments themes BF: don't force override terminal foreground color for Pygments themes Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant