ronisbr / PrettyTables.jl

Print data in formatted tables.
MIT License
404 stars 38 forks source link

Export as PNG or JPEG or any image #213

Closed Roh-codeur closed 10 months ago

Roh-codeur commented 1 year ago

Hi

this is truly an awesome package.

qq: is there a way to export the generated output to image please? I want to post it to Slack using code, unfortunately, as Text it loses all highlights and formatting.

thanks Roh

ronisbr commented 1 year ago

Hi @Roh-codeur

Thanks! I am glad it is being useful :)

Do you mean generate a PNG from the terminal output?

Roh-codeur commented 1 year ago

@ronisbr : hey mate, thanks for coming back. yeah indeed, I have a beautiful output generated using PrettyTables.jl. I want to be able to export this output to png, so I can send this to Slack.

ta!

ronisbr commented 1 year ago

In this case, we need some external tool that renders the escape sequences into a PNG. I did this in the past using a combination of aha, wkhtmltopdf, and convert. However, it was so complicated that the best way is just to take a screenshot of your terminal.

ronisbr commented 11 months ago

I am closing this bug since this feature should be handled outside PrettyTables.jl.

ronisbr commented 4 months ago

Hi @Roh-codeur !

I just found and AMAZING tool that will help you to do this. It is called AnsiToImg.

You can obtain the SVG of the PrettyTables.jl output by:

str = pretty_table(
    String,
    [0:10 0:2:20 0:4:40];
    color = true,
    tf = tf_unicode_rounded,
    highlighters = hl_geq(5)
)

write("tmp", str)
run(`ansitoimg --title "Generated by AnsiToImg" tmp output.svg`)
run(`rm tmp`)

leading to:

output