Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 2, 2024
1 parent 0b5aa58 commit 3cda20d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1393,28 +1393,28 @@ else
end

@doc """
allow_unicode(flag::Bool; temporary::Bool=false) -> Bool
allow_unicode(allowed::Bool; temporary::Bool=false) -> Bool
Set whether unicode characters are allowed in pretty printing and returns the
previous value.
If `temporary` is `true`, then the change is only active for the current worker and session.
Otherwise, the change is permanently saved in the preferences.
A permanent change will always override a temporary change.
This function may behave arbitrarily, if called from within an argument to
`with_unicode`.
This function may behave arbitrarily if called from within the scope of a
`with_unicode` do-block.
"""
function allow_unicode(flag::Bool; temporary::Bool=false)
function allow_unicode(allowed::Bool; temporary::Bool=false)
global ALLOW_UNICODE_OVERRIDE_VALUE
if temporary
old_flag = is_unicode_allowed()
ALLOW_UNICODE_OVERRIDE_VALUE = flag
return old_flag
old_allowed = is_unicode_allowed()
ALLOW_UNICODE_OVERRIDE_VALUE = allowed
return old_allowed

Check warning on line 1412 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1407-L1412

Added lines #L1407 - L1412 were not covered by tests
else
old_flag = is_unicode_allowed()
@set_preferences!("unicode" => flag)
old_allowed = is_unicode_allowed()
@set_preferences!("unicode" => allowed)
ALLOW_UNICODE_OVERRIDE_VALUE = nothing
return old_flag
return old_allowed

Check warning on line 1417 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1414-L1417

Added lines #L1414 - L1417 were not covered by tests
end
end

Expand All @@ -1425,25 +1425,33 @@ Return whether unicode characters are allowed in pretty printing.
"""
function is_unicode_allowed()
global ALLOW_UNICODE_OVERRIDE_VALUE
value = ALLOW_UNICODE_OVERRIDE_VALUE
!isnothing(value) && return value
override = ALLOW_UNICODE_OVERRIDE_VALUE
!isnothing(override) && return override
return @load_preference("unicode", default = false)::Bool

Check warning on line 1430 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1427-L1430

Added lines #L1427 - L1430 were not covered by tests
end

@doc """
with_unicode(f::Function, flag::Bool=true)
with_unicode(f::Function, allowed::Bool=true)
Temporarily set whether unicode characters are allowed in pretty printing
during the execution of `f`.
This is useful for e.g. running doctests independently on the user preference.
`with_unicode` is expected to be called in the following way:
```julia
with_unicode([allowed]) do
# code that should be executed with unicode allowed/disallowed
end
```
"""
function with_unicode(f::Function, flag::Bool=true)
function with_unicode(f::Function, allowed::Bool=true)
global ALLOW_UNICODE_OVERRIDE_VALUE
previous = ALLOW_UNICODE_OVERRIDE_VALUE
ALLOW_UNICODE_OVERRIDE_VALUE = flag
ALLOW_UNICODE_OVERRIDE_VALUE = allowed
try
f()

Check warning on line 1452 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1447-L1452

Added lines #L1447 - L1452 were not covered by tests
finally
@assert ALLOW_UNICODE_OVERRIDE_VALUE == flag
@assert ALLOW_UNICODE_OVERRIDE_VALUE == allowed
ALLOW_UNICODE_OVERRIDE_VALUE = previous

Check warning on line 1455 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1454-L1455

Added lines #L1454 - L1455 were not covered by tests
end
end
Expand Down

0 comments on commit 3cda20d

Please sign in to comment.