From beafe961479d4c7380e3c0dab4b18bcf60d29255 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 25 Feb 2018 17:02:50 +0000 Subject: [PATCH] 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. --- stand/lua/menu.lua | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index d707ab5a6bed..1a6ca97a9f57 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -38,7 +38,7 @@ local drawer = require("drawer") local menu = {} -local screen_invalid = true +local drawn_menu local function OnOff(str, b) if b then @@ -82,7 +82,6 @@ menu.handlers = { end end, [core.MENU_SUBMENU] = function(_, entry) - screen_invalid = true menu.process(entry.submenu) end, [core.MENU_RETURN] = function(_, entry) @@ -348,12 +347,12 @@ menu.default = menu.welcome -- the local alias_table in menu.process. menu.current_alias_table = {} -function menu.redraw(m) - -- redraw screen +function menu.draw(m) + -- Clear the screen, reset the cursor, then draw screen.clear() screen.defcursor() menu.current_alias_table = drawer.drawscreen(m) - screen_invalid = false + drawn_menu = m end -- 'keypress' allows the caller to indicate that a key has been pressed that we @@ -361,10 +360,8 @@ end function menu.process(m, keypress) assert(m ~= nil) - -- Trigger a redraw if we've been invalidated. Otherwise, we assume - -- that this menu has already been drawn. - if screen_invalid then - menu.redraw(m) + if drawn_menu ~= m then + menu.draw(m) end while true do @@ -404,13 +401,9 @@ function menu.process(m, keypress) end -- If we got an alias key the screen is out of date... -- redraw it. - menu.redraw(m) + menu.draw(m) 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 function menu.run() @@ -419,10 +412,11 @@ function menu.run() return end - menu.redraw(menu.default) + menu.draw(menu.default) local autoboot_key = menu.autoboot() menu.process(menu.default, autoboot_key) + drawn_menu = nil screen.defcursor() print("Exiting menu!")