Pygments ANSI Color (version 0.3.0) provides a Pygments lexer specifically designed to highlight ANSI escape codes for colors and styles. It allows Pygments to correctly render colored terminal output, making it readable and formatted. The library has a slow release cadence, with the last update in September 2022, but remains functional for its intended purpose.
pip install pygments-ansi-colorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `AnsiColorLexer` with Pygments' `highlight` function and `TerminalFormatter` to render a string containing ANSI color codes directly to your terminal. Ensure your terminal supports ANSI escape sequences for colors to display correctly.
Always combine `AnsiColorLexer()` with a Pygments formatter like `highlight(code, AnsiColorLexer(), TerminalFormatter())`.
Ensure `pip install Pygments` is run if you encounter `ModuleNotFoundError` for `pygments` modules.
Assume support primarily for `\u001b[...m` sequences for color and style. For other ANSI features, manual parsing or a different specialized library might be necessary.
Run `pip install pygments-ansi-color` to install the library.
Add `from pygments_ansi_color import AnsiColorLexer` at the top of your Python script.
Ensure you are using a Pygments formatter like `TerminalFormatter` for terminal output and that your terminal emulator is configured to display ANSI colors. Example: `highlight(code, AnsiColorLexer(), TerminalFormatter())`.