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

ANSI color code rendering in output #894

Open
pfitzseb opened this issue Feb 4, 2021 · 10 comments
Open

ANSI color code rendering in output #894

pfitzseb opened this issue Feb 4, 2021 · 10 comments
Labels
display & PlutoRunner & AbstractPlutoDingetjes.jl good first issue Good for newcomers other packages Integration with other Julia packages

Comments

@pfitzseb
Copy link

pfitzseb commented Feb 4, 2021

Would be cool to render ANSI color codes in text (and maybe even rich) output.

@fonsp
Copy link
Owner

fonsp commented Feb 8, 2021

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

@pfitzseb
Copy link
Author

pfitzseb commented Feb 8, 2021

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

@fonsp
Copy link
Owner

fonsp commented Feb 8, 2021

Hmmmmm but we also have HTML! Who wants ANSI colors if you can have <marquee> and font-family: "Comic Sans MS"? ☺️

@pfitzseb
Copy link
Author

pfitzseb commented Feb 8, 2021

True true. This is only relevant for code ignorant of the (questionable) beauty of HTML ;)

@fonsp
Copy link
Owner

fonsp commented Mar 4, 2021

I don't think it's worth the effort! But counterexamples are welcome

@fonsp fonsp closed this as completed Mar 4, 2021
@fonsp
Copy link
Owner

fonsp commented Apr 7, 2021

#983

@clarkevans
Copy link

clarkevans commented Apr 7, 2021

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.

@fonsp fonsp reopened this Apr 12, 2021
@fonsp fonsp added display & PlutoRunner & AbstractPlutoDingetjes.jl other packages Integration with other Julia packages labels Apr 13, 2021
@fonsp
Copy link
Owner

fonsp commented Sep 7, 2021

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

@diegozea
Copy link
Contributor

diegozea commented Jun 1, 2022

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:
image

Terminal:

image

@danielwe
Copy link
Contributor

Adding a vote for terminal color support. For user experience, there are only positives:

  • Enabling colors when packages implement terminal colors but not text/html
  • Avoiding garbled display when packages don't check the IOContext as they should (packages should be fixed too, but this would be a pragmatic and harmless band-aid)

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

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display & PlutoRunner & AbstractPlutoDingetjes.jl good first issue Good for newcomers other packages Integration with other Julia packages
Projects
None yet
Development

No branches or pull requests

5 participants