diff --git a/src/display.jl b/src/display.jl index 249ad93f..f3029f1a 100644 --- a/src/display.jl +++ b/src/display.jl @@ -44,10 +44,6 @@ function prefix(x::Unit) end end -function show(io::IO, x::Unit{N,D}) where {N,D} - show(io, FreeUnits{(x,), D, nothing}()) -end - abstract type BracketStyle end struct NoBrackets <: BracketStyle end @@ -89,7 +85,7 @@ brackets are not printed. """ function showval(io::IO, x::Number, brackets::Bool=true) brackets && print_opening_bracket(io, x) - show(io, x) + show(io, MIME"text/plain"(), x) brackets && print_closing_bracket(io, x) end @@ -107,20 +103,10 @@ has_unit_spacing(u) = true has_unit_spacing(u::Units{(Unit{:Degree, NoDims}(0, 1//1),), NoDims}) = false """ - show(io::IO, x::Quantity) + show(io::IO, mime::MIME"text/plain", x::Quantity) Show a unitful quantity by calling [`showval`](@ref) on the numeric value, appending a space, and then calling `show` on a units object `U()`. """ -function show(io::IO, x::Quantity) - if isunitless(unit(x)) - showval(io, x.val, false) - else - showval(io, x.val, true) - has_unit_spacing(unit(x)) && print(io, ' ') - show(io, unit(x)) - end -end - function show(io::IO, mime::MIME"text/plain", x::Quantity) if isunitless(unit(x)) showval(io, mime, x.val, false) @@ -131,30 +117,30 @@ function show(io::IO, mime::MIME"text/plain", x::Quantity) end end -function show(io::IO, r::Union{StepRange{T},StepRangeLen{T}}) where T<:Quantity +function show(io::IO, mime::MIME"text/plain", r::Union{StepRange{T},StepRangeLen{T}}) where T<:Quantity a,s,b = first(r), step(r), last(r) U = unit(a) print(io, '(') if ustrip(U, s) == 1 - show(io, ustrip(U, a):ustrip(U, b)) + show(io, mime, ustrip(U, a):ustrip(U, b)) else - show(io, ustrip(U, a):ustrip(U, s):ustrip(U, b)) + show(io, mime, ustrip(U, a):ustrip(U, s):ustrip(U, b)) end print(io, ')') has_unit_spacing(U) && print(io,' ') - show(io, U) + show(io, mime, U) end -function show(io::IO, x::typeof(NoDims)) +function show(io::IO, ::MIME"text/plain", x::typeof(NoDims)) print(io, "NoDims") end """ - show(io::IO, x::Unitlike) + show(io::IO, ::MIME"text/plain", x::Unitlike) Call [`Unitful.showrep`](@ref) on each object in the tuple that is the type variable of a [`Unitful.Units`](@ref) or [`Unitful.Dimensions`](@ref) object. """ -function show(io::IO, x::Unitlike) +function show(io::IO, ::MIME"text/plain", x::Unitlike) showoperators = get(io, :showoperators, false) first = "" sep = showoperators ? "*" : " " diff --git a/src/logarithm.jl b/src/logarithm.jl index 58d76beb..a9d9daa4 100644 --- a/src/logarithm.jl +++ b/src/logarithm.jl @@ -84,11 +84,11 @@ tolog(L,x) = (1+isrootpower(L)) * prefactor(L()) * (logfn(L()))(x) fromlog(L,S,x) = unwrap(S) * expfn(L())( x / ((1+isrootpower(S))*prefactor(L())) ) fromlog(L,x) = expfn(L())( x / ((1+isrootpower(L))*prefactor(L())) ) -function Base.show(io::IO, x::MixedUnits{T,U}) where {T,U} +function Base.show(io::IO, mime::MIME"text/plain", x::MixedUnits{T,U}) where {T,U} print(io, abbr(x)) if x.units != NoUnits print(io, " ") - show(io, x.units) + show(io, mime, x.units) end end @@ -312,11 +312,11 @@ function Base.promote_rule(::Type{G}, ::Type{N}) where {L,S,T1, G<:Gain{L,S,T1}, end Base.promote_rule(A::Type{G}, B::Type{L}) where {G<:Gain, L2, L<:Level{L2}} = LogScaled{L2} -function Base.show(io::IO, x::Gain) +function Base.show(io::IO, mime::MIME"text/plain", x::Gain) print(io, x.val, " ", abbr(x)) nothing end -function Base.show(io::IO, x::Level) +function Base.show(io::IO, mime::MIME"text/plain", x::Level) print(io, ustrip(x), " ", abbr(x)) nothing end diff --git a/src/types.jl b/src/types.jl index 05b76f61..2d87469e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -273,7 +273,7 @@ struct IsRootPowerRatio{S,T} val::T end IsRootPowerRatio{S}(x) where {S} = IsRootPowerRatio{S, typeof(x)}(x) -Base.show(io::IO, x::IsRootPowerRatio{S}) where {S} = +Base.show(io::IO, ::MIME"text/plain", x::IsRootPowerRatio{S}) where {S} = print(io, ifelse(S, "root-power ratio", "power ratio"), " with reference ", x.val) const PowerRatio{T} = IsRootPowerRatio{false,T} const RootPowerRatio{T} = IsRootPowerRatio{true,T}