Skip to content

Commit

Permalink
Compatibility with older Julia versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock committed Dec 1, 2024
1 parent cd9422e commit 31146fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,17 @@ superscript(i::Integer) = map(repr(i)) do c
error("unexpected character")
end

if isdefined(Base, :alignment_from_show)
printed_length(io, x) = Base.alignment_from_show(io, x)
else
printed_length(io, x) = length(sprint(show, x, context=io))
end

function Base.alignment(io::IO, x::Quantity)
if isunitless(unit(x))
return Base.alignment(io, x.val)
end
length = Base.alignment_from_show(io, x)
length = printed_length(io, x)
left, _ = Base.alignment(io, x.val)
left += BracketStyle(x.val) != NoBrackets()
return left, length - left
Expand Down
4 changes: 2 additions & 2 deletions src/logarithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ function Base.show(io::IO, x::Level)
end

function Base.alignment(io::IO, x::Gain)
length = Base.alignment_from_show(io, x)
length = printed_length(io, x)
left, _ = Base.alignment(io, x.val)
return left, length - left
end
function Base.alignment(io::IO, x::Level)
length = Base.alignment_from_show(io, x)
length = printed_length(io, x)
left, _ = Base.alignment(io, ustrip(x))
return left, length - left
end
Expand Down

0 comments on commit 31146fa

Please sign in to comment.