Show richer type parameter information

This commit is contained in:
TEC 2024-04-08 23:18:32 +08:00
parent 40f29a9bd0
commit 4cef33ae79
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
2 changed files with 11 additions and 6 deletions

View File

@ -54,9 +54,10 @@ function about(io::IO, type::Type)
print(Base.summary(type))
print(io, styled" defined in {about_module:$(parentmodule(type))}, ")
hassizeof(type) && print(io, "$(join(humansize(sizeof(type))))")
println(io, "\n ", supertypestr(type))
print(io, "\n ")
supertypeinfo(io, type)
(!isstructtype(type) || fieldcount(type) == 0) && return
println(io, styled"\nStruct with {bold:$(fieldcount(type))} fields:")
println(io, styled"\n\nStruct with {bold:$(fieldcount(type))} fields:")
fieldinfo = AnnotatedString[]
if type isa DataType
sinfo = structinfo(type)
@ -80,8 +81,11 @@ function about(io::IO, type::Type)
end
end
supertypestr(type::Type) =
join(string.(supertypes(type)), styled" {julia_comparator:<:} ")
function supertypeinfo(io::IO, type::Type)
typestr(t) = highlight(sprint(show, Base.unwrap_unionall(t)))
join(io, map(typestr, supertypes(type)),
styled" {julia_comparator:<:} ")
end
function memorylayout(io::IO, type::DataType)
si = structinfo(type)

View File

@ -13,8 +13,9 @@ function about(io::IO, value::T) where {T}
if indirectbytes > directbytes
print(io, styled" referencing {bold:$(join(humansize(indirectbytes)))}")
end
print(io, styled" ({julia_comparator:<:} ", supertypestr(supertype(T)), ")")
println(io)
print(io, styled" ({julia_comparator:<:} ")
supertypeinfo(io, supertype(T))
println(io, ")")
memorylayout(io, value)
end