fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.96k stars 286 forks source link

Printing issue with ASCII colour characters #983

Closed chenspc closed 3 years ago

chenspc commented 3 years ago

I ran into a printing problem when using Configuration.jl in Pluto. See also Roger-luo/Configurations.jl#18. The package author said

haha, this is because Pluto doesn't support ASCII color characters - would be nice if Pluto supports it.

Is this something that will be added in the future, or are there any suggested workarounds? Thanks!

extra_characters
fonsp commented 3 years ago

Hey! Pluto does not support ASCII color characters (since it is not a terminal), which we declare using the IOContext. (We won't support color characters because we support HTML+CSS output.) Packages should use the IOContext to find out whether colored printing is supported, before writing ANSI codes to the io stream.

Take a look at a very similar PR that I submitted https://github.com/SciML/SciMLBase.jl/pull/30. Note that for this PR, I tried to minimize code changes, but ideally you would use Base.printstyled or Crayons.jl to make this automatic. (At least, I assume that these handle the :color setting, I haven't tried it.)

In the particular case of Configurations.jl: Note that Pluto has a really nice built-in viewer for structs, which uses similar color and indentation, except you can collapse the tree. You might want to consider disabling the custom show method inside Pluto. (The official way is to use isdefined(Main, :PlutoRunner) to check for Plutoness)

@Roger-luo

fonsp commented 3 years ago

It looks like this is an issue with Crayons.jl -- it should check the :color setting.

Roger-luo commented 3 years ago

I haven't looked into this, but I'm thinking to provide a show method for HTML specifically which should solve this problem.

On the other hand, we should file an issue for Crayons?