Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Feb 2018 16:25:43 +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: r329583 - head/stand/lua
Message-ID:  <201802191625.w1JGPhnS097216@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Feb 19 16:25:43 2018
New Revision: 329583
URL: https://svnweb.freebsd.org/changeset/base/329583

Log:
  stand/lua: Store menu entries in an "entries" table
  
  Instead of directly listing them in menu.welcome and menu.boot_options,
  store them at menu.welcome.entries and welcome.boot_options.entries.
  
  This will come into play later when we need to re-order the welcome menu if
  boot_single is specified.

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

Modified: head/stand/lua/drawer.lua
==============================================================================
--- head/stand/lua/drawer.lua	Mon Feb 19 15:56:33 2018	(r329582)
+++ head/stand/lua/drawer.lua	Mon Feb 19 16:25:43 2018	(r329583)
@@ -166,7 +166,9 @@ function drawer.drawmenu(m)
 	-- print the menu and build the alias table
 	local alias_table = {};
 	local entry_num = 0;
-	for line_num, e in ipairs(m) do
+	local menu_entries = m.entries;
+
+	for line_num, e in ipairs(menu_entries) do
 		-- Allow menu items to be conditionally visible by specifying
 		-- a visible function.
 		if (e.visible ~= nil) and (not e.visible()) then

Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua	Mon Feb 19 15:56:33 2018	(r329582)
+++ head/stand/lua/menu.lua	Mon Feb 19 16:25:43 2018	(r329583)
@@ -44,202 +44,205 @@ local carousel_choices = {};
 -- loader menu tree is rooted at menu.welcome
 
 menu.boot_options = {
-	-- return to welcome menu
-	{
-		entry_type = core.MENU_RETURN,
-		name = function()
-			return "Back to main menu" ..
-			    color.highlight(" [Backspace]");
-		end
-	},
+	entries = {
+		-- return to welcome menu
+		{
+			entry_type = core.MENU_RETURN,
+			name = function()
+				return "Back to main menu" ..
+				    color.highlight(" [Backspace]");
+			end
+		},
 
-	-- load defaults
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return "Load System " .. color.highlight("D") ..
-			    "efaults";
-		end,
-		func = function()
-			core.setDefaults();
-		end,
-		alias = {"d", "D"}
-	},
+		-- load defaults
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return "Load System " .. color.highlight("D") ..
+				    "efaults";
+			end,
+			func = function()
+				core.setDefaults();
+			end,
+			alias = {"d", "D"}
+		},
 
-	{
-		entry_type = core.MENU_SEPARATOR,
-		name = function()
-			return "";
-		end
-	},
+		{
+			entry_type = core.MENU_SEPARATOR,
+			name = function()
+				return "";
+			end
+		},
 
-	{
-		entry_type = core.MENU_SEPARATOR,
-		name = function()
-			return "Boot Options:";
-		end
-	},
+		{
+			entry_type = core.MENU_SEPARATOR,
+			name = function()
+				return "Boot Options:";
+			end
+		},
 
-	-- acpi
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return OnOff(color.highlight("A") .. "CPI       :",
-			    core.acpi);
-		end,
-		func = function()
-			core.setACPI();
-		end,
-		alias = {"a", "A"}
+		-- acpi
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return OnOff(color.highlight("A") .. "CPI       :",
+				    core.acpi);
+			end,
+			func = function()
+				core.setACPI();
+			end,
+			alias = {"a", "A"}
+		},
+		-- safe mode
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return OnOff("Safe " .. color.highlight("M") ..
+				    "ode  :", core.sm);
+			end,
+			func = function()
+				core.setSafeMode();
+			end,
+			alias = {"m", "M"}
+		},
+		-- single user
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return OnOff(color.highlight("S") .. "ingle user:",
+				    core.su);
+			end,
+			func = function()
+				core.setSingleUser();
+			end,
+			alias = {"s", "S"}
+		},
+		-- verbose boot
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return OnOff(color.highlight("V") .. "erbose    :",
+				    core.verbose);
+			end,
+			func = function()
+				core.setVerbose();
+			end,
+			alias = {"v", "V"}
+		},
 	},
-	-- safe mode
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return OnOff("Safe " .. color.highlight("M") ..
-			    "ode  :", core.sm);
-		end,
-		func = function()
-			core.setSafeMode();
-		end,
-		alias = {"m", "M"}
-	},
-	-- single user
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return OnOff(color.highlight("S") .. "ingle user:",
-			    core.su);
-		end,
-		func = function()
-			core.setSingleUser();
-		end,
-		alias = {"s", "S"}
-	},
-	-- verbose boot
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return OnOff(color.highlight("V") .. "erbose    :",
-			    core.verbose);
-		end,
-		func = function()
-			core.setVerbose();
-		end,
-		alias = {"v", "V"}
-	},
 };
 
 menu.welcome = {
-	-- boot multi user
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return color.highlight("B") .. "oot Multi user " ..
-			    color.highlight("[Enter]");
-		end,
-		func = function()
-			core.setSingleUser(false);
-			core.boot();
-		end,
-		alias = {"b", "B"}
-	},
+	entries = {
+		-- boot multi user
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return color.highlight("B") .. "oot Multi user " ..
+				    color.highlight("[Enter]");
+			end,
+			func = function()
+				core.setSingleUser(false);
+				core.boot();
+			end,
+			alias = {"b", "B"}
+		},
 
-	-- boot single user
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return "Boot " .. color.highlight("S") .. "ingle user";
-		end,
-		func = function()
-			core.setSingleUser(true);
-			core.boot();
-		end,
-		alias = {"s", "S"}
-	},
+		-- boot single user
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return "Boot " .. color.highlight("S") .. "ingle user";
+			end,
+			func = function()
+				core.setSingleUser(true);
+				core.boot();
+			end,
+			alias = {"s", "S"}
+		},
 
-	-- escape to interpreter
-	{
-		entry_type = core.MENU_RETURN,
-		name = function()
-			return color.highlight("Esc") .. "ape to loader prompt";
-		end,
-		func = function()
-			loader.setenv("autoboot_delay", "NO");
-		end,
-		alias = {core.KEYSTR_ESCAPE}
-	},
+		-- escape to interpreter
+		{
+			entry_type = core.MENU_RETURN,
+			name = function()
+				return color.highlight("Esc") .. "ape to loader prompt";
+			end,
+			func = function()
+				loader.setenv("autoboot_delay", "NO");
+			end,
+			alias = {core.KEYSTR_ESCAPE}
+		},
 
-	-- reboot
-	{
-		entry_type = core.MENU_ENTRY,
-		name = function()
-			return color.highlight("R") .. "eboot";
-		end,
-		func = function()
-			loader.perform("reboot");
-		end,
-		alias = {"r", "R"}
-	},
+		-- reboot
+		{
+			entry_type = core.MENU_ENTRY,
+			name = function()
+				return color.highlight("R") .. "eboot";
+			end,
+			func = function()
+				loader.perform("reboot");
+			end,
+			alias = {"r", "R"}
+		},
 
 
-	{
-		entry_type = core.MENU_SEPARATOR,
-		name = function()
-			return "";
-		end
-	},
-
-	{
-		entry_type = core.MENU_SEPARATOR,
-		name = function()
-			return "Options:";
-		end
-	},
-
-	-- kernel options
-	{
-		entry_type = core.MENU_CAROUSEL_ENTRY,
-		carousel_id = "kernel",
-		items = core.kernelList,
-		name = function(idx, choice, all_choices)
-			if (#all_choices == 0) then
-				return "Kernel: ";
+		{
+			entry_type = core.MENU_SEPARATOR,
+			name = function()
+				return "";
 			end
+		},
 
-			local is_default = (idx == 1);
-			local kernel_name = "";
-			local name_color;
-			if (is_default) then
-				name_color = color.escapef(color.GREEN);
-				kernel_name = "default/";
-			else
-				name_color = color.escapef(color.BLUE);
+		{
+			entry_type = core.MENU_SEPARATOR,
+			name = function()
+				return "Options:";
 			end
-			kernel_name = kernel_name .. name_color .. choice ..
-			    color.default();
-			return color.highlight("K").."ernel: " .. kernel_name ..
-			    " (" .. idx ..
-			    " of " .. #all_choices .. ")";
-		end,
-		func = function(idx, choice, all_choices)
-			config.selectkernel(choice);
-		end,
-		alias = {"k", "K"}
-	},
+		},
 
-	-- boot options
-	{
-		entry_type = core.MENU_SUBMENU,
-		name = function()
-			return "Boot " .. color.highlight("O") .. "ptions";
-		end,
-		submenu = function()
-			return menu.boot_options;
-		end,
-		alias = {"o", "O"}
-	}
+		-- kernel options
+		{
+			entry_type = core.MENU_CAROUSEL_ENTRY,
+			carousel_id = "kernel",
+			items = core.kernelList,
+			name = function(idx, choice, all_choices)
+				if (#all_choices == 0) then
+					return "Kernel: ";
+				end
 
+				local is_default = (idx == 1);
+				local kernel_name = "";
+				local name_color;
+				if (is_default) then
+					name_color = color.escapef(color.GREEN);
+					kernel_name = "default/";
+				else
+					name_color = color.escapef(color.BLUE);
+				end
+				kernel_name = kernel_name .. name_color .. choice ..
+				    color.default();
+				return color.highlight("K").."ernel: " .. kernel_name ..
+				    " (" .. idx ..
+				    " of " .. #all_choices .. ")";
+			end,
+			func = function(idx, choice, all_choices)
+				config.selectkernel(choice);
+			end,
+			alias = {"k", "K"}
+		},
+
+		-- boot options
+		{
+			entry_type = core.MENU_SUBMENU,
+			name = function()
+				return "Boot " .. color.highlight("O") .. "ptions";
+			end,
+			submenu = function()
+				return menu.boot_options;
+			end,
+			alias = {"o", "O"}
+		},
+	},
 };
 
 -- The first item in every carousel is always the default item.



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