Skip to content

Commit e4a9af7

Browse files
committed
added print_child_key to print_tree
1 parent 238c835 commit e4a9af7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/printing.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""
22
print_tree(tree; kw...)
33
print_tree(io::IO, tree; kw...)
4-
print_tree(f::Function, io::IO, tree; kw...)
4+
print_tree(f::Function, g::Function, io::IO, tree; kw...)
55
66
Print a text representation of `tree` to the given `io` object.
77
88
# Arguments
99
1010
* `f::Function` - custom implementation of [`printnode`](@ref) to use. Should have the
11-
signature `f(io::IO, node)`.
11+
signature `f(io::IO, node; kw...)`.
12+
* `g::Function` - custom implementation of [`print_child_key`](@ref) to use. Should have the
13+
signature `g(io::IO, key;)`.
1214
* `io::IO` - IO stream to write to.
1315
* `tree` - tree to print.
1416
* `maxdepth::Integer = 5` - truncate printing of subtrees at this depth.
@@ -185,7 +187,7 @@ print_child_key(io::IO, key::CartesianIndex) = show(io, Tuple(key))
185187

186188
branchwidth(cs::TreeCharSet) = sum(textwidth.((cs.mid, cs.dash)))
187189

188-
function print_tree(printnode::Function, io::IO, node;
190+
function print_tree(printnode::Function, print_child_key::Function, io::IO, node;
189191
maxdepth::Integer=5,
190192
indicate_truncation::Bool=true,
191193
charset::TreeCharSet=TreeCharSet(),
@@ -260,14 +262,14 @@ function print_tree(printnode::Function, io::IO, node;
260262
child_prefix *= " " ^ (textwidth(key_str) + textwidth(charset.pair))
261263
end
262264

263-
print_tree(printnode, io, child;
265+
print_tree(printnode, print_child_key, io, child;
264266
maxdepth=maxdepth, indicate_truncation=indicate_truncation, charset=charset,
265267
printkeys=printkeys, depth=depth+1, prefix=child_prefix
266268
)
267269
end
268270
end
269271

270-
print_tree(io::IO, node; kw...) = print_tree(printnode, io, node; kw...)
272+
print_tree(io::IO, node; kw...) = print_tree(printnode, print_child_key, io, node; kw...)
271273
print_tree(node; kw...) = print_tree(stdout, node; kw...)
272274

273275

@@ -279,10 +281,10 @@ Get the string result of calling [`print_tree`](@ref) with the supplied argument
279281
280282
The `context` argument works as it does in `Base.repr`.
281283
"""
282-
repr_tree(tree; context=nothing, kw...) = repr_tree(printnode, tree; context=nothing, kw...)
283-
function repr_tree(f, tree; context=nothing, kw...)
284+
repr_tree(tree; context=nothing, kw...) = repr_tree(printnode, print_child_key, tree; context=nothing, kw...)
285+
function repr_tree(f, g, tree; context=nothing, kw...)
284286
buf = IOBuffer()
285287
io = context === nothing ? buf : IOContext(buf, context)
286-
print_tree(f, io, tree; kw...)
288+
print_tree(f, g, io, tree; kw...)
287289
return String(take!(buf))
288290
end

0 commit comments

Comments
 (0)