svn commit: r329593 - head/stand/lua

Kyle Evans kevans at FreeBSD.org
Mon Feb 19 17:40:20 UTC 2018


Author: kevans
Date: Mon Feb 19 17:40:19 2018
New Revision: 329593
URL: https://svnweb.freebsd.org/changeset/base/329593

Log:
  stand/lua: Change boot menu items' names when swapped
  
  [Enter] should be moved to the single user menu item when we swap them.
  
  Define a non-standard menu entry function "alternate_name" to use for this
  purpose for ultimate flexibility if we change our minds later. When we're
  booting single user, make a shallow copy of the menu that we'd normally
  display and swap the items and their name functions to use alternate_name
  instead. Toggling single user in the options menu and going back to the main
  menu will now correctly reflect the current boot setting with the first two
  menu options and "[Enter]" will always be on the right one.
  
  This shallow copy technique has the chance of being quite slow since it's
  done on every redraw, but in my testing it does not seem to make any obvious
  difference.
  
  shallowCopyTable could likely belong better in a general-purpose utility
  module, but this (and the key constnats) are the only candidates we have at
  the moment so we'll drop it into our core stuff for the moment and consider
  re-organization at a later date.

Modified:
  head/stand/lua/core.lua
  head/stand/lua/menu.lua

Modified: head/stand/lua/core.lua
==============================================================================
--- head/stand/lua/core.lua	Mon Feb 19 17:09:29 2018	(r329592)
+++ head/stand/lua/core.lua	Mon Feb 19 17:40:19 2018	(r329593)
@@ -217,5 +217,18 @@ function core.isSerialBoot()
 	return false;
 end
 
+-- This may be a better candidate for a 'utility' module.
+function core.shallowCopyTable(tbl)
+	local new_tbl = {};
+	for k, v in pairs(tbl) do
+		if (type(v) == "table") then
+			new_tbl[k] = core.shallowCopyTable(v);
+		else
+			new_tbl[k] = v;
+		end
+	end
+	return new_tbl;
+end
+
 core.setACPI(core.getACPIPresent(false));
 return core;

Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua	Mon Feb 19 17:09:29 2018	(r329592)
+++ head/stand/lua/menu.lua	Mon Feb 19 17:40:19 2018	(r329593)
@@ -137,9 +137,15 @@ menu.welcome = {
 		local menu_entries = menu.welcome.all_entries;
 		-- Swap the first two menu items on single user boot
 		if (core.isSingleUserBoot()) then
+			-- Shallow copy the table
+			menu_entries = core.shallowCopyTable(menu_entries);
+
 			local multiuser = menu_entries[1];
 			local singleuser = menu_entries[2];
 
+			multiuser.name = multiuser.alternate_name;
+			singleuser.name = singleuser.alternate_name;
+
 			menu_entries[2] = multiuser;
 			menu_entries[1] = singleuser;
 		end
@@ -154,6 +160,11 @@ menu.welcome = {
 				    "oot Multi user " ..
 				    color.highlight("[Enter]");
 			end,
+			-- Not a standard menu entry function!
+			alternate_name = function()
+				return color.highlight("B") ..
+				    "oot Multi user";
+			end,
 			func = function()
 				core.setSingleUser(false);
 				core.boot();
@@ -167,6 +178,11 @@ menu.welcome = {
 			name = function()
 				return "Boot " .. color.highlight("S") ..
 				    "ingle user";
+			end,
+			-- Not a standard menu entry function!
+			alternate_name = function()
+				return "Boot " .. color.highlight("S") ..
+				    "ingle user " .. color.highlight("[Enter]");
 			end,
 			func = function()
 				core.setSingleUser(true);


More information about the svn-src-all mailing list