From 87b1b5106532c3989c95dfb0e202fb6b4159f67f Mon Sep 17 00:00:00 2001 From: Alex Waite Date: Sun, 8 Dec 2024 18:07:24 +0100 Subject: [PATCH] don't override terminal foreground color for pygments themes Styles without a color should not hardcode to black, and instead use None, which instructs Pygments to use the terminal's configured foreground color. --- CHANGELOG.md | 5 +++++ CONTRIBUTORS.md | 1 + rich/syntax.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c7332fee..6ec5460f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Pygments styles without color now use terminal's foreground color rather than hardcode black https://github.com/Textualize/rich/pull/3582 ## [13.9.4] - 2024-11-01 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d8985ca13..a5af1be8d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -72,6 +72,7 @@ The following people have contributed to the development of Rich: - [Karolina Surma](https://github.com/befeleme) - [Gabriele N. Tornetta](https://github.com/p403n1x87) - [Nils Vu](https://github.com/nilsvu) +- [Alex Waite](https://github.com/aqw) - [Arian Mollik Wasi](https://github.com/wasi-master) - [Jan van Wijk](https://github.com/jdvanwijk) - [Handhika Yanuar Pratama](https://github.com/theDreamer911) diff --git a/rich/syntax.py b/rich/syntax.py index cff8fd235..246a19acd 100644 --- a/rich/syntax.py +++ b/rich/syntax.py @@ -162,7 +162,7 @@ def get_style_for_token(self, token_type: TokenType) -> Style: color = pygments_style["color"] bgcolor = pygments_style["bgcolor"] style = Style( - color="#" + color if color else "#000000", + color="#" + color if color else None, bgcolor="#" + bgcolor if bgcolor else self._background_color, bold=pygments_style["bold"], italic=pygments_style["italic"],