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

Colorful printing #181

Open
MilesCranmer opened this issue Mar 17, 2023 · 5 comments
Open

Colorful printing #181

MilesCranmer opened this issue Mar 17, 2023 · 5 comments
Labels
feature (importance: low) Low-importance feature

Comments

@MilesCranmer
Copy link
Owner

It could be nice to have colorful printouts of equations, with colored parentheses indicating level of nestedness, similar to OhMyREPL.jl.

@khdlr do you know if ProgressBars.jl set_multiline_postfix would support colors?

@khdlr
Copy link

khdlr commented Mar 20, 2023

Currently, ANSI escape codes will already work, e.g.

iter = ProgressBar(1:100)
for i in iter
  # ...
  set_multiline_postfix(iter, "\u001b[31mred: \u001b[32mgreen\u001b[37m")
end

However, this is not a great API to program around and might not work on windows platforms either. I guess the best way to go about this is for ProgressBars.jl to also accept a Crayon instead of a string for methods like set_postfix, set_multiline_postfix, etc.

Just realized that Crayons.jl is by the same author as OhMyREPL.jl, so it's likely what they are using there as well.

@MilesCranmer
Copy link
Owner Author

Awesome. Thanks! I didn't realize it would be that simple. I'm happy with that as-is, it seems like this works well and isn't much work at all to interface:

for i in iter
    set_multiline_postfix(iter, "$(Crayon(foreground=:red))In red: $i$(Crayon(reset=true))")
    sleep(0.01)
end

It will be cool to have different colors for each column of the output and also for nested expressions!

@khdlr
Copy link

khdlr commented Mar 20, 2023

Okay that's convenient, I guess we won't need a new API from the ProgressBars.jl side for that then.

The ANSI escapes will currently mess up the character-counting for the multiline_postfix:

for i in iter
    set_multiline_postfix(iter, "$(Crayon(foreground=:red))In red: $i$(Crayon(reset=true))\nsecond line")
    sleep(0.01)
end

Currently working on fixing that with some regex-magic 😃

@khdlr
Copy link

khdlr commented Mar 20, 2023

Just released v1.5.0 that fixes colorful multiline postfixes

@MilesCranmer
Copy link
Owner Author

That was fast 🤯 nice work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature (importance: low) Low-importance feature
Projects
None yet
Development

No branches or pull requests

2 participants