Use JuliaSyntaxHighlighting for nicer printing
This commit is contained in:
parent
7dd9352d70
commit
d67e9a3bce
|
@ -5,8 +5,10 @@ version = "0.1.0"
|
|||
|
||||
[deps]
|
||||
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
|
||||
JuliaSyntaxHighlighting = "dc6e5ff7-fb65-4e79-a425-ec3bc9c03011"
|
||||
StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
|
||||
|
||||
[compat]
|
||||
InteractiveUtils = "1.11.0"
|
||||
JuliaSyntaxHighlighting = "1.11.0"
|
||||
StyledStrings = "1.11.0"
|
||||
|
|
|
@ -2,6 +2,7 @@ module About
|
|||
|
||||
using Base: AnnotatedString, AnnotatedIOBuffer
|
||||
using StyledStrings: @styled_str, Face, face!
|
||||
using JuliaSyntaxHighlighting: highlight
|
||||
using InteractiveUtils
|
||||
|
||||
export about
|
||||
|
|
|
@ -2,7 +2,8 @@ function about(io::IO, fn::Function)
|
|||
source = Main.InteractiveUtils.which(parentmodule(fn), Symbol(fn))
|
||||
methodmodules = getproperty.(methods(fn).ms, :module)
|
||||
others = setdiff(methodmodules, [source])
|
||||
print(io, Base.summary(fn), styled"\n Defined in {bright_red:$source}")
|
||||
fn_name, fn_extra = split(Base.summary(fn), ' ', limit=2)
|
||||
print(io, styled"{julia_funcall:$fn_name} $fn_extra\n Defined in {bright_red:$source}")
|
||||
if length(others) > 0
|
||||
print(io, styled"{shadow:({emphasis:$(sum(Ref(source) .=== methodmodules))})} extended in ")
|
||||
for (i, oth) in enumerate(others)
|
||||
|
@ -30,7 +31,8 @@ function about(io::IO, fn::Function, @nospecialize(sig::Type{<:Tuple}))
|
|||
about(io, fn); println(io)
|
||||
ms = methods(fn, sig)
|
||||
if isempty(ms)
|
||||
print(io, styled" {error:!} No methods matched $fn($(join(collect(Tuple{Int64, Int64, Int64}.types), \", \")))")
|
||||
fncall = highlight("$fn($(join(collect(sig.types), ", ")))")
|
||||
println(io, styled" {error:!} No methods matched $fncall")
|
||||
return
|
||||
end
|
||||
println(io, styled" Matched {emphasis:$(length(ms))} method$(ifelse(length(ms) > 1, \"s\", \"\")):")
|
||||
|
|
|
@ -83,7 +83,7 @@ function about(io::IO, type::Type)
|
|||
end
|
||||
|
||||
supertypestr(type::Type) =
|
||||
join(string.(supertypes(type)), styled" {red:<:} ")
|
||||
join(string.(supertypes(type)), styled" {julia_comparator:<:} ")
|
||||
|
||||
function memorylayout(io::IO, type::DataType)
|
||||
si = structinfo(type)
|
||||
|
|
|
@ -13,7 +13,7 @@ function about(io::IO, value::T) where {T}
|
|||
if indirectbytes > directbytes
|
||||
print(io, styled" referencing {bold:$(join(humansize(indirectbytes)))}")
|
||||
end
|
||||
print(io, styled" ({red:<:} ", supertypestr(supertype(T)), ")")
|
||||
print(io, styled" ({julia_comparator:<:} ", supertypestr(supertype(T)), ")")
|
||||
println(io)
|
||||
memorylayout(io, value)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue