Skip to content

Commit 4bbbad2

Browse files
committed
Define default TreeCharSet with global var instead of no-arg constructor
1 parent efc0ace commit 4bbbad2

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/src/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ AbstractTrees.printnode
2525
AbstractTrees.siblinglinks
2626
treemap
2727
treemap!
28+
AbstractTrees.DEFAULT_CHARSET
29+
AbstractTrees.ASCII_CHARSET
2830
```

src/printing.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ struct TreeCharSet
9696
trunc
9797
end
9898

99-
# Default charset
100-
TreeCharSet() = TreeCharSet('','','','','')
101-
TreeCharSet(mid, term, skip, dash) = TreeCharSet(mid, term, skip, dash, '')
99+
"""Default `charset` argument used by [`print_tree`](@ref)."""
100+
const DEFAULT_CHARSET = TreeCharSet('', '', '', '', '')
101+
"""Charset using only ASCII characters."""
102+
const ASCII_CHARSET = TreeCharSet("+", "\\", "|", "--", "...")
103+
104+
function TreeCharSet()
105+
Base.depwarn("The 0-argument constructor of TreeCharSet is deprecated, use AbstractTrees.DEFAULT_CHARSET instead.", :TreeCharSet)
106+
return DEFAULT_CHARSET
107+
end
102108

103109

104110
"""
@@ -116,7 +122,7 @@ function print_prefix(io::IO, depth::Int, charset::TreeCharSet, active_levels)
116122
end
117123

118124
function _print_tree(printnode::Function, io::IO, tree; maxdepth = 5, indicate_truncation = true,
119-
depth = 0, active_levels = Int[], charset = TreeCharSet(), withinds = false,
125+
depth = 0, active_levels = Int[], charset = DEFAULT_CHARSET, withinds = false,
120126
inds = [], from = nothing, to = nothing, roottree = tree)
121127
nodebuf = IOBuffer()
122128
isa(io, IOContext) && (nodebuf = IOContext(nodebuf, io))

test/printing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ AbstractTrees.children(::SingleChildInfiniteDepth) = (SingleChildInfiniteDepth()
5252
# └─ 3
5353
#
5454

55-
truncation_char = AbstractTrees.TreeCharSet().trunc
55+
truncation_char = AbstractTrees.DEFAULT_CHARSET.trunc
5656

5757
for maxdepth in [3,5,8]
5858
ptxt = repr_tree(Num(0), maxdepth=maxdepth)

0 commit comments

Comments
 (0)