{"id":10098,"library":"pygments-ansi-color","title":"Pygments ANSI Color","description":"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.","status":"maintenance","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/thomas-messire/pygments-ansi-color","tags":["pygments","ansi","color","syntax-highlighting","terminal"],"install":[{"cmd":"pip install pygments-ansi-color","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for core functionality, as this library provides a lexer that integrates with Pygments.","package":"Pygments","optional":false}],"imports":[{"symbol":"AnsiColorLexer","correct":"from pygments_ansi_color import AnsiColorLexer"}],"quickstart":{"code":"from pygments import highlight\nfrom pygments.formatters import TerminalFormatter\nfrom pygments_ansi_color import AnsiColorLexer\n\n# Example string with ANSI color codes\nansi_string = \"\\u001b[31mError: Something went wrong!\\u001b[0m \\u001b[32mSuccess: Operation completed.\\u001b[0m\"\n\n# Highlight the string using AnsiColorLexer and output to terminal\nhighlighted_output = highlight(ansi_string, AnsiColorLexer(), TerminalFormatter())\n\nprint(highlighted_output)","lang":"python","description":"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."},"warnings":[{"fix":"Always combine `AnsiColorLexer()` with a Pygments formatter like `highlight(code, AnsiColorLexer(), TerminalFormatter())`.","message":"This library provides a Pygments *lexer*, not a standalone formatter. You still need a Pygments formatter (e.g., `TerminalFormatter` or `HtmlFormatter`) to render the highlighted output.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `pip install Pygments` is run if you encounter `ModuleNotFoundError` for `pygments` modules.","message":"The `Pygments` library itself is a required dependency for `pygments-ansi-color` to function, but it may not be automatically installed. You might need to install `Pygments` separately.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The lexer primarily focuses on ANSI color and style codes. It may not fully parse or render all complex ANSI escape sequences (e.g., cursor manipulation, advanced screen control codes) that are not directly related to text styling.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pygments-ansi-color` to install the library.","cause":"The 'pygments-ansi-color' library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'pygments_ansi_color'"},{"fix":"Add `from pygments_ansi_color import AnsiColorLexer` at the top of your Python script.","cause":"The `AnsiColorLexer` class was used in the code without being imported first.","error":"NameError: name 'AnsiColorLexer' is not defined"},{"fix":"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())`.","cause":"The Pygments formatter being used does not render ANSI escape codes for the specific output environment, or the terminal itself doesn't support them.","error":"Output shows raw ANSI escape codes instead of colored text."}]}