pytest-dev / pytest-dev/pytest

Use richer colors pygments terminal formatter?

Open
#11,666 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: reporting
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

pytest currently uses pygments' TerminalFormatter. While reviewing a PR I've noticed that pygments also has Terminal256Formatter and TerminalTrueColorFormatter which presumably have richer colors than TerminalFormatter. Maybe if we use them we'll get better syntax highlighting.

pygments cmdline tool seems to use the following logic for selecting a formatter:

            if os.environ.get('COLORTERM','') in ('truecolor', '24bit'):
                fmter = TerminalTrueColorFormatter(**parsed_opts)
            elif '256' in os.environ.get('TERM', ''):
                fmter = Terminal256Formatter(**parsed_opts)
            else:
                fmter = TerminalFormatter(**parsed_opts)

https://github.com/pygments/pygments/blob/861fb9131b13241d7ea700fba8f6a38cf6f97285/pygments/cmdline.py#L448-L453C57

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating pytest's use of Pygments' TerminalFormatter and compare it with the formatter-selection logic shown from the Pygments command-line tool. Done means terminal syntax highlighting selects an appropriate richer formatter for true-color or 256-color environments while retaining the fallback behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.