diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2018-02-21 04:48:37 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2018-02-21 04:48:37 +0000 |
commit | a51f9f0c480fc3d10f5938c91ea0a1dd82c10fb1 (patch) | |
tree | d356907517f108e6052d0baaeada5b88f1ca27f5 | |
parent | 9a28f948ee29bfea13c8f128383acc06b2819aeb (diff) | |
download | src-a51f9f0c480fc3d10f5938c91ea0a1dd82c10fb1.tar.gz src-a51f9f0c480fc3d10f5938c91ea0a1dd82c10fb1.zip |
lualoader: Simplify menu definitions a little further
Allow "name" entries to be simple strings, instead of just functions. We
know whether we support colors or not by the time any of this is setup, so
all menu names that are basically static with colors sprinkled in are good
candidates for simplification.
Also simplify "func" in many cases where it's just invoking another function
with no arguments. The downside to this simplification is that the functions
called can no longer be trivially replaced by a local module. The upside is
that it removes another layer of indirection that we likely don't need.
These can be re-evaluated later if a compelling argument is raised, on a
case-by-case basis, for replacement.
Notes
Notes:
svn path=/head/; revision=329699
-rw-r--r-- | stand/lua/drawer.lua | 12 | ||||
-rw-r--r-- | stand/lua/menu.lua | 90 |
2 files changed, 30 insertions, 72 deletions
diff --git a/stand/lua/drawer.lua b/stand/lua/drawer.lua index 9c94c9b023d2..cc75e59648a4 100644 --- a/stand/lua/drawer.lua +++ b/stand/lua/drawer.lua @@ -48,7 +48,10 @@ local menu_entry_name = function(drawing_menu, entry) if name_handler ~= nil then return name_handler(drawing_menu, entry) end - return entry.name() + if type(entry.name) == "function" then + return entry.name() + end + return entry.name end local shift_brand_text = function(shift) @@ -174,10 +177,13 @@ drawer.menu_name_handlers = { -- drawn as parameters, and return the name of the item. -- This is designed so that everything, including menu separators, may -- have their names derived differently. The default action for entry - -- types not specified here is to call and use entry.name(). + -- types not specified here is to use entry.name directly. [core.MENU_SEPARATOR] = function(drawing_menu, entry) if entry.name ~= nil then - return entry.name() + if type(entry.name) == "function" then + return entry.name() + end + return entry.name end return "" end, diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index 3bfbdaadca96..dd12d7fabd2a 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -92,36 +92,24 @@ menu.boot_options = { -- return to welcome menu { entry_type = core.MENU_RETURN, - name = function() - return "Back to main menu" .. - color.highlight(" [Backspace]") - end + name = "Back to main menu" .. + color.highlight(" [Backspace]"), }, - -- load defaults { entry_type = core.MENU_ENTRY, - name = function() - return "Load System " .. color.highlight("D") .. - "efaults" - end, - func = function() - core.setDefaults() - end, + name = "Load System " .. color.highlight("D") .. + "efaults", + func = core.setDefaults, alias = {"d", "D"} }, - { entry_type = core.MENU_SEPARATOR, }, - { entry_type = core.MENU_SEPARATOR, - name = function() - return "Boot Options:" - end + name = "Boot Options:", }, - -- acpi { entry_type = core.MENU_ENTRY, @@ -130,9 +118,7 @@ menu.boot_options = { return OnOff(color.highlight("A") .. "CPI :", core.acpi) end, - func = function() - core.setACPI() - end, + func = core.setACPI, alias = {"a", "A"} }, -- safe mode @@ -142,9 +128,7 @@ menu.boot_options = { return OnOff("Safe " .. color.highlight("M") .. "ode :", core.sm) end, - func = function() - core.setSafeMode() - end, + func = core.setSafeMode, alias = {"m", "M"} }, -- single user @@ -154,9 +138,7 @@ menu.boot_options = { return OnOff(color.highlight("S") .. "ingle user:", core.su) end, - func = function() - core.setSingleUser() - end, + func = core.setSingleUser, alias = {"s", "S"} }, -- verbose boot @@ -166,9 +148,7 @@ menu.boot_options = { return OnOff(color.highlight("V") .. "erbose :", core.verbose) end, - func = function() - core.setVerbose() - end, + func = core.setVerbose, alias = {"v", "V"} }, }, @@ -202,79 +182,55 @@ menu.welcome = { -- boot multi user { entry_type = core.MENU_ENTRY, - name = function() - return color.highlight("B") .. - "oot Multi user " .. - color.highlight("[Enter]") - end, + name = color.highlight("B") .. "oot Multi user " .. + color.highlight("[Enter]"), -- Not a standard menu entry function! - alternate_name = function() - return color.highlight("B") .. - "oot Multi user" - end, + alternate_name = color.highlight("B") .. + "oot Multi user", 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, + name = "Boot " .. color.highlight("S") .. "ingle user", -- Not a standard menu entry function! - alternate_name = function() - return "Boot " .. color.highlight("S") .. - "ingle user " .. color.highlight("[Enter]") - end, + alternate_name = "Boot " .. color.highlight("S") .. + "ingle user " .. color.highlight("[Enter]"), 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, + name = color.highlight("Esc") .. "ape to loader prompt", 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, + name = color.highlight("R") .. "eboot", func = function() loader.perform("reboot") end, alias = {"r", "R"} }, - - { entry_type = core.MENU_SEPARATOR, }, - { entry_type = core.MENU_SEPARATOR, - name = function() - return "Options:" - end + name = "Options:", }, - -- kernel options { entry_type = core.MENU_CAROUSEL_ENTRY, @@ -305,14 +261,10 @@ menu.welcome = { end, alias = {"k", "K"} }, - -- boot options { entry_type = core.MENU_SUBMENU, - name = function() - return "Boot " .. color.highlight("O") .. - "ptions" - end, + name = "Boot " .. color.highlight("O") .. "ptions", submenu = menu.boot_options, alias = {"o", "O"} }, |