ronisbr / PrettyTables.jl

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

When precompiling without a terminal support reset crayon string is blank #246

Open ktdq opened 1 week ago

ktdq commented 1 week ago

const _reset_crayon_str = string(_reset_crayon) is evaluated during precompilation of the package. But when there's no terminal support it becomes an empty string. When loaded afterwards with a proper terminal it fails to draw things correctly.

Need to ensure that the initialization of _reset_crayon_str occurs at runtime rather than at compile time.

ronisbr commented 1 week ago

Thanks @ktdq ! Do you have any MWE so that I can test?

ktdq commented 1 week ago

Something along these lines:

$ ssh localhost 'julia -e "using PrettyTables; @show(string(PrettyTables._reset_crayon))"' < /dev/null > out 2>&1
$ sleep 5
$ cat out
string(PrettyTables._reset_crayon) = ""
$ julia -e "using PrettyTables; @show(string(PrettyTables._reset_crayon))"
string(PrettyTables._reset_crayon) = "\e[0m"

I use ssh to precompile on a cluster, and there's no terminal...

ktdq commented 1 week ago

What is wrong with just hardcoding the string?

const _reset_crayon_str = "\e[0m"
ronisbr commented 1 week ago

Hum, that will be difficult to reproduce in the CI. Maybe hardcoding the string is the only safe solution then.

ktdq commented 1 week ago

Just tried, hardcoding doesn't work when there's no terminal. You really want an empty string in this case otherwise you have extra escape codes in otherwise plain text output.

ktdq commented 1 week ago

The only safe way is to remove _reset_crayon_str completely and let Crayon.jl logic figure out if _reset_crayon should print anything or not.

ronisbr commented 1 week ago

Ok, thanks.