FoldingTrees.jl
FoldingTrees.TreeMenu
FoldingTrees.count_open_leaves
FoldingTrees.fold!
FoldingTrees.isroot
FoldingTrees.next
FoldingTrees.nodes
FoldingTrees.prev
FoldingTrees.toggle!
FoldingTrees.unfold!
FoldingTrees.writeoption
FoldingTrees.TreeMenu
— TypeTreeMenu(root; pagesize::Int=10, dynamic = false, maxsize = pagesize, keypress = (m,i) -> false, kwargs...)
Use root
to create an interactive menu using TerminalMenus. pagesize
is the number of lines to use for a page. If dynamic
, adjust the page size based on the expansion of the content. maxsize
is the maximum size of the page.
Provide a function keypress
to respond to keys while the menu is shown. The function has two arguments, m::TreeMenu
and i::UInt32
. The integer i
is the key pressed. This function should return true
if the menu should exit and false
otherwise.
kwargs
are passed to TerminalMenus.Config
.
FoldingTrees.count_open_leaves
— Functioncount_open_leaves(node)
Return the number of unfolded descendants of node
.
FoldingTrees.fold!
— MethodFoldingTrees.isroot
— Methodisroot(node)
Return true
if node
is the root node (meaning, it has no parent).
FoldingTrees.next
— Functionnewnode, newdepth = next(node, depth::Int=0)
Return the next node in a depth-first search. depth
counts the number of levels below the root. The parent is visited before any children.
FoldingTrees.nodes
— Methoditr = nodes(node)
Create an iterator itr
that will return the nodes, rather than the node data.
Example
julia> foreach(unfold!, nodes(root))
would ensure that each node in the tree is unfolded.
FoldingTrees.prev
— Functionnewnode, newdepth = prev(node, depth::Int=0)
Return the previous node in a depth-first search. depth
counts the number of levels below the root.
This traverses in the opposite direction as next
, so last, deepest children are visited before their parents.
FoldingTrees.toggle!
— MethodFoldingTrees.unfold!
— MethodFoldingTrees.writeoption
— Methodwriteoption(buf::IO, data, charsused::Int; width::Int=displaysize(stdout)[2])
Print data
to buf
as a menu option. charsused
is the number of characters already printed on that line. width
allows you to specify the display width (in characters), which defaults to the width of the terminal window.
Given a tree built from Node{Data}
, packages implementing a TreeMenu
may need to implement writeoption(buf, data::Data, charsused)
.
The implementation for data::AbstractString
is careful to ensure that the option does not wrap to a new line of the terminal, and to ensure that any color printing is turned off even when the line has to be truncated.