Skip to content

Commit

Permalink
Use a Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 5, 2024
1 parent 6108fee commit 6bc24cd
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1386,11 +1386,7 @@ end
#
################################################################################

@static if VERSION < v"1.8.0-DEV.1465"
ALLOW_UNICODE_OVERRIDE_VALUE = nothing
else
ALLOW_UNICODE_OVERRIDE_VALUE::Union{Bool,Nothing} = nothing
end
const ALLOW_UNICODE_OVERRIDE_VALUE = Ref{Union{Bool,Nothing}}(nothing)

@doc """
allow_unicode(allowed::Bool; temporary::Bool=false) -> Bool
Expand All @@ -1408,12 +1404,12 @@ function allow_unicode(allowed::Bool; temporary::Bool=false)
global ALLOW_UNICODE_OVERRIDE_VALUE
if temporary
old_allowed = is_unicode_allowed()
ALLOW_UNICODE_OVERRIDE_VALUE = allowed
ALLOW_UNICODE_OVERRIDE_VALUE[] = allowed
return old_allowed
else
old_allowed = is_unicode_allowed()
@set_preferences!("unicode" => allowed)
ALLOW_UNICODE_OVERRIDE_VALUE = nothing
ALLOW_UNICODE_OVERRIDE_VALUE[] = nothing
return old_allowed
end
end
Expand All @@ -1425,7 +1421,7 @@ Return whether unicode characters are allowed in pretty printing.
"""
function is_unicode_allowed()
global ALLOW_UNICODE_OVERRIDE_VALUE
override = ALLOW_UNICODE_OVERRIDE_VALUE
override = ALLOW_UNICODE_OVERRIDE_VALUE[]
!isnothing(override) && return override
return @load_preference("unicode", default = false)::Bool
end
Expand All @@ -1446,13 +1442,13 @@ end
"""
function with_unicode(f::Function, allowed::Bool=true)
global ALLOW_UNICODE_OVERRIDE_VALUE
previous = ALLOW_UNICODE_OVERRIDE_VALUE
ALLOW_UNICODE_OVERRIDE_VALUE = allowed
previous = ALLOW_UNICODE_OVERRIDE_VALUE[]
ALLOW_UNICODE_OVERRIDE_VALUE[] = allowed
try
f()
finally
@assert ALLOW_UNICODE_OVERRIDE_VALUE == allowed
ALLOW_UNICODE_OVERRIDE_VALUE = previous
@assert ALLOW_UNICODE_OVERRIDE_VALUE[] == allowed
ALLOW_UNICODE_OVERRIDE_VALUE[] = previous
end
end

Expand Down

0 comments on commit 6bc24cd

Please sign in to comment.