diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index 4dcd5708c262..f8f7fd5a20cd 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -81,7 +81,7 @@ menu.handlers = { end, [core.MENU_SUBMENU] = function(_, entry) -- recurse - return menu.run(entry.submenu) + menu.process(entry.submenu) end, [core.MENU_RETURN] = function(_, entry) -- allow entry to have a function/side effect @@ -342,29 +342,24 @@ menu.welcome = { menu.default = menu.welcome -function menu.run(m) - - if menu.skip() then - core.autoboot() - return false - end - - if m == nil then - m = menu.default - end - +function menu.process(m) + assert(m ~= nil) -- redraw screen screen.clear() screen.defcursor() 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; if m == menu.default then autoboot_key = menu.autoboot() end - local cont = true - while cont do + while true do local key = autoboot_key or io.getchar() autoboot_key = nil @@ -391,12 +386,11 @@ function menu.run(m) -- Get menu handler local handler = menu.handlers[sel_entry.entry_type] if handler ~= nil then - -- The handler's return value indicates whether - -- we need to exit this menu. An omitted return - -- value means "continue" by default. - cont = handler(m, sel_entry) - if cont == nil then - cont = true + -- The handler's return value indicates if we + -- need to exit this menu. An omitted or true + -- return value means to continue. + if handler(m, sel_entry) == false then + return end end -- 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) end end +end - if m == menu.default then - screen.defcursor() - print("Exiting menu!") - return false +function menu.run() + if menu.skip() then + core.autoboot() + return end - return true + menu.process(menu.default) + + screen.defcursor() + print("Exiting menu!") end function menu.skip()