lualoader: Track the menu currently drawn, instead of validity
This cleans up the odd approach to menu drawing. Instead of tracking validity, we track the menu that was drawn on the screen. Whenever we draw a menu, we'll set this to that menu. Anything that invalidates the screen should go ahead and trigger an explicit redraw, rather than finding a wy to set screen_invalid. The currently drawn menu is then reset in menu.run as we exit the menu system, so that dropping to the loader prompt or leaving menu.run() will just behave as expected without doing redundant work every time we leave a menu.
This commit is contained in:
parent
fe226a72cb
commit
beafe96147
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329987
@ -38,7 +38,7 @@ local drawer = require("drawer")
|
|||||||
|
|
||||||
local menu = {}
|
local menu = {}
|
||||||
|
|
||||||
local screen_invalid = true
|
local drawn_menu
|
||||||
|
|
||||||
local function OnOff(str, b)
|
local function OnOff(str, b)
|
||||||
if b then
|
if b then
|
||||||
@ -82,7 +82,6 @@ menu.handlers = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
[core.MENU_SUBMENU] = function(_, entry)
|
[core.MENU_SUBMENU] = function(_, entry)
|
||||||
screen_invalid = true
|
|
||||||
menu.process(entry.submenu)
|
menu.process(entry.submenu)
|
||||||
end,
|
end,
|
||||||
[core.MENU_RETURN] = function(_, entry)
|
[core.MENU_RETURN] = function(_, entry)
|
||||||
@ -348,12 +347,12 @@ menu.default = menu.welcome
|
|||||||
-- the local alias_table in menu.process.
|
-- the local alias_table in menu.process.
|
||||||
menu.current_alias_table = {}
|
menu.current_alias_table = {}
|
||||||
|
|
||||||
function menu.redraw(m)
|
function menu.draw(m)
|
||||||
-- redraw screen
|
-- Clear the screen, reset the cursor, then draw
|
||||||
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
|
drawn_menu = m
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 'keypress' allows the caller to indicate that a key has been pressed that we
|
-- 'keypress' allows the caller to indicate that a key has been pressed that we
|
||||||
@ -361,10 +360,8 @@ end
|
|||||||
function menu.process(m, keypress)
|
function menu.process(m, keypress)
|
||||||
assert(m ~= nil)
|
assert(m ~= nil)
|
||||||
|
|
||||||
-- Trigger a redraw if we've been invalidated. Otherwise, we assume
|
if drawn_menu ~= m then
|
||||||
-- that this menu has already been drawn.
|
menu.draw(m)
|
||||||
if screen_invalid then
|
|
||||||
menu.redraw(m)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
@ -404,13 +401,9 @@ function menu.process(m, keypress)
|
|||||||
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...
|
||||||
-- redraw it.
|
-- redraw it.
|
||||||
menu.redraw(m)
|
menu.draw(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Invalidate the screen upon exit so that it gets redrawn upon
|
|
||||||
-- processing a new menu, assuming it won't be redrawn after leaving
|
|
||||||
-- this menu
|
|
||||||
screen_invalid = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu.run()
|
function menu.run()
|
||||||
@ -419,10 +412,11 @@ function menu.run()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
menu.redraw(menu.default)
|
menu.draw(menu.default)
|
||||||
local autoboot_key = menu.autoboot()
|
local autoboot_key = menu.autoboot()
|
||||||
|
|
||||||
menu.process(menu.default, autoboot_key)
|
menu.process(menu.default, autoboot_key)
|
||||||
|
drawn_menu = nil
|
||||||
|
|
||||||
screen.defcursor()
|
screen.defcursor()
|
||||||
print("Exiting menu!")
|
print("Exiting menu!")
|
||||||
|
Loading…
Reference in New Issue
Block a user