lualoader: Clean up menu handling a little bit
This is driven by an urge to separate out the bits that really only need to happen when the menu system starts up. Key points: - menu.process now does the bulk of menu handling. It retains autoboot handling for dubious reasons, and it no longer accepts a 'nil' menu to process as 'the default'. Its return value is insignificant. - The MENU_SUBMENU handler now returns nothing. If menu.process has exited, then we continue processing menu items on the parent menu as expected. - menu.run is now the entry point of the menu system. It checks whether the menu should be skipped, processes the default menu, then returns.
This commit is contained in:
parent
71999db645
commit
c7da60c4f0
@ -81,7 +81,7 @@ menu.handlers = {
|
|||||||
end,
|
end,
|
||||||
[core.MENU_SUBMENU] = function(_, entry)
|
[core.MENU_SUBMENU] = function(_, entry)
|
||||||
-- recurse
|
-- recurse
|
||||||
return menu.run(entry.submenu)
|
menu.process(entry.submenu)
|
||||||
end,
|
end,
|
||||||
[core.MENU_RETURN] = function(_, entry)
|
[core.MENU_RETURN] = function(_, entry)
|
||||||
-- allow entry to have a function/side effect
|
-- allow entry to have a function/side effect
|
||||||
@ -342,29 +342,24 @@ menu.welcome = {
|
|||||||
|
|
||||||
menu.default = menu.welcome
|
menu.default = menu.welcome
|
||||||
|
|
||||||
function menu.run(m)
|
function menu.process(m)
|
||||||
|
assert(m ~= nil)
|
||||||
if menu.skip() then
|
|
||||||
core.autoboot()
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if m == nil then
|
|
||||||
m = menu.default
|
|
||||||
end
|
|
||||||
|
|
||||||
-- redraw screen
|
-- redraw screen
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.defcursor()
|
screen.defcursor()
|
||||||
local alias_table = drawer.drawscreen(m)
|
local alias_table = drawer.drawscreen(m)
|
||||||
|
|
||||||
-- Might return nil, that's ok
|
-- autoboot processing likely belongs better in menu.run, but we want
|
||||||
|
-- to draw the menu once before we do any autoboot prompting. We also
|
||||||
|
-- collect the alias table from the drawer, which generates the table
|
||||||
|
-- based on all of the 'alias' entries along with effective line numbers
|
||||||
|
-- that each entry is drawn at. This makes it cleaner to handle here,
|
||||||
|
-- for the time being.
|
||||||
local autoboot_key;
|
local autoboot_key;
|
||||||
if m == menu.default then
|
if m == menu.default then
|
||||||
autoboot_key = menu.autoboot()
|
autoboot_key = menu.autoboot()
|
||||||
end
|
end
|
||||||
local cont = true
|
while true do
|
||||||
while cont do
|
|
||||||
local key = autoboot_key or io.getchar()
|
local key = autoboot_key or io.getchar()
|
||||||
autoboot_key = nil
|
autoboot_key = nil
|
||||||
|
|
||||||
@ -391,12 +386,11 @@ function menu.run(m)
|
|||||||
-- Get menu handler
|
-- Get menu handler
|
||||||
local handler = menu.handlers[sel_entry.entry_type]
|
local handler = menu.handlers[sel_entry.entry_type]
|
||||||
if handler ~= nil then
|
if handler ~= nil then
|
||||||
-- The handler's return value indicates whether
|
-- The handler's return value indicates if we
|
||||||
-- we need to exit this menu. An omitted return
|
-- need to exit this menu. An omitted or true
|
||||||
-- value means "continue" by default.
|
-- return value means to continue.
|
||||||
cont = handler(m, sel_entry)
|
if handler(m, sel_entry) == false then
|
||||||
if cont == nil then
|
return
|
||||||
cont = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- if we got an alias key the screen is out of date:
|
-- if we got an alias key the screen is out of date:
|
||||||
@ -405,14 +399,18 @@ function menu.run(m)
|
|||||||
alias_table = drawer.drawscreen(m)
|
alias_table = drawer.drawscreen(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if m == menu.default then
|
function menu.run()
|
||||||
screen.defcursor()
|
if menu.skip() then
|
||||||
print("Exiting menu!")
|
core.autoboot()
|
||||||
return false
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
menu.process(menu.default)
|
||||||
|
|
||||||
|
screen.defcursor()
|
||||||
|
print("Exiting menu!")
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu.skip()
|
function menu.skip()
|
||||||
|
Loading…
Reference in New Issue
Block a user