yunabe / tslab

Interactive JavaScript and TypeScript programming with Jupyter
Apache License 2.0
733 stars 45 forks source link

Disable ANSI colorization in output by default? #31

Open bolinfest opened 4 years ago

bolinfest commented 4 years ago

If I run console.log(55), the Jupyter message I get back is a stdout stream with the contents "\u001b[33m55\u001b[39m\n" because of the ANSI escapes for colorization. I was hoping to get "55\n" just like I would if I did print(55) in a Python kernel.

yunabe commented 4 years ago

In my environment, Jupyter notebook/lab handles ANSI escape colors and show colorful texts in browsers.

e.g. https://nbviewer.jupyter.org/github/yunabe/tslab-examples/blob/master/notebooks/getting_started.ipynb

Screen Shot 2020-04-26 at 9 44 24 PM

What is shown in your Jupyter environment for console.log(55)?

bolinfest commented 4 years ago

I am not using the stock Jupyter notebook/lab for my presentation layer.

I use https://www.npmjs.com/package/ansi-to-html to render ANSI output for errors, which works fine because you get the entire error at once. I do not believe it works well for streaming output, though. For example, in my original example, suppose you received the output in two chunks: "\u001b[33" and "m55\u001b[39m\n". How would you ensure it is displayed correctly as you receive each chunk of the stream?

It's doable, but it's not simple. Output that is free of ANSI characters is much easier to deal with because you can just keep appending to the innerText of the DOM element used to display it.