lualoader: improve the design of the brand-/logo- mechanism

In the previous world order, any brand/logo was forced to pull in the
drawer and call drawer.add{Brand,Logo} with the name their brand/logo is
taking and a table describing it.

In the new world order, these files just need to return a table that maps
out graphics types to a table of the exact same format as what was
previously being passed back into the drawer. The appeal here is not needing
to grab a reference back to the drawer module and having a cleaner
data-driven looking format for these. The format has been renamed to 'gfx-*'
prefixes and each one can provide a logo and a brand.

drawer.addBrand/drawer.addLogo will remain in place until FreeBSD 13, as
there's no overhead to them and it's not yet worth the break in
compatibility with any pre-existing brands and logos.

Reviewed by:	freqlabs
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D24966
This commit is contained in:
Kyle Evans 2020-10-04 22:41:43 +00:00
parent 3331a1d173
commit 546f18f3da
8 changed files with 178 additions and 138 deletions

View File

@ -36,6 +36,13 @@
# xargs -n1 | sort | uniq -d;
# done
# 20201004: logo files renamed to type-agnostic gfx-*.lua
OLD_FILES+=boot/lua/logo-beastie.lua
OLD_FILES+=boot/lua/logo-beastiebw.lua
OLD_FILES+=boot/lua/logo-fbsdbw.lua
OLD_FILES+=boot/lua/logo-orb.lua
OLD_FILES+=boot/lua/logo-orbbw.lua
# 20200923: memfd_test moved to /usr/tests/sys/posixshm
OLD_FILES+=usr/tests/sys/kern/memfd_test

View File

@ -20,11 +20,11 @@ FILES= cli.lua \
drawer.lua \
hook.lua \
loader.lua \
logo-beastie.lua \
logo-beastiebw.lua \
logo-fbsdbw.lua \
logo-orb.lua \
logo-orbbw.lua \
gfx-beastie.lua \
gfx-beastiebw.lua \
gfx-fbsdbw.lua \
gfx-orb.lua \
gfx-orbbw.lua \
menu.lua \
password.lua \
screen.lua

View File

@ -61,6 +61,35 @@ local function menuEntryName(drawing_menu, entry)
return entry.name
end
local function processFile(gfxname)
if gfxname == nil then
return false, "Missing filename"
end
local ret = try_include('gfx-' .. gfxname)
if ret == nil then
return false, "Failed to include gfx-" .. gfxname
end
-- Legacy format
if type(ret) ~= "table" then
return true
end
for gfxtype, def in pairs(ret) do
if gfxtype == "brand" then
drawer.addBrand(gfxname, def)
elseif gfxtype == "logo" then
drawer.addLogo(gfxname, def)
else
return false, "Unknown graphics type '" .. gfxtype ..
"'"
end
end
return true
end
local function getBranddef(brand)
if brand == nil then
return nil
@ -70,7 +99,18 @@ local function getBranddef(brand)
-- Try to pull it in
if branddef == nil then
local res, err = processFile(brand)
if not res then
-- This fallback should go away after FreeBSD 13.
try_include('brand-' .. brand)
-- If the fallback also failed, print whatever error
-- we encountered in the original processing.
if branddefs[brand] == nil then
print(err)
return nil
end
end
branddef = branddefs[brand]
end
@ -86,7 +126,18 @@ local function getLogodef(logo)
-- Try to pull it in
if logodef == nil then
local res, err = processFile(logo)
if not res then
-- This fallback should go away after FreeBSD 13.
try_include('logo-' .. logo)
-- If the fallback also failed, print whatever error
-- we encountered in the original processing.
if logodefs[logo] == nil then
print(err)
return nil
end
end
logodef = logodefs[logo]
end
@ -364,6 +415,8 @@ drawer.default_bw_logodef = 'orbbw'
-- drawer module in case it's a filesystem issue.
drawer.default_fallback_logodef = 'none'
-- These should go away after FreeBSD 13; only available for backwards
-- compatibility with old logo- files.
function drawer.addBrand(name, def)
branddefs[name] = def
end

View File

@ -27,9 +27,9 @@
-- $FreeBSD$
--
local drawer = require("drawer")
local beastie_color = {
return {
logo = {
graphic = {
" \027[31m, ,",
" /( )`",
" \\ \\___ / |",
@ -48,12 +48,8 @@ local beastie_color = {
" \\ / /\\",
" \027[36m______\027[31m( (_ / \\______/",
" \027[36m,' ,-----' |",
" `--{__________)\027[m"
}
drawer.addLogo("beastie", {
" `--{__________)\027[m",
},
requires_color = true,
graphic = beastie_color,
})
return true
}
}

View File

@ -27,9 +27,9 @@
-- $FreeBSD$
--
local drawer = require("drawer")
local beastiebw = {
return {
logo = {
graphic = {
" , ,",
" /( )`",
" \\ \\___ / |",
@ -48,11 +48,7 @@ local beastiebw = {
" \\ / /\\",
" ______( (_ / \\______/",
" ,' ,-----' |",
" `--{__________)"
" `--{__________)",
},
}
}
drawer.addLogo("beastiebw", {
graphic = beastiebw,
})
return true

View File

@ -27,9 +27,9 @@
-- $FreeBSD$
--
local drawer = require("drawer")
local fbsd_logo = {
return {
logo = {
graphic = {
" ______",
" | ____| __ ___ ___ ",
" | |__ | '__/ _ \\/ _ \\",
@ -42,12 +42,8 @@ local fbsd_logo = {
" | _ < \\___ \\| | | |",
" | |_) |____) | |__| |",
" | | | |",
" |____/|_____/|_____/"
}
drawer.addLogo("fbsdbw", {
graphic = fbsd_logo,
" |____/|_____/|_____/",
},
shift = {x = 5, y = 4},
})
return true
}
}

View File

@ -27,9 +27,9 @@
-- $FreeBSD$
--
local drawer = require("drawer")
local orb_color = {
return {
logo = {
graphic = {
" \027[31m``` \027[31;1m`\027[31m",
" s` `.....---...\027[31;1m....--.``` -/\027[31m",
" +o .--` \027[31;1m/y:` +.\027[31m",
@ -44,13 +44,9 @@ local orb_color = {
" -- \027[31;1m-.\027[31m",
" `:` \027[31;1m`:`",
" \027[31;1m.-- `--.",
" .---.....----.\027[m"
}
drawer.addLogo("orb", {
" .---.....----.\027[m",
},
requires_color = true,
graphic = orb_color,
shift = {x = 2, y = 4},
})
return true
}
}

View File

@ -27,9 +27,9 @@
-- $FreeBSD$
--
local drawer = require("drawer")
local orbbw = {
return {
logo = {
graphic = {
" ``` `",
" s` `.....---.......--.``` -/",
" +o .--` /y:` +.",
@ -44,12 +44,8 @@ local orbbw = {
" -- -.",
" `:` `:`",
" .-- `--.",
" .---.....----."
}
drawer.addLogo("orbbw", {
graphic = orbbw,
" .---.....----.",
},
shift = {x = 2, y = 4},
})
return true
}
}