11"""
22 print_tree(tree; kw...)
33 print_tree(io::IO, tree; kw...)
4+ print_tree(f::Function, io::IO, tree; kw...)
45 print_tree(f::Function, g::Function, io::IO, tree; kw...)
56
67Print a text representation of `tree` to the given `io` object.
@@ -20,6 +21,7 @@ signature `g(io::IO, key;)`.
2021* `printkeys::Union{Bool, Nothing}` - Whether to print keys of child nodes (using
2122 `pairs(children(node))`). A value of `nothing` uses [`printkeys_default`](@ref) do decide the
2223 behavior on a node-by-node basis.
24+ * `printnode_kw = (;)` - keyword arguments to forward to `f`.
2325
2426# Examples
2527
@@ -77,12 +79,14 @@ function print_tree end
7779
7880
7981"""
80- printnode(io::IO, node)
82+ printnode(io::IO, node; kw... )
8183
8284Print a compact representation of a single node. By default, this prints `nodevalue(node)`.
8385
8486**OPTIONAL**: This can be extended for custom types and controls how nodes are shown
8587in [`print_tree`](@ref).
88+
89+ The keyword argument `printnode_kw` of [`print_tree`](@ref) will be passed to this function.
8690"""
8791printnode (io:: IO , node; kw... ) = show (IOContext (io, :compact => true , :limit => true ), nodevalue (node))
8892
@@ -194,11 +198,11 @@ function print_tree(printnode::Function, print_child_key::Function, io::IO, node
194198 printkeys:: Union{Bool,Nothing} = nothing ,
195199 depth:: Integer = 0 ,
196200 prefix:: AbstractString = " " ,
197- kw ...
201+ printnode_kw = (;),
198202 )
199203 # Get node representation as string
200204 buf = IOBuffer ()
201- printnode (IOContext (buf, io), node; kw ... )
205+ printnode (IOContext (buf, io), node; printnode_kw ... )
202206 str = String (take! (buf))
203207
204208 # Copy buffer to output, prepending prefix to each line
@@ -264,24 +268,27 @@ function print_tree(printnode::Function, print_child_key::Function, io::IO, node
264268
265269 print_tree (printnode, print_child_key, io, child;
266270 maxdepth= maxdepth, indicate_truncation= indicate_truncation, charset= charset,
267- printkeys= printkeys, depth= depth+ 1 , prefix= child_prefix
271+ printkeys= printkeys, depth= depth+ 1 , prefix= child_prefix, printnode_kw = printnode_kw,
268272 )
269273 end
270274end
271275
276+ print_tree (printnode:: Function , io:: IO , node; kw... ) = print_tree (printnode, print_child_key, io, node; kw... )
272277print_tree (io:: IO , node; kw... ) = print_tree (printnode, print_child_key, io, node; kw... )
273278print_tree (node; kw... ) = print_tree (stdout , node; kw... )
274279
275280
276281"""
277282 repr_tree(tree; context=nothing, kw...)
278283 repr_tree(f, tree; context=nothing, kw...)
284+ repr_tree(f, g, tree; context=nothing, kw...)
279285
280286Get the string result of calling [`print_tree`](@ref) with the supplied arguments.
281287
282288The `context` argument works as it does in `Base.repr`.
283289"""
284290repr_tree (tree; context= nothing , kw... ) = repr_tree (printnode, print_child_key, tree; context= nothing , kw... )
291+ repr_tree (f:: Function , tree; context= nothing , kw... ) = repr_tree (f, print_child_key, tree; context= nothing , kw... )
285292function repr_tree (f:: Function , g:: Function , tree; context= nothing , kw... )
286293 buf = IOBuffer ()
287294 io = context === nothing ? buf : IOContext (buf, context)
0 commit comments