lualoader: Hide the rest of the private interfaces

These are less controversial than the others, thus done in a separate
commit. These are all used internally and ways to override are provided via
soon-to-be-documented API or loader.conf(5) variables.
This commit is contained in:
Kyle Evans 2018-08-19 18:37:33 +00:00
parent 12eaa305dd
commit a9edc01b20
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=338066

View File

@ -39,8 +39,18 @@ local drawer = {}
local fbsd_brand local fbsd_brand
local none local none
local menu_name_handlers
local branddefs
local logodefs
local brand_position
local logo_position
local menu_position
local frame_size
local default_shift
local shift
local function menuEntryName(drawing_menu, entry) local function menuEntryName(drawing_menu, entry)
local name_handler = drawer.menu_name_handlers[entry.entry_type] local name_handler = menu_name_handlers[entry.entry_type]
if name_handler ~= nil then if name_handler ~= nil then
return name_handler(drawing_menu, entry) return name_handler(drawing_menu, entry)
@ -56,12 +66,12 @@ local function getBranddef(brand)
return nil return nil
end end
-- Look it up -- Look it up
local branddef = drawer.branddefs[brand] local branddef = branddefs[brand]
-- Try to pull it in -- Try to pull it in
if branddef == nil then if branddef == nil then
try_include('brand-' .. brand) try_include('brand-' .. brand)
branddef = drawer.branddefs[brand] branddef = branddefs[brand]
end end
return branddef return branddef
@ -72,12 +82,12 @@ local function getLogodef(logo)
return nil return nil
end end
-- Look it up -- Look it up
local logodef = drawer.logodefs[logo] local logodef = logodefs[logo]
-- Try to pull it in -- Try to pull it in
if logodef == nil then if logodef == nil then
try_include('logo-' .. logo) try_include('logo-' .. logo)
logodef = drawer.logodefs[logo] logodef = logodefs[logo]
end end
return logodef return logodef
@ -91,11 +101,11 @@ local function draw(x, y, logo)
end end
local function drawmenu(menudef) local function drawmenu(menudef)
local x = drawer.menu_position.x local x = menu_position.x
local y = drawer.menu_position.y local y = menu_position.y
x = x + drawer.shift.x x = x + shift.x
y = y + drawer.shift.y y = y + shift.y
-- print the menu and build the alias table -- print the menu and build the alias table
local alias_table = {} local alias_table = {}
@ -135,10 +145,10 @@ local function drawmenu(menudef)
end end
local function drawbox() local function drawbox()
local x = drawer.menu_position.x - 3 local x = menu_position.x - 3
local y = drawer.menu_position.y - 1 local y = menu_position.y - 1
local w = drawer.frame_size.w local w = frame_size.w
local h = drawer.frame_size.h local h = frame_size.h
local framestyle = loader.getenv("loader_menu_frame") or "double" local framestyle = loader.getenv("loader_menu_frame") or "double"
local framespec = drawer.frame_styles[framestyle] local framespec = drawer.frame_styles[framestyle]
@ -156,8 +166,8 @@ local function drawbox()
local tr = framespec.top_right local tr = framespec.top_right
local br = framespec.bottom_right local br = framespec.bottom_right
x = x + drawer.shift.x x = x + shift.x
y = y + drawer.shift.y y = y + shift.y
screen.setcursor(x, y); printc(tl) screen.setcursor(x, y); printc(tl)
screen.setcursor(x, y + h); printc(bl) screen.setcursor(x, y + h); printc(bl)
@ -205,9 +215,9 @@ end
local function drawbrand() local function drawbrand()
local x = tonumber(loader.getenv("loader_brand_x")) or local x = tonumber(loader.getenv("loader_brand_x")) or
drawer.brand_position.x brand_position.x
local y = tonumber(loader.getenv("loader_brand_y")) or local y = tonumber(loader.getenv("loader_brand_y")) or
drawer.brand_position.y brand_position.y
local branddef = getBranddef(loader.getenv("loader_brand")) local branddef = getBranddef(loader.getenv("loader_brand"))
@ -217,16 +227,16 @@ local function drawbrand()
local graphic = branddef.graphic local graphic = branddef.graphic
x = x + drawer.shift.x x = x + shift.x
y = y + drawer.shift.y y = y + shift.y
draw(x, y, graphic) draw(x, y, graphic)
end end
local function drawlogo() local function drawlogo()
local x = tonumber(loader.getenv("loader_logo_x")) or local x = tonumber(loader.getenv("loader_logo_x")) or
drawer.logo_position.x logo_position.x
local y = tonumber(loader.getenv("loader_logo_y")) or local y = tonumber(loader.getenv("loader_logo_y")) or
drawer.logo_position.y logo_position.y
local logo = loader.getenv("loader_logo") local logo = loader.getenv("loader_logo")
local colored = color.isEnabled() local colored = color.isEnabled()
@ -244,13 +254,13 @@ local function drawlogo()
end end
if logodef ~= nil and logodef.graphic == none then if logodef ~= nil and logodef.graphic == none then
drawer.shift = logodef.shift shift = logodef.shift
else else
drawer.shift = drawer.default_shift shift = default_shift
end end
x = x + drawer.shift.x x = x + shift.x
y = y + drawer.shift.y y = y + shift.y
if logodef ~= nil and logodef.shift ~= nil then if logodef ~= nil and logodef.shift ~= nil then
x = x + logodef.shift.x x = x + logodef.shift.x
@ -271,10 +281,7 @@ fbsd_brand = {
} }
none = {""} none = {""}
-- Module exports menu_name_handlers = {
drawer.default_brand = 'fbsd'
drawer.menu_name_handlers = {
-- Menu name handlers should take the menu being drawn and entry being -- Menu name handlers should take the menu being drawn and entry being
-- drawn as parameters, and return the name of the item. -- drawn as parameters, and return the name of the item.
-- This is designed so that everything, including menu separators, may -- This is designed so that everything, including menu separators, may
@ -303,14 +310,7 @@ drawer.menu_name_handlers = {
end, end,
} }
drawer.brand_position = {x = 2, y = 1} branddefs = {
drawer.logo_position = {x = 46, y = 4}
drawer.menu_position = {x = 5, y = 10}
drawer.frame_size = {w = 42, h = 13}
drawer.default_shift = {x = 0, y = 0}
drawer.shift = drawer.default_shift
drawer.branddefs = {
-- Indexed by valid values for loader_brand in loader.conf(5). Valid -- Indexed by valid values for loader_brand in loader.conf(5). Valid
-- keys are: graphic (table depicting graphic) -- keys are: graphic (table depicting graphic)
["fbsd"] = { ["fbsd"] = {
@ -321,15 +321,7 @@ drawer.branddefs = {
}, },
} }
function drawer.addBrand(name, def) logodefs = {
drawer.branddefs[name] = def
end
function drawer.addLogo(name, def)
drawer.logodefs[name] = def
end
drawer.logodefs = {
-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys -- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
-- are: requires_color (boolean), graphic (table depicting graphic), and -- are: requires_color (boolean), graphic (table depicting graphic), and
-- shift (table containing x and y). -- shift (table containing x and y).
@ -345,6 +337,24 @@ drawer.logodefs = {
}, },
} }
brand_position = {x = 2, y = 1}
logo_position = {x = 46, y = 4}
menu_position = {x = 5, y = 10}
frame_size = {w = 42, h = 13}
default_shift = {x = 0, y = 0}
shift = default_shift
-- Module exports
drawer.default_brand = 'fbsd'
function drawer.addBrand(name, def)
branddefs[name] = def
end
function drawer.addLogo(name, def)
logodefs[name] = def
end
drawer.frame_styles = { drawer.frame_styles = {
-- Indexed by valid values for loader_menu_frame in loader.conf(5). -- Indexed by valid values for loader_menu_frame in loader.conf(5).
-- All of the keys appearing below must be set for any menu frame style -- All of the keys appearing below must be set for any menu frame style