|
12 | 12 | from pathlib import Path |
13 | 13 |
|
14 | 14 | import numpy as np |
15 | | -from pygments import highlight |
| 15 | +from pygments import highlight, styles |
16 | 16 | from pygments.formatters.html import HtmlFormatter |
17 | 17 | from pygments.lexers import get_lexer_by_name, guess_lexer_for_filename |
18 | | -from pygments.styles import get_all_styles |
19 | 18 |
|
| 19 | +# from pygments.styles import get_all_styles |
20 | 20 | from manim.constants import * |
21 | 21 | from manim.mobject.geometry.arc import Dot |
22 | 22 | from manim.mobject.geometry.polygram import RoundedRectangle |
|
25 | 25 | from manim.mobject.types.vectorized_mobject import VGroup |
26 | 26 | from manim.utils.color import WHITE |
27 | 27 |
|
28 | | -__all__ = ["Code"] |
29 | | - |
30 | 28 |
|
31 | 29 | class Code(VGroup): |
32 | 30 | """A highlighted source code listing. |
@@ -63,7 +61,7 @@ class Code(VGroup): |
63 | 61 | background_stroke_width=1, |
64 | 62 | background_stroke_color=WHITE, |
65 | 63 | insert_line_no=True, |
66 | | - style=Code.styles_list[15], |
| 64 | + style="emacs", |
67 | 65 | background="window", |
68 | 66 | language="cpp", |
69 | 67 | ) |
@@ -127,7 +125,9 @@ def construct(self): |
127 | 125 | line_no_buff |
128 | 126 | Defines the spacing between line numbers and displayed code. Defaults to 0.4. |
129 | 127 | style |
130 | | - Defines the style type of displayed code. You can see possible names of styles in with :attr:`styles_list`. Defaults to ``"vim"``. |
| 128 | + Defines the style type of displayed code. To see a list possible |
| 129 | + names of styles call :meth:`get_styles_list`. |
| 130 | + Defaults to ``"vim"``. |
131 | 131 | language |
132 | 132 | Specifies the programming language the given code was written in. If ``None`` |
133 | 133 | (the default), the language will be automatically detected. For the list of |
@@ -156,7 +156,7 @@ def construct(self): |
156 | 156 | # For more information about pygments.lexers visit https://pygments.org/docs/lexers/ |
157 | 157 | # from pygments.lexers import get_all_lexers |
158 | 158 | # all_lexers = get_all_lexers() |
159 | | - styles_list = list(get_all_styles()) |
| 159 | + _styles_list_cache: list[str] | None = None |
160 | 160 | # For more information about pygments.styles visit https://pygments.org/docs/styles/ |
161 | 161 |
|
162 | 162 | def __init__( |
@@ -288,6 +288,20 @@ def __init__( |
288 | 288 | ) |
289 | 289 | self.move_to(np.array([0, 0, 0])) |
290 | 290 |
|
| 291 | + @classmethod |
| 292 | + def get_styles_list(cls): |
| 293 | + """Get list of available code styles. |
| 294 | +
|
| 295 | + Returns |
| 296 | + ------- |
| 297 | + list[str] |
| 298 | + The list of available code styles to use for the ``styles`` |
| 299 | + argument. |
| 300 | + """ |
| 301 | + if cls._styles_list_cache is None: |
| 302 | + cls._styles_list_cache = list(styles.get_all_styles()) |
| 303 | + return cls._styles_list_cache |
| 304 | + |
291 | 305 | def _ensure_valid_file(self): |
292 | 306 | """Function to validate file.""" |
293 | 307 | if self.file_name is None: |
|
0 commit comments