-
Notifications
You must be signed in to change notification settings - Fork 112
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
To certain functions, add the fancy_exponents
kwarg, which allows the user to toggle the "fancy exponents" setting in a thread-safe way
#445
To certain functions, add the fancy_exponents
kwarg, which allows the user to toggle the "fancy exponents" setting in a thread-safe way
#445
Conversation
…he user to toggle the "fancy exponents" setting in a thread-safe way
Codecov Report
@@ Coverage Diff @@
## master #445 +/- ##
==========================================
- Coverage 83.84% 83.80% -0.04%
==========================================
Files 16 16
Lines 1337 1334 -3
==========================================
- Hits 1121 1118 -3
Misses 216 216
Continue to review full report at Codecov.
|
I can't say I'm a fan of using environment variables for this. Why not using IO context instead? |
Sure, that would work. I just didn't want to break the existing behavior of the package. |
I.e. the package already uses the environment variable, so removing it would be a breaking change. |
How using IO context would be different from using an environment variable? You don't break anything, you don't even add any extra arguments |
Ah I think I see what you mean. |
Well just to clarify, we'd use IO contexts instead of the kwarg. The |
Yes, the extra argument is redundant since you can pass extra stuff already from the IO. I use IO context in Measurements.jl, see for example https://github.com/JuliaPhysics/Measurements.jl/blob/master/src/show.jl#L42 and the tests |
It's so much cleaner! I like it. Closing this PR in favor of #446, which uses the IO context property. |
This pull request adds the
fancy_exponents::Bool
kwarg to several methods of the following functions:show
showval
showrep
superscript
We use the fancy Unicode exponents if and only if
fancy_exponents
istrue
.The
fancy_exponents::Bool
kwarg is optional. The default value is determined as follows:fancy_exponents
kwarg, we use that value.UNITFUL_FANCY_EXPONENTS
environment, and the lowercased value parses to aBool
, we use that value.UNITFUL_FANCY_EXPONENTS
environment variable, but the lowercased value does not parse to aBool
, we default tofalse
.true
on macOS andfalse
otherwise.Therefore, if the user does not provide the
fancy_exponents
kwarg, this PR preserves the existing behavior.Motivation
Currently, the only way to control the behavior of the fancy Unicode exponents is by the
UNITFUL_FANCY_EXPONENTS
environment variable. Unfortunately, as far as I understand, there is no thread-safe way to modify the environment while calling a Julia function. (Thewithenv
function is not thread-safe. Theaddenv
function is thread-safe, but as far as I can tell, it only lets you run aCmd
.)The
fancy_exponents
kwarg allows the user to turn fancy Unicode exponents on/off in a thread-safe way.