tslab icon indicating copy to clipboard operation
tslab copied to clipboard

Disable ANSI colorization in output by default?

Open bolinfest opened this issue 4 years ago • 2 comments

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.

bolinfest avatar Apr 25 '20 20:04 bolinfest

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)?

yunabe avatar Apr 26 '20 12:04 yunabe

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.

bolinfest avatar Apr 28 '20 07:04 bolinfest