- Notifications
You must be signed in to change notification settings - Fork 750
Allow ansi color name in Pygments style. #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Hi @Carreau, For this, I don't mind breaking backwards-compatibilty in prompt-toolkit. Ansi colors names have only been added to the latest release of prompt-toolkit, because it was required for pymux. (When an application outputs an ANSI color, instead of using the 256color palette, we wanted to send an ansi color to the terminal as well.) As far as I know, nobody else is really using it. So, I propose to simply rename our colors that they match those of Pygments. Jonathan |
Ok, in progress then. Is that true for Win32. enum class keys as well ? |
| Yes, otherwise this assertion would fail: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/terminal/win32_output.py#L412 |
| ok, done. Seam to work with current master of IPython, that just got the prompt_toolkit PR merged. |
| That's cool. Thank you! I was preparing the new release for prompt-toolkit, but I guess, I'll merge this first. It looks good, but two remarks
Thanks again. |
That will break as pygments does have the Squash in progress. |
| Yes, sure. It should be in the style dictionary in order to be compatible. But the |
| OK, I see. |
| Done. |
| Ok, thanks! I guess, I'll squanch the following change against this commit. Are you fine with that? diff --git a/prompt_toolkit/styles/base.py b/prompt_toolkit/styles/base.py index dbc7c0a..e9ddaa5 100644 --- a/prompt_toolkit/styles/base.py +++ b/prompt_toolkit/styles/base.py @@ -18,8 +18,8 @@ __all__ = ( #: Style attributes. Attrs = namedtuple('Attrs', 'color bgcolor bold underline italic blink reverse') """ -:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. '#ansiblue' -:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. '#ansired' +:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue' +:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired' :param bold: Boolean :param underline: Boolean :param italic: Boolean diff --git a/prompt_toolkit/styles/from_dict.py b/prompt_toolkit/styles/from_dict.py index 34e4ace..4f6e224 100644 --- a/prompt_toolkit/styles/from_dict.py +++ b/prompt_toolkit/styles/from_dict.py @@ -28,7 +28,7 @@ def _colorformat(text): col = text[1:] if col in ANSI_COLOR_NAMES: return col - if len(col) == 6: + elif len(col) == 6: return col elif len(col) == 3: return col[0]*2 + col[1]*2 + col[2]*2 diff --git a/prompt_toolkit/terminal/vt100_output.py b/prompt_toolkit/terminal/vt100_output.py index a98e079..4c33a55 100644 --- a/prompt_toolkit/terminal/vt100_output.py +++ b/prompt_toolkit/terminal/vt100_output.py @@ -99,7 +99,6 @@ ANSI_COLORS_TO_RGB = { } - assert set(FG_ANSI_COLORS) == set(ANSI_COLOR_NAMES) assert set(BG_ANSI_COLORS) == set(ANSI_COLOR_NAMES) assert set(ANSI_COLORS_TO_RGB) == set(ANSI_COLOR_NAMES) diff --git a/prompt_toolkit/terminal/win32_output.py b/prompt_toolkit/terminal/win32_output.py index aef4f52..60d8054 100644 --- a/prompt_toolkit/terminal/win32_output.py +++ b/prompt_toolkit/terminal/win32_output.py @@ -382,28 +382,28 @@ class BACKROUND_COLOR: def _create_ansi_color_dict(color_cls): " Create a table that maps the 16 named ansi colors to their Windows code. " return { - '#ansiblack': color_cls.BLACK, - '#ansidefault': color_cls.BLACK, - '#ansiwhite': color_cls.GRAY | color_cls.INTENSITY, + 'ansiblack': color_cls.BLACK, + 'ansidefault': color_cls.BLACK, + 'ansiwhite': color_cls.GRAY | color_cls.INTENSITY, # Low intensity. - '#ansired': color_cls.RED, - '#ansigreen': color_cls.GREEN, - '#ansiyellow': color_cls.YELLOW, - '#ansiblue': color_cls.BLUE, - '#ansifuchsia': color_cls.MAGENTA, - '#ansiturquoise': color_cls.CYAN, - '#ansilightgray': color_cls.GRAY, + 'ansired': color_cls.RED, + 'ansigreen': color_cls.GREEN, + 'ansiyellow': color_cls.YELLOW, + 'ansiblue': color_cls.BLUE, + 'ansifuchsia': color_cls.MAGENTA, + 'ansiturquoise': color_cls.CYAN, + 'ansilightgray': color_cls.GRAY, # High intensity. - '#ansidarkgray': color_cls.BLACK | color_cls.INTENSITY, - '#ansidarkred': color_cls.RED | color_cls.INTENSITY, - '#ansidarkgreen': color_cls.GREEN | color_cls.INTENSITY, - '#ansibrown': color_cls.YELLOW | color_cls.INTENSITY, - '#ansidarkblue': color_cls.BLUE | color_cls.INTENSITY, - '#ansipurple': color_cls.MAGENTA | color_cls.INTENSITY, - '#ansiteal': color_cls.CYAN | color_cls.INTENSITY, + 'ansidarkgray': color_cls.BLACK | color_cls.INTENSITY, + 'ansidarkred': color_cls.RED | color_cls.INTENSITY, + 'ansidarkgreen': color_cls.GREEN | color_cls.INTENSITY, + 'ansibrown': color_cls.YELLOW | color_cls.INTENSITY, + 'ansidarkblue': color_cls.BLUE | color_cls.INTENSITY, + 'ansipurple': color_cls.MAGENTA | color_cls.INTENSITY, + 'ansiteal': color_cls.CYAN | color_cls.INTENSITY, } FG_ANSI_COLORS = _create_ansi_color_dict(FOREGROUND_COLOR) diff --git a/tests/style_tests.py b/tests/style_tests.py index ff9e71c..cd92143 100644 --- a/tests/style_tests.py +++ b/tests/style_tests.py @@ -32,7 +32,7 @@ class StyleFromDictTest(unittest.TestCase): underline=False, italic=False, blink=False, reverse=False) self.assertEqual(style.get_attrs_for_token(Token.A.B.C), expected) - expected = Attrs(color='#ansired', bgcolor=None, bold=True, + expected = Attrs(color='ansired', bgcolor=None, bold=True, underline=False, italic=False, blink=False, reverse=False) self.assertEqual(style.get_attrs_for_token(Token.A.B.C.D), expected) |
| Sure, it's your project, you're the boss. |
this allow using `#ansigreen`,`#ansired`... as pygments color names, and will be matched to 30-37 to ansi escape sequences
| Actually I left 1 |
| And travis is happy. He is all green. |
| Merged in: ab62bee Thanks a lot! |
Hey,
I know that currently you can use vt100 to get GREN/BLUE ... etc, though if you create your own style that should work with pygments, it wont be accepted as these string won't be detected as correct colors.
Pygments recently added the ability to do that, except the names are slightly different, so this (once finished) should allow to have themes that works correctly with both Pygments 2.2+ and Prompt Toolkit and get the correct ansi escape sequences.