lualoader: Pull autoboot handling out into menu.run()

There's no reason for autoboot handling to be mixed in with menu processing.
It is a distinct process that should only be done once when entering the
menu system.

menu.process has been modified to take an initial keypress to process and to
only draw the screen initially if it's been invalidated. The keypress is
kind of a kludge, although it could be argued to be a potentially useful
kludge if there are other processes that may need to feed a keypress into
the menu system.
This commit is contained in:
Kyle Evans 2018-02-25 05:00:54 +00:00
parent 28384160a7
commit ca16d83fd4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329948

View File

@ -38,6 +38,8 @@ local drawer = require("drawer")
local menu = {} local menu = {}
local screen_invalid = true
local function OnOff(str, b) local function OnOff(str, b)
if b then if b then
return str .. color.escapef(color.GREEN) .. "On" .. return str .. color.escapef(color.GREEN) .. "On" ..
@ -80,7 +82,7 @@ menu.handlers = {
end end
end, end,
[core.MENU_SUBMENU] = function(_, entry) [core.MENU_SUBMENU] = function(_, entry)
-- recurse screen_invalid = true
menu.process(entry.submenu) menu.process(entry.submenu)
end, end,
[core.MENU_RETURN] = function(_, entry) [core.MENU_RETURN] = function(_, entry)
@ -351,27 +353,23 @@ function menu.redraw(m)
screen.clear() screen.clear()
screen.defcursor() screen.defcursor()
menu.current_alias_table = drawer.drawscreen(m) menu.current_alias_table = drawer.drawscreen(m)
screen_invalid = false
end end
function menu.process(m) -- 'keypress' allows the caller to indicate that a key has been pressed that we
-- should process as our initial input.
function menu.process(m, keypress)
assert(m ~= nil) assert(m ~= nil)
-- Trigger a redraw if we've not been drawn -- Trigger a redraw if we've been invalidated. Otherwise, we assume
menu.redraw(m) -- that this menu has already been drawn.
if screen_invalid then
-- autoboot processing likely belongs better in menu.run, but we want menu.redraw(m)
-- 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 end
while true do while true do
local key = autoboot_key or io.getchar() local key = keypress or io.getchar()
autoboot_key = nil keypress = nil
-- Special key behaviors -- Special key behaviors
if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and
@ -417,7 +415,10 @@ function menu.run()
return return
end end
menu.process(menu.default) menu.redraw(menu.default)
local autoboot_key = menu.autoboot()
menu.process(menu.default, autoboot_key)
screen.defcursor() screen.defcursor()
print("Exiting menu!") print("Exiting menu!")