Improved singleton value handling in layout

This commit is contained in:
TEC 2024-04-10 18:19:03 +08:00
parent e0025cd0a2
commit b0c7025372
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 6 additions and 5 deletions

View File

@ -78,23 +78,24 @@ function memorylayout(io::IO, value::T) where {T}
push!(ftypes, string(type))
push!(fsizes, join(humansize(size)))
aio = AnnotatedIOBuffer()
if Base.issingletontype(type)
fvalue = getfield(value, name)
if Base.issingletontype(typeof(fvalue))
push!(freprs, styled"{shadow:singleton}")
elseif size == 0
push!(freprs, styled"{error:??}")
elseif ispointer
try
pt = pointer(getfield(value, name))
push!(freprs, styled"{about_pointer,light:$pt}")
pt = pointer(fvalue)
push!(freprs, styled"{about_pointer:@ $(sprint(show, UInt64(pt)))}")
catch
push!(freprs, styled"{about_pointer:Ptr?}")
end
else
memorylayout(IOContext(aio, :compact => true), getfield(value, name))
memorylayout(IOContext(aio, :compact => true), fvalue)
push!(freprs, read(seekstart(aio), AnnotatedString))
end
truncate(aio, 0)
show(IOContext(aio, :compact => true), getfield(value, name))
show(IOContext(aio, :compact => true), fvalue)
push!(fshows, read(seekstart(aio), AnnotatedString))
end
width = last(displaysize(io)) - 2