Skip to content
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

Syntax highlighting of traceback context always uses default Pygments style #13953

Closed
li-dan opened this issue Feb 26, 2023 · 1 comment
Closed

Comments

@li-dan
Copy link

li-dan commented Feb 26, 2023

We have TerminalInteractiveShell.highlighting_style to pick a Pygments style for normal syntax highlighting, but tracebacks always use the default style:

if self.has_colors:
style = get_style_by_name("default")
style = stack_data.style_with_executing_node(style, self._tb_highlight)
formatter = Terminal256Formatter(style=style)

Similar to #13756 for mitigating #13446 and #13486, would it be possible to put in a stop-gap to allow the user to change the style?

$ git diff
diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py
index 18eff2708..030dea717 100644
--- a/IPython/core/ultratb.py
+++ b/IPython/core/ultratb.py
@@ -617,6 +617,7 @@ class VerboseTB(TBTools):
     would appear in the traceback)."""

     _tb_highlight = "bg:ansiyellow"
+    _tb_highlight_style = "default"

     def __init__(
         self,
@@ -841,7 +842,7 @@ class VerboseTB(TBTools):
         after = context // 2
         before = context - after
         if self.has_colors:
-            style = get_style_by_name("default")
+            style = get_style_by_name(self._tb_highlight_style)
             style = stack_data.style_with_executing_node(style, self._tb_highlight)
             formatter = Terminal256Formatter(style=style)
         else:
li-dan pushed a commit to li-dan/ipython that referenced this issue Aug 14, 2023
Similar to ipython#13756, add a hack to configure the Pygments style for
syntax highlighting of tracebacks.

This does not change default behavior.

To use the hack, add to ipython_config.py:

    from IPython.core.ultratb import VerboseTB
    VerboseTB._tb_highlight_style = "pastie"

Mitigates ipython#13953.
Carreau added a commit that referenced this issue Aug 28, 2023
Similar to #13756, add a hack to configure the Pygments style for syntax
highlighting of tracebacks.

This does not change default behavior.

To use the hack, add to ipython_config.py:

    from IPython.core.ultratb import VerboseTB
    VerboseTB._tb_highlight_style = "pastie"

Mitigates #13953.
@li-dan
Copy link
Author

li-dan commented Aug 28, 2023

Closing as the patch has been merged to main.

@li-dan li-dan closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant