Skip to content

Commit dd58616

Browse files
committed
Define default TreeCharSet with global var instead of no-arg constructor
1 parent b12f765 commit dd58616

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ 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("+", "\\", "|", "--", "...")
102103

103104

104105
"""
@@ -116,7 +117,7 @@ function print_prefix(io::IO, depth::Int, charset::TreeCharSet, active_levels)
116117
end
117118

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

test/printing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ AbstractTrees.children(::SingleChildInfiniteDepth) = (SingleChildInfiniteDepth()
3434
# └─ 3
3535
#
3636

37-
truncation_char = AbstractTrees.TreeCharSet().trunc
37+
truncation_char = AbstractTrees.DEFAULT_CHARSET.trunc
3838

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

0 commit comments

Comments
 (0)