Skip to content

Commit

Permalink
more fixes for printing with custom units
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 committed Oct 23, 2020
1 parent 0996462 commit 463a5ff
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ end
function Base.show(io::IO, sp::Spec{T}) where T
print(io,"spec(")


a = value(sp)
units = default_units(T)

Expand All @@ -140,18 +139,23 @@ function Base.show(io::IO, sp::Spec{T}) where T
end

function print_long_spec(io::IO, sp::Spec{T}) where T
print_spec(io,T)
print(io," : ")
a = value(sp)
print(io,a)
if is_real(a)
units = default_units(T)
if !(units == Unitful.NoUnits)
printstyled(io,'[',color = :light_black)
print(IOContext(io,:compact => true),units)
printstyled(io,']',color = :light_black)
end
end
print_spec(io,T)
print(io," : ")
a = value(sp)
units = default_units(T)

if is_unitful(a)
units = unit(a)
a = ustrip(a)
end
print(io,a)
if is_real(a)
if !(units == Unitful.NoUnits)
printstyled(io,'[',color = :light_black)
print(IOContext(io,:compact => true),units)
printstyled(io,']',color = :light_black)
end
end
end


Expand Down Expand Up @@ -229,9 +233,13 @@ function Base.show(io::IO, sp::ThermodynamicState)
(i !=1) && print(io,", ")
print(io,string(SPEC_TO_KW[specification(spec)])," = ")
a = value(spec)
units = default_units(typeof(specification(spec)))
if is_unitful(a)
units = unit(a)
a = ustrip(a)
end
if is_real(a)
print(IOContext(io,:compact => true),a)
units = default_units(typeof(specification(spec)))
if !(units == Unitful.NoUnits)
printstyled(io,'[',color = :light_black)
print(IOContext(io,:compact => true),units)
Expand Down

0 comments on commit 463a5ff

Please sign in to comment.