2
2
3
3
export TreeMenu
4
4
5
+ """
6
+ TreeMenu(root; pagesize::Int=10, dynamic = false, maxsize = pagesize, keypress = (m,i) -> false, kwargs...)
7
+
8
+ Use `root` to create an interactive menu using TerminalMenus. `pagesize` is the number of lines to use for a page.
9
+ If `dynamic`, adjust the page size based on the expansion of the content. `maxsize` is the maximum size of the page.
10
+
11
+ Provide a function `keypress` to respond to keys while the menu is shown. The function has two arguments, `m::TreeMenu`
12
+ and `i::UInt32`. The integer `i` is the key pressed. This function should return `true` if the menu should exit and
13
+ `false` otherwise.
14
+
15
+ `kwargs` are passed to `TerminalMenus.Config`.
16
+ """
5
17
mutable struct TreeMenu{N<: Node } <: TerminalMenus._ConfiguredMenu{TerminalMenus.Config}
6
18
root:: N
7
19
current:: N
@@ -14,11 +26,12 @@ mutable struct TreeMenu{N<:Node} <: TerminalMenus._ConfiguredMenu{TerminalMenus.
14
26
dynamic:: Bool
15
27
maxsize:: Int
16
28
pageoffset:: Int
29
+ keypress:: Any
17
30
config:: TerminalMenus.Config
18
31
end
19
- function TreeMenu (root; pagesize:: Int = 10 , dynamic = false , maxsize = pagesize, kwargs... )
32
+ function TreeMenu (root; pagesize:: Int = 10 , dynamic = false , maxsize = pagesize, keypress = (m,i) -> false , kwargs... )
20
33
pagesize = min (pagesize, count_open_leaves (root))
21
- return TreeMenu (root, root, 1 , 1 , 1 , false , pagesize, dynamic, maxsize, 0 , TerminalMenus. Config (kwargs... ))
34
+ return TreeMenu (root, root, 1 , 1 , 1 , false , pagesize, dynamic, maxsize, 0 , keypress, TerminalMenus. Config (kwargs... ))
22
35
end
23
36
24
37
"""
@@ -122,7 +135,7 @@ function TerminalMenus.keypress(menu::TreeMenu, i::UInt32)
122
135
menu. pagesize = min (menu. maxsize, count_open_leaves (menu. root))
123
136
end
124
137
end
125
- return false
138
+ return menu . keypress (menu, i)
126
139
end
127
140
128
141
function TerminalMenus. selected (menu:: TreeMenu )
0 commit comments