Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Feb 2018 04:44:46 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329947 - head/stand/lua
Message-ID:  <201802250444.w1P4ikVh037925@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sun Feb 25 04:44:45 2018
New Revision: 329947
URL: https://svnweb.freebsd.org/changeset/base/329947

Log:
  lualoader: Pull menu redrawing specifics out of menu.process
  
  In general, every menu redraw is going to require a screen clear and cursor
  reset. Each redraw also has the potential to invalidate the alias table, so
  we move the alias table being used out into a module variable. This allows
  third party consumers to also inspect or update the alias table if they need
  to.
  
  While here, stop searching the alias table once we've found a match.

Modified:
  head/stand/lua/menu.lua

Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua	Sun Feb 25 04:11:08 2018	(r329946)
+++ head/stand/lua/menu.lua	Sun Feb 25 04:44:45 2018	(r329947)
@@ -341,14 +341,24 @@ menu.welcome = {
 }
 
 menu.default = menu.welcome
+-- current_alias_table will be used to keep our alias table consistent across
+-- screen redraws, instead of relying on whatever triggered the redraw to update
+-- the local alias_table in menu.process.
+menu.current_alias_table = {}
 
-function menu.process(m)
-	assert(m ~= nil)
+function menu.redraw(m)
 	-- redraw screen
 	screen.clear()
 	screen.defcursor()
-	local alias_table = drawer.drawscreen(m)
+	menu.current_alias_table = drawer.drawscreen(m)
+end
 
+function menu.process(m)
+	assert(m ~= nil)
+
+	-- Trigger a redraw if we've not been drawn
+	menu.redraw(m)
+
 	-- 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
@@ -375,9 +385,10 @@ function menu.process(m)
 		key = string.char(key)
 		-- check to see if key is an alias
 		local sel_entry = nil
-		for k, v in pairs(alias_table) do
+		for k, v in pairs(menu.current_alias_table) do
 			if key == k then
 				sel_entry = v
+				break
 			end
 		end
 
@@ -387,16 +398,15 @@ function menu.process(m)
 			local handler = menu.handlers[sel_entry.entry_type]
 			if handler ~= nil then
 				-- The handler's return value indicates if we
-				-- need to exit this menu. An omitted or true
+				-- 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:
-			screen.clear()
-			screen.defcursor()
-			alias_table = drawer.drawscreen(m)
+			-- If we got an alias key the screen is out of date...
+			-- redraw it.
+			menu.redraw(m)
 		end
 	end
 end



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802250444.w1P4ikVh037925>