catppuccin.extras.pygments

Pygments styles for all Catppuccin flavors.

This package provides a Pygments style for each of the four Catppuccin flavors.

Install Catppuccin with the pygments feature to include the relevant dependencies:

pip install catppuccin[pygments]

The styles are registered as importlib entrypoints, which allows Pygments to find them by name:

from pygments.styles import get_style_by_name

get_style_by_name("catppuccin-frappe")
# catppuccin.extras.pygments.FrappeStyle

The following style names are available:

  • catppuccin-latte
  • catppuccin-frappe
  • catppuccin-macchiato
  • catppuccin-mocha

They can also be accessed by directly importing them:

from catppuccin.extras.pygments import MacchiatoStyle
  1# ruff: noqa: ERA001
  2"""Pygments styles for all Catppuccin flavors.
  3
  4This package provides a Pygments style for each of the four Catppuccin flavors.
  5
  6Install Catppuccin with the `pygments` feature to include the relevant dependencies:
  7
  8```
  9pip install catppuccin[pygments]
 10```
 11
 12The styles are registered as importlib entrypoints, which allows Pygments to
 13find them by name:
 14
 15```python
 16from pygments.styles import get_style_by_name
 17
 18get_style_by_name("catppuccin-frappe")
 19# catppuccin.extras.pygments.FrappeStyle
 20```
 21
 22The following style names are available:
 23
 24- `catppuccin-latte`
 25- `catppuccin-frappe`
 26- `catppuccin-macchiato`
 27- `catppuccin-mocha`
 28
 29They can also be accessed by directly importing them:
 30
 31```python
 32from catppuccin.extras.pygments import MacchiatoStyle
 33```
 34"""
 35
 36from __future__ import annotations
 37
 38from typing import TYPE_CHECKING
 39
 40from pygments.style import Style
 41from pygments.token import (
 42    Comment,
 43    Error,
 44    Generic,
 45    Keyword,
 46    Literal,
 47    Name,
 48    Number,
 49    Operator,
 50    Other,
 51    Punctuation,
 52    String,
 53    Text,
 54    Whitespace,
 55    _TokenType,
 56)
 57
 58from catppuccin import PALETTE
 59
 60if TYPE_CHECKING:
 61    from catppuccin.models import FlavorColors
 62
 63
 64def _make_styles(colors: FlavorColors) -> dict[_TokenType, str]:
 65    # https://pygments.org/docs/tokens/
 66    return {
 67        Comment: colors.overlay2.hex,
 68        Comment.Hashbang: colors.overlay2.hex,
 69        Comment.Multiline: colors.overlay2.hex,
 70        Comment.Preproc: colors.pink.hex,
 71        Comment.Single: colors.overlay2.hex,
 72        Comment.Special: colors.overlay2.hex,
 73        Generic: colors.text.hex,
 74        Generic.Deleted: colors.red.hex,
 75        Generic.Emph: f"{colors.text.hex} underline",
 76        Generic.Error: colors.text.hex,
 77        Generic.Heading: f"{colors.text.hex} bold",
 78        Generic.Inserted: f"{colors.text.hex} bold",
 79        Generic.Output: colors.overlay0.hex,
 80        Generic.Prompt: colors.text.hex,
 81        Generic.Strong: colors.text.hex,
 82        Generic.Subheading: f"{colors.text.hex} bold",
 83        Generic.Traceback: colors.text.hex,
 84        Error: colors.text.hex,
 85        # `as`
 86        Keyword: colors.mauve.hex,
 87        Keyword.Constant: colors.mauve.hex,
 88        Keyword.Declaration: f"{colors.mauve.hex} italic",
 89        # `from`, `import`
 90        Keyword.Namespace: colors.mauve.hex,
 91        Keyword.Pseudo: colors.pink.hex,
 92        Keyword.Reserved: colors.mauve.hex,
 93        Keyword.Type: colors.yellow.hex,
 94        Literal: colors.text.hex,
 95        Literal.Date: colors.text.hex,
 96        # from xxx import NAME
 97        # NAME = NAME
 98        # NAME.NAME()
 99        Name: colors.text.hex,
100        Name.Attribute: colors.green.hex,
101        # `len`, `print`
102        Name.Builtin: f"{colors.red.hex} italic",
103        # `self`
104        Name.Builtin.Pseudo: colors.red.hex,
105        # class Name.Class:
106        Name.Class: colors.yellow.hex,
107        Name.Constant: colors.text.hex,
108        Name.Decorator: colors.text.hex,
109        Name.Entity: colors.text.hex,
110        Name.Exception: colors.yellow.hex,
111        # def __Name.Label__(
112        Name.Function: colors.blue.hex,
113        Name.Label: f"{colors.teal.hex} italic",
114        Name.Namespace: colors.text.hex,
115        Name.Other: colors.text.hex,
116        Name.Tag: colors.blue.hex,
117        Name.Variable: f"{colors.text.hex} italic",
118        Name.Variable.Class: f"{colors.yellow.hex} italic",
119        Name.Variable.Global: f"{colors.text.hex} italic",
120        Name.Variable.Instance: f"{colors.text.hex} italic",
121        Number: colors.peach.hex,
122        Number.Bin: colors.peach.hex,
123        Number.Float: colors.peach.hex,
124        Number.Hex: colors.peach.hex,
125        Number.Integer: colors.peach.hex,
126        Number.Integer.Long: colors.peach.hex,
127        Number.Oct: colors.peach.hex,
128        # `=`
129        Operator: colors.sky.hex,
130        # `not`, `in`
131        Operator.Word: colors.mauve.hex,
132        Other: colors.text.hex,
133        # `(`, `)`, `,`, `[`, `]`, `:`
134        Punctuation: colors.overlay2.hex,
135        String: colors.green.hex,
136        String.Backtick: colors.green.hex,
137        String.Char: colors.green.hex,
138        String.Doc: colors.green.hex,
139        String.Double: colors.green.hex,
140        String.Escape: colors.pink.hex,
141        String.Heredoc: colors.green.hex,
142        String.Interpol: colors.green.hex,
143        String.Other: colors.green.hex,
144        String.Regex: colors.pink.hex,
145        String.Single: colors.green.hex,
146        String.Symbol: colors.red.hex,
147        Text: colors.text.hex,
148        Whitespace: colors.text.hex,
149    }
150
151
152class LatteStyle(Style):
153    """Catppuccin Latte pygments style."""
154
155    _colors = PALETTE.latte.colors
156
157    background_color = _colors.base.hex
158    highlight_color = _colors.surface0.hex
159    line_number_background_color = _colors.mantle.hex
160    line_number_color = _colors.text.hex
161    line_number_special_background_color = _colors.mantle.hex
162    line_number_special_color = _colors.text.hex
163
164    styles = _make_styles(_colors)
165
166
167class FrappeStyle(Style):
168    """Catppuccin Frappé pygments style."""
169
170    _colors = PALETTE.frappe.colors
171
172    background_color = _colors.base.hex
173    highlight_color = _colors.surface0.hex
174    line_number_background_color = _colors.mantle.hex
175    line_number_color = _colors.text.hex
176    line_number_special_background_color = _colors.mantle.hex
177    line_number_special_color = _colors.text.hex
178
179    styles = _make_styles(_colors)
180
181
182class MacchiatoStyle(Style):
183    """Catppuccin Macchiato pygments style."""
184
185    _colors = PALETTE.macchiato.colors
186
187    background_color = _colors.base.hex
188    highlight_color = _colors.surface0.hex
189    line_number_background_color = _colors.mantle.hex
190    line_number_color = _colors.text.hex
191    line_number_special_background_color = _colors.mantle.hex
192    line_number_special_color = _colors.text.hex
193
194    styles = _make_styles(_colors)
195
196
197class MochaStyle(Style):
198    """Catppuccin Mocha pygments style."""
199
200    _colors = PALETTE.mocha.colors
201
202    background_color = _colors.base.hex
203    highlight_color = _colors.surface0.hex
204    line_number_background_color = _colors.mantle.hex
205    line_number_color = _colors.text.hex
206    line_number_special_background_color = _colors.mantle.hex
207    line_number_special_color = _colors.text.hex
208
209    styles = _make_styles(_colors)
class LatteStyle(pygments.style.Style):
153class LatteStyle(Style):
154    """Catppuccin Latte pygments style."""
155
156    _colors = PALETTE.latte.colors
157
158    background_color = _colors.base.hex
159    highlight_color = _colors.surface0.hex
160    line_number_background_color = _colors.mantle.hex
161    line_number_color = _colors.text.hex
162    line_number_special_background_color = _colors.mantle.hex
163    line_number_special_color = _colors.text.hex
164
165    styles = _make_styles(_colors)

Catppuccin Latte pygments style.

class FrappeStyle(pygments.style.Style):
168class FrappeStyle(Style):
169    """Catppuccin Frappé pygments style."""
170
171    _colors = PALETTE.frappe.colors
172
173    background_color = _colors.base.hex
174    highlight_color = _colors.surface0.hex
175    line_number_background_color = _colors.mantle.hex
176    line_number_color = _colors.text.hex
177    line_number_special_background_color = _colors.mantle.hex
178    line_number_special_color = _colors.text.hex
179
180    styles = _make_styles(_colors)

Catppuccin Frappé pygments style.

class MacchiatoStyle(pygments.style.Style):
183class MacchiatoStyle(Style):
184    """Catppuccin Macchiato pygments style."""
185
186    _colors = PALETTE.macchiato.colors
187
188    background_color = _colors.base.hex
189    highlight_color = _colors.surface0.hex
190    line_number_background_color = _colors.mantle.hex
191    line_number_color = _colors.text.hex
192    line_number_special_background_color = _colors.mantle.hex
193    line_number_special_color = _colors.text.hex
194
195    styles = _make_styles(_colors)

Catppuccin Macchiato pygments style.

class MochaStyle(pygments.style.Style):
198class MochaStyle(Style):
199    """Catppuccin Mocha pygments style."""
200
201    _colors = PALETTE.mocha.colors
202
203    background_color = _colors.base.hex
204    highlight_color = _colors.surface0.hex
205    line_number_background_color = _colors.mantle.hex
206    line_number_color = _colors.text.hex
207    line_number_special_background_color = _colors.mantle.hex
208    line_number_special_color = _colors.text.hex
209
210    styles = _make_styles(_colors)

Catppuccin Mocha pygments style.