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.
This commit is contained in:
Kyle Evans 2018-02-19 17:40:19 +00:00
parent e6db469bfa
commit 5c1b516581
2 changed files with 29 additions and 0 deletions

View File

@ -217,5 +217,18 @@ function core.isSerialBoot()
return false; return false;
end 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)); core.setACPI(core.getACPIPresent(false));
return core; return core;

View File

@ -137,9 +137,15 @@ menu.welcome = {
local menu_entries = menu.welcome.all_entries; local menu_entries = menu.welcome.all_entries;
-- Swap the first two menu items on single user boot -- Swap the first two menu items on single user boot
if (core.isSingleUserBoot()) then if (core.isSingleUserBoot()) then
-- Shallow copy the table
menu_entries = core.shallowCopyTable(menu_entries);
local multiuser = menu_entries[1]; local multiuser = menu_entries[1];
local singleuser = menu_entries[2]; local singleuser = menu_entries[2];
multiuser.name = multiuser.alternate_name;
singleuser.name = singleuser.alternate_name;
menu_entries[2] = multiuser; menu_entries[2] = multiuser;
menu_entries[1] = singleuser; menu_entries[1] = singleuser;
end end
@ -154,6 +160,11 @@ menu.welcome = {
"oot Multi user " .. "oot Multi user " ..
color.highlight("[Enter]"); color.highlight("[Enter]");
end, end,
-- Not a standard menu entry function!
alternate_name = function()
return color.highlight("B") ..
"oot Multi user";
end,
func = function() func = function()
core.setSingleUser(false); core.setSingleUser(false);
core.boot(); core.boot();
@ -168,6 +179,11 @@ menu.welcome = {
return "Boot " .. color.highlight("S") .. return "Boot " .. color.highlight("S") ..
"ingle user"; "ingle user";
end, end,
-- Not a standard menu entry function!
alternate_name = function()
return "Boot " .. color.highlight("S") ..
"ingle user " .. color.highlight("[Enter]");
end,
func = function() func = function()
core.setSingleUser(true); core.setSingleUser(true);
core.boot(); core.boot();