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

vscode-jupyter does not show ANSI color codes when using the output widget #3957

Open
raldone01 opened this issue Oct 21, 2024 · 4 comments
Open

Comments

@raldone01
Copy link

Description

Ansi color codes are stripped and no color is shown in output captured by the output widget.

Reproduce

import ipywidgets as widgets

print("\033[91mHello World\033[0m")
output = widgets.Output()
output.append_stdout("\033[91mHello World\033[0m")
output

image

Expected behavior

Both lines are colored red.

Context

  • ipywidgets version 8.1.5
  • Operating System and version: WIN11
  • Browser and version: VSCODE
@mvanderlee
Copy link

I think this is a VSCode issue.

If I change the representation to text I see the ANSI codes:

Output(outputs=({'output_type': 'stream', 'name': 'stdout', 'text': '\x1b[91mHello World\x1b[0m'},))

Image

@mvanderlee
Copy link

It even has the right classes, but for some reason the style sheet appears to be missing:
https://github.com/jupyterlab/jupyterlab/blob/main/packages/rendermime/style/base.css#L126

Image

@mvanderlee
Copy link

Workaround: Import the missing stylesheet manually.

from IPython.display import HTML
from urllib.request import urlopen
html = urlopen("https://raw.githubusercontent.com/jupyterlab/jupyterlab/refs/heads/main/packages/rendermime/style/base.css")
HTML(f"<style>{html.read().decode('utf-8')}</style>")

@raldone01
Copy link
Author

Awesome thanks for tracking this down. I hope upstream vscode fixes this soon. Colorful logs here I come!

@raldone01 raldone01 changed the title ANSI color codes are stripped when using the output widget Vscode-jupyter does not show ANSI color codes when using the output widget Mar 26, 2025
@raldone01 raldone01 changed the title Vscode-jupyter does not show ANSI color codes when using the output widget vscode-jupyter does not show ANSI color codes when using the output widget Mar 26, 2025
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

2 participants