Open pfitzseb opened 3 years ago
Do you have an example package for us to test? Since we don't support stdout, I'm not sure if there's enough reason to add it
IIRC this came up on Slack with a reference to MLJ.jl, but technically outputting ANSI color codes in show
methods without the user/IOContext
asking for it is wrong. Would still be kinda neat though, imho :)
Hmmmmm but we also have HTML! Who wants ANSI colors if you can have <marquee>
and font-family: "Comic Sans MS"
? βΊοΈ
True true. This is only relevant for code ignorant of the (questionable) beauty of HTML ;)
I don't think it's worth the effort! But counterexamples are welcome
So, if you are writing applications that normally work with the terminal, ANSI colours are rather obvious thing to do. Converting pre-formatted text + ANSI colours to HTML, like Jupyter does, seems like an obvious gap that Pluto has. Asking each library to write their own HTML formatter to get colour seems... like the wrong separation of concerns.
...
Here is concrete use case for FunSQL.jl -- when you use the console, in the display of q
you'll see that the 1st Get.person_id
is coloured blue. In the display of render(q)
you'll notice that the second Get.person_id
is highlighted in red. In both cases, the output has indentation which is helpful for readability.
(@v1.6) pkg> add FunSQL
julia> using FunSQL: From, Select, Get, Highlight, SQLTable, render
julia> person = SQLTable(:person, columns = [:person_id])
SQLTable(:person, columns = [:person_id])
julia> q = From(person) |>
Select(Get.person_id |> Highlight(:blue), Get.person_id)
let person = SQLTable(:person, β¦),
q1 = From(person),
q2 = q1 |> Select(Get.person_id, Get.person_id)
q2
end
julia> render(q)
ERROR: DuplicateAliasError: person_id in:
let person = SQLTable(:person, β¦),
q1 = From(person),
q2 = q1 |> Select(Get.person_id, Get.person_id)
q2
end
Stacktrace:
...
If you type this same into Pluto, you'll notice that the display of q
is indented but that the blue highlight for the 1st Get.person_id
is missing. In the display of render(q)
you'll notice that indentation is lost, and there is no red highlighting of the 2nd Get.person_id
.
Take a peek at how we supported colour in the package installation terminal: https://github.com/fonsp/Pluto.jl/blob/main/frontend/components/PkgTerminalView.js
I found this while using programs designed for the terminal, distributed in the Julia ecosystem as jll packages. For example:
# βββ‘ 4c4d8eaa-87ae-4f2b-8f33-4cced2cc824c
using FastME_jll
# βββ‘ 0505615f-bf25-4316-923e-eb4dcef34129
fastme() do _fastme
run(`$_fastme -h`)
end
Here the problem is not only color code but also bold character and other things I have no idea about: Pluto:
Terminal:
Adding a vote for terminal color support. For user experience, there are only positives:
text/html
As an example of the latter, here's BifurcationKit.jl; compare the raw output to the one that's captured from stdout using print
(I'll try to make a PR to BifurcationKit):
Another classic example would be BenchmarkTools.jl which is probably one of the most used packages out there in the ecosystem.
The lack of colour in the regular display is pretty painful, and the purposefully ugly terminal display for stdout is also a bit hard to look at compared to how it looks in a regularly set up REPL:
It should be easy to implement! Take a look at how we implemented color in https://github.com/fonsp/Pluto.jl/blob/main/frontend/components/PkgTerminalView.js for inspiration, feel free to make a PR!
Would be cool to render ANSI color codes in text (and maybe even rich) output.