Page MenuHomeFreeBSD

loader: create a generic vendor sub-menu place holder

Authored by imp on Mar 31 2021, 12:44 AM.



Add a dummy vendor menu entry on the main welcome menu. Vendors can override
this in their local.lua file to create whatever sub-menu they need for their

Diff Detail

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

imp requested review of this revision.Mar 31 2021, 12:44 AM
imp added inline comments.

Kyle pointed out in email something that makes me want to retract this entire paragraph.
It's possible, and we should document it.

+1 in advance for the idea of creating a vendor entry and changing the example to just reference using the vendor entry. I'll likely come back through after and add an example of modifying a submenu or something (e.g., adding another boot option) just to have one of those covered.

Actually, you can go ahead and tack this on there after the vendor example; I suspect the vendor example will be more useful to folks and the below is just for informational purposes.

local color = require('color')
local core = require('core')
local menu = require('menu')

-- This is a silly example that rotates local_option through the values
-- 0 to 4.  local_option would still need to be used elsewhere.
local local_option = 0

-- The `entries` of a menu may either be a table or a function.  In this
-- example we're augmenting a menu that just has a static table, but if we
-- wanted to be more robust then we would need to instead check the type
-- of `stock_options` here to determine our next move.
-- If `entries` is a table, then the stock menu system won't be changing it
-- so we can just add our menu option as we do below.
-- If `entries` is a function, then we would need to provide a new function to
-- replace `entries` that does a core.deepCopyTable() of the result and adds
-- the below item to it.  The deep copy is necessary to avoid duplicating our
-- new menu item and allowing the menu to alter its behavior however it pleases.
local stock_options = menu.boot_options.entries
stock_options[#stock_options + 1] = {
	entry_type = core.MENU_ENTRY,
	name = function()
		return color.highlight('L') ..
		    "ocal Option     : " .. local_option
	func = function()
		local_option = (local_option + 1) % 5
	alias= {"l", "L"}

Update with the suggestions from Kyle.
I didn't do the rename / redirect thing you suggested in email, though... should I?

One last round of example polishing.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 1 2021, 4:05 AM
This revision was automatically updated to reflect the committed changes.