xref: /freebsd/stand/lua/drawer.lua (revision 546f18f3dadc50e6978e02b1479bc55cfa677094)
1088b4f5fSWarner Losh--
272e39d71SKyle Evans-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
372e39d71SKyle Evans--
4088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5df74a61fSKyle Evans-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6088b4f5fSWarner Losh-- All rights reserved.
7088b4f5fSWarner Losh--
8088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without
9088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions
10088b4f5fSWarner Losh-- are met:
11088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright
12088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer.
13088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright
14088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer in the
15088b4f5fSWarner Losh--    documentation and/or other materials provided with the distribution.
16088b4f5fSWarner Losh--
17088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20088b4f5fSWarner Losh-- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27088b4f5fSWarner Losh-- SUCH DAMAGE.
28088b4f5fSWarner Losh--
29088b4f5fSWarner Losh-- $FreeBSD$
30088b4f5fSWarner Losh--
31088b4f5fSWarner Losh
32aedd6be5SKyle Evanslocal color = require("color")
33aedd6be5SKyle Evanslocal config = require("config")
34aedd6be5SKyle Evanslocal core = require("core")
35aedd6be5SKyle Evanslocal screen = require("screen")
36088b4f5fSWarner Losh
37aedd6be5SKyle Evanslocal drawer = {}
38c8518398SKyle Evans
391091c8feSKyle Evanslocal fbsd_brand
40aedd6be5SKyle Evanslocal none
4102122e53SKyle Evans
42a9edc01bSKyle Evanslocal menu_name_handlers
43a9edc01bSKyle Evanslocal branddefs
44a9edc01bSKyle Evanslocal logodefs
45a9edc01bSKyle Evanslocal brand_position
46a9edc01bSKyle Evanslocal logo_position
47a9edc01bSKyle Evanslocal menu_position
48a9edc01bSKyle Evanslocal frame_size
49a9edc01bSKyle Evanslocal default_shift
50a9edc01bSKyle Evanslocal shift
51a9edc01bSKyle Evans
52322a2dddSKyle Evanslocal function menuEntryName(drawing_menu, entry)
53a9edc01bSKyle Evans	local name_handler = menu_name_handlers[entry.entry_type]
54e15abd1fSKyle Evans
559f71d421SKyle Evans	if name_handler ~= nil then
56aedd6be5SKyle Evans		return name_handler(drawing_menu, entry)
57e15abd1fSKyle Evans	end
58a51f9f0cSKyle Evans	if type(entry.name) == "function" then
59aedd6be5SKyle Evans		return entry.name()
60e15abd1fSKyle Evans	end
61a51f9f0cSKyle Evans	return entry.name
62a51f9f0cSKyle Evansend
63e15abd1fSKyle Evans
64*546f18f3SKyle Evanslocal function processFile(gfxname)
65*546f18f3SKyle Evans	if gfxname == nil then
66*546f18f3SKyle Evans		return false, "Missing filename"
67*546f18f3SKyle Evans	end
68*546f18f3SKyle Evans
69*546f18f3SKyle Evans	local ret = try_include('gfx-' .. gfxname)
70*546f18f3SKyle Evans	if ret == nil then
71*546f18f3SKyle Evans		return false, "Failed to include gfx-" .. gfxname
72*546f18f3SKyle Evans	end
73*546f18f3SKyle Evans
74*546f18f3SKyle Evans	-- Legacy format
75*546f18f3SKyle Evans	if type(ret) ~= "table" then
76*546f18f3SKyle Evans		return true
77*546f18f3SKyle Evans	end
78*546f18f3SKyle Evans
79*546f18f3SKyle Evans	for gfxtype, def in pairs(ret) do
80*546f18f3SKyle Evans		if gfxtype == "brand" then
81*546f18f3SKyle Evans			drawer.addBrand(gfxname, def)
82*546f18f3SKyle Evans		elseif gfxtype == "logo" then
83*546f18f3SKyle Evans			drawer.addLogo(gfxname, def)
84*546f18f3SKyle Evans		else
85*546f18f3SKyle Evans			return false, "Unknown graphics type '" .. gfxtype ..
86*546f18f3SKyle Evans			    "'"
87*546f18f3SKyle Evans		end
88*546f18f3SKyle Evans	end
89*546f18f3SKyle Evans
90*546f18f3SKyle Evans	return true
91*546f18f3SKyle Evansend
92*546f18f3SKyle Evans
93e21e1dbeSKyle Evanslocal function getBranddef(brand)
94e21e1dbeSKyle Evans	if brand == nil then
95e21e1dbeSKyle Evans		return nil
96e21e1dbeSKyle Evans	end
97e21e1dbeSKyle Evans	-- Look it up
98a9edc01bSKyle Evans	local branddef = branddefs[brand]
99e21e1dbeSKyle Evans
100e21e1dbeSKyle Evans	-- Try to pull it in
101e21e1dbeSKyle Evans	if branddef == nil then
102*546f18f3SKyle Evans		local res, err = processFile(brand)
103*546f18f3SKyle Evans		if not res then
104*546f18f3SKyle Evans			-- This fallback should go away after FreeBSD 13.
105e21e1dbeSKyle Evans			try_include('brand-' .. brand)
106*546f18f3SKyle Evans			-- If the fallback also failed, print whatever error
107*546f18f3SKyle Evans			-- we encountered in the original processing.
108*546f18f3SKyle Evans			if branddefs[brand] == nil then
109*546f18f3SKyle Evans				print(err)
110*546f18f3SKyle Evans				return nil
111*546f18f3SKyle Evans			end
112*546f18f3SKyle Evans		end
113*546f18f3SKyle Evans
114a9edc01bSKyle Evans		branddef = branddefs[brand]
115e21e1dbeSKyle Evans	end
116e21e1dbeSKyle Evans
117e21e1dbeSKyle Evans	return branddef
118e21e1dbeSKyle Evansend
119e21e1dbeSKyle Evans
1201091c8feSKyle Evanslocal function getLogodef(logo)
121bbb516aeSKyle Evans	if logo == nil then
122bbb516aeSKyle Evans		return nil
123bbb516aeSKyle Evans	end
1241091c8feSKyle Evans	-- Look it up
125a9edc01bSKyle Evans	local logodef = logodefs[logo]
1261091c8feSKyle Evans
1271091c8feSKyle Evans	-- Try to pull it in
1281091c8feSKyle Evans	if logodef == nil then
129*546f18f3SKyle Evans		local res, err = processFile(logo)
130*546f18f3SKyle Evans		if not res then
131*546f18f3SKyle Evans			-- This fallback should go away after FreeBSD 13.
1321091c8feSKyle Evans			try_include('logo-' .. logo)
133*546f18f3SKyle Evans			-- If the fallback also failed, print whatever error
134*546f18f3SKyle Evans			-- we encountered in the original processing.
135*546f18f3SKyle Evans			if logodefs[logo] == nil then
136*546f18f3SKyle Evans				print(err)
137*546f18f3SKyle Evans				return nil
138*546f18f3SKyle Evans			end
139*546f18f3SKyle Evans		end
140*546f18f3SKyle Evans
141a9edc01bSKyle Evans		logodef = logodefs[logo]
1421091c8feSKyle Evans	end
1431091c8feSKyle Evans
1441091c8feSKyle Evans	return logodef
1451091c8feSKyle Evansend
1461091c8feSKyle Evans
1476112ee09SKyle Evanslocal function draw(x, y, logo)
1486112ee09SKyle Evans	for i = 1, #logo do
1496112ee09SKyle Evans		screen.setcursor(x, y + i - 1)
1506112ee09SKyle Evans		printc(logo[i])
1516112ee09SKyle Evans	end
1526112ee09SKyle Evansend
1536112ee09SKyle Evans
15412eaa305SKyle Evanslocal function drawmenu(menudef)
155a9edc01bSKyle Evans	local x = menu_position.x
156a9edc01bSKyle Evans	local y = menu_position.y
15712eaa305SKyle Evans
158a9edc01bSKyle Evans	x = x + shift.x
159a9edc01bSKyle Evans	y = y + shift.y
16012eaa305SKyle Evans
16112eaa305SKyle Evans	-- print the menu and build the alias table
16212eaa305SKyle Evans	local alias_table = {}
16312eaa305SKyle Evans	local entry_num = 0
16412eaa305SKyle Evans	local menu_entries = menudef.entries
16512eaa305SKyle Evans	local effective_line_num = 0
16612eaa305SKyle Evans	if type(menu_entries) == "function" then
16712eaa305SKyle Evans		menu_entries = menu_entries()
16812eaa305SKyle Evans	end
16912eaa305SKyle Evans	for _, e in ipairs(menu_entries) do
17012eaa305SKyle Evans		-- Allow menu items to be conditionally visible by specifying
17112eaa305SKyle Evans		-- a visible function.
17212eaa305SKyle Evans		if e.visible ~= nil and not e.visible() then
17312eaa305SKyle Evans			goto continue
17412eaa305SKyle Evans		end
17512eaa305SKyle Evans		effective_line_num = effective_line_num + 1
17612eaa305SKyle Evans		if e.entry_type ~= core.MENU_SEPARATOR then
17712eaa305SKyle Evans			entry_num = entry_num + 1
17812eaa305SKyle Evans			screen.setcursor(x, y + effective_line_num)
17912eaa305SKyle Evans
18012eaa305SKyle Evans			printc(entry_num .. ". " .. menuEntryName(menudef, e))
18112eaa305SKyle Evans
18212eaa305SKyle Evans			-- fill the alias table
18312eaa305SKyle Evans			alias_table[tostring(entry_num)] = e
18412eaa305SKyle Evans			if e.alias ~= nil then
18512eaa305SKyle Evans				for _, a in ipairs(e.alias) do
18612eaa305SKyle Evans					alias_table[a] = e
18712eaa305SKyle Evans				end
18812eaa305SKyle Evans			end
18912eaa305SKyle Evans		else
19012eaa305SKyle Evans			screen.setcursor(x, y + effective_line_num)
19112eaa305SKyle Evans			printc(menuEntryName(menudef, e))
19212eaa305SKyle Evans		end
19312eaa305SKyle Evans		::continue::
19412eaa305SKyle Evans	end
19512eaa305SKyle Evans	return alias_table
19612eaa305SKyle Evansend
19712eaa305SKyle Evans
19890a25417SKyle Evanslocal function defaultframe()
19990a25417SKyle Evans	if core.isSerialConsole() then
20090a25417SKyle Evans		return "ascii"
20190a25417SKyle Evans	end
20290a25417SKyle Evans	return "double"
20390a25417SKyle Evansend
20490a25417SKyle Evans
20512eaa305SKyle Evanslocal function drawbox()
206a9edc01bSKyle Evans	local x = menu_position.x - 3
207a9edc01bSKyle Evans	local y = menu_position.y - 1
208a9edc01bSKyle Evans	local w = frame_size.w
209a9edc01bSKyle Evans	local h = frame_size.h
21012eaa305SKyle Evans
21190a25417SKyle Evans	local framestyle = loader.getenv("loader_menu_frame") or defaultframe()
21212eaa305SKyle Evans	local framespec = drawer.frame_styles[framestyle]
21312eaa305SKyle Evans	-- If we don't have a framespec for the current frame style, just don't
21412eaa305SKyle Evans	-- draw a box.
21512eaa305SKyle Evans	if framespec == nil then
21612eaa305SKyle Evans		return
21712eaa305SKyle Evans	end
21812eaa305SKyle Evans
21912eaa305SKyle Evans	local hl = framespec.horizontal
22012eaa305SKyle Evans	local vl = framespec.vertical
22112eaa305SKyle Evans
22212eaa305SKyle Evans	local tl = framespec.top_left
22312eaa305SKyle Evans	local bl = framespec.bottom_left
22412eaa305SKyle Evans	local tr = framespec.top_right
22512eaa305SKyle Evans	local br = framespec.bottom_right
22612eaa305SKyle Evans
227a9edc01bSKyle Evans	x = x + shift.x
228a9edc01bSKyle Evans	y = y + shift.y
22912eaa305SKyle Evans
23012eaa305SKyle Evans	screen.setcursor(x, y); printc(tl)
23112eaa305SKyle Evans	screen.setcursor(x, y + h); printc(bl)
23212eaa305SKyle Evans	screen.setcursor(x + w, y); printc(tr)
23312eaa305SKyle Evans	screen.setcursor(x + w, y + h); printc(br)
23412eaa305SKyle Evans
23512eaa305SKyle Evans	screen.setcursor(x + 1, y)
23612eaa305SKyle Evans	for _ = 1, w - 1 do
23712eaa305SKyle Evans		printc(hl)
23812eaa305SKyle Evans	end
23912eaa305SKyle Evans
24012eaa305SKyle Evans	screen.setcursor(x + 1, y + h)
24112eaa305SKyle Evans	for _ = 1, w - 1 do
24212eaa305SKyle Evans		printc(hl)
24312eaa305SKyle Evans	end
24412eaa305SKyle Evans
24512eaa305SKyle Evans	for i = 1, h - 1 do
24612eaa305SKyle Evans		screen.setcursor(x, y + i)
24712eaa305SKyle Evans		printc(vl)
24812eaa305SKyle Evans		screen.setcursor(x + w, y + i)
24912eaa305SKyle Evans		printc(vl)
25012eaa305SKyle Evans	end
25112eaa305SKyle Evans
25212eaa305SKyle Evans	local menu_header = loader.getenv("loader_menu_title") or
25312eaa305SKyle Evans	    "Welcome to FreeBSD"
25412eaa305SKyle Evans	local menu_header_align = loader.getenv("loader_menu_title_align")
25512eaa305SKyle Evans	local menu_header_x
25612eaa305SKyle Evans
25712eaa305SKyle Evans	if menu_header_align ~= nil then
25812eaa305SKyle Evans		menu_header_align = menu_header_align:lower()
25912eaa305SKyle Evans		if menu_header_align == "left" then
26012eaa305SKyle Evans			-- Just inside the left border on top
26112eaa305SKyle Evans			menu_header_x = x + 1
26212eaa305SKyle Evans		elseif menu_header_align == "right" then
26312eaa305SKyle Evans			-- Just inside the right border on top
26412eaa305SKyle Evans			menu_header_x = x + w - #menu_header
26512eaa305SKyle Evans		end
26612eaa305SKyle Evans	end
26712eaa305SKyle Evans	if menu_header_x == nil then
26812eaa305SKyle Evans		menu_header_x = x + (w / 2) - (#menu_header / 2)
26912eaa305SKyle Evans	end
27012eaa305SKyle Evans	screen.setcursor(menu_header_x, y)
27112eaa305SKyle Evans	printc(menu_header)
27212eaa305SKyle Evansend
27312eaa305SKyle Evans
27412eaa305SKyle Evanslocal function drawbrand()
27512eaa305SKyle Evans	local x = tonumber(loader.getenv("loader_brand_x")) or
276a9edc01bSKyle Evans	    brand_position.x
27712eaa305SKyle Evans	local y = tonumber(loader.getenv("loader_brand_y")) or
278a9edc01bSKyle Evans	    brand_position.y
27912eaa305SKyle Evans
28012eaa305SKyle Evans	local branddef = getBranddef(loader.getenv("loader_brand"))
28112eaa305SKyle Evans
28212eaa305SKyle Evans	if branddef == nil then
28312eaa305SKyle Evans		branddef = getBranddef(drawer.default_brand)
28412eaa305SKyle Evans	end
28512eaa305SKyle Evans
28612eaa305SKyle Evans	local graphic = branddef.graphic
28712eaa305SKyle Evans
288a9edc01bSKyle Evans	x = x + shift.x
289a9edc01bSKyle Evans	y = y + shift.y
29012eaa305SKyle Evans	draw(x, y, graphic)
29112eaa305SKyle Evansend
29212eaa305SKyle Evans
29312eaa305SKyle Evanslocal function drawlogo()
29412eaa305SKyle Evans	local x = tonumber(loader.getenv("loader_logo_x")) or
295a9edc01bSKyle Evans	    logo_position.x
29612eaa305SKyle Evans	local y = tonumber(loader.getenv("loader_logo_y")) or
297a9edc01bSKyle Evans	    logo_position.y
29812eaa305SKyle Evans
29912eaa305SKyle Evans	local logo = loader.getenv("loader_logo")
30012eaa305SKyle Evans	local colored = color.isEnabled()
30112eaa305SKyle Evans
30212eaa305SKyle Evans	local logodef = getLogodef(logo)
30312eaa305SKyle Evans
30412eaa305SKyle Evans	if logodef == nil or logodef.graphic == nil or
30512eaa305SKyle Evans	    (not colored and logodef.requires_color) then
30612eaa305SKyle Evans		-- Choose a sensible default
30712eaa305SKyle Evans		if colored then
3082c690e2aSKyle Evans			logodef = getLogodef(drawer.default_color_logodef)
30912eaa305SKyle Evans		else
3102c690e2aSKyle Evans			logodef = getLogodef(drawer.default_bw_logodef)
31112eaa305SKyle Evans		end
3126697f577SKyle Evans
3136697f577SKyle Evans		-- Something has gone terribly wrong.
3146697f577SKyle Evans		if logodef == nil then
3156697f577SKyle Evans			logodef = getLogodef(drawer.default_fallback_logodef)
3166697f577SKyle Evans		end
31712eaa305SKyle Evans	end
31812eaa305SKyle Evans
31912eaa305SKyle Evans	if logodef ~= nil and logodef.graphic == none then
320a9edc01bSKyle Evans		shift = logodef.shift
32112eaa305SKyle Evans	else
322a9edc01bSKyle Evans		shift = default_shift
32312eaa305SKyle Evans	end
32412eaa305SKyle Evans
325a9edc01bSKyle Evans	x = x + shift.x
326a9edc01bSKyle Evans	y = y + shift.y
32712eaa305SKyle Evans
32812eaa305SKyle Evans	if logodef ~= nil and logodef.shift ~= nil then
32912eaa305SKyle Evans		x = x + logodef.shift.x
33012eaa305SKyle Evans		y = y + logodef.shift.y
33112eaa305SKyle Evans	end
33212eaa305SKyle Evans
33312eaa305SKyle Evans	draw(x, y, logodef.graphic)
33412eaa305SKyle Evansend
33512eaa305SKyle Evans
3361091c8feSKyle Evansfbsd_brand = {
337088b4f5fSWarner Losh"  ______               ____   _____ _____  ",
338088b4f5fSWarner Losh" |  ____|             |  _ \\ / ____|  __ \\ ",
339088b4f5fSWarner Losh" | |___ _ __ ___  ___ | |_) | (___ | |  | |",
340088b4f5fSWarner Losh" |  ___| '__/ _ \\/ _ \\|  _ < \\___ \\| |  | |",
341088b4f5fSWarner Losh" | |   | | |  __/  __/| |_) |____) | |__| |",
342088b4f5fSWarner Losh" | |   | | |    |    ||     |      |      |",
343088b4f5fSWarner Losh" |_|   |_|  \\___|\\___||____/|_____/|_____/ "
344aedd6be5SKyle Evans}
345aedd6be5SKyle Evansnone = {""}
346088b4f5fSWarner Losh
347a9edc01bSKyle Evansmenu_name_handlers = {
348b5746545SKyle Evans	-- Menu name handlers should take the menu being drawn and entry being
349b5746545SKyle Evans	-- drawn as parameters, and return the name of the item.
350b5746545SKyle Evans	-- This is designed so that everything, including menu separators, may
351b5746545SKyle Evans	-- have their names derived differently. The default action for entry
352a51f9f0cSKyle Evans	-- types not specified here is to use entry.name directly.
353e2df27e3SKyle Evans	[core.MENU_SEPARATOR] = function(_, entry)
354dd65496aSKyle Evans		if entry.name ~= nil then
355a51f9f0cSKyle Evans			if type(entry.name) == "function" then
356dd65496aSKyle Evans				return entry.name()
357dd65496aSKyle Evans			end
358a51f9f0cSKyle Evans			return entry.name
359a51f9f0cSKyle Evans		end
360dd65496aSKyle Evans		return ""
361dd65496aSKyle Evans	end,
362e2df27e3SKyle Evans	[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
363aedd6be5SKyle Evans		local carid = entry.carousel_id
364aedd6be5SKyle Evans		local caridx = config.getCarouselIndex(carid)
3654f437f9eSKyle Evans		local choices = entry.items
3664f437f9eSKyle Evans		if type(choices) == "function" then
3674f437f9eSKyle Evans			choices = choices()
3684f437f9eSKyle Evans		end
3699f71d421SKyle Evans		if #choices < caridx then
370aedd6be5SKyle Evans			caridx = 1
371b5746545SKyle Evans		end
372aedd6be5SKyle Evans		return entry.name(caridx, choices[caridx], choices)
373b5746545SKyle Evans	end,
374aedd6be5SKyle Evans}
375b5746545SKyle Evans
376a9edc01bSKyle Evansbranddefs = {
377699578a6SKyle Evans	-- Indexed by valid values for loader_brand in loader.conf(5). Valid
378699578a6SKyle Evans	-- keys are: graphic (table depicting graphic)
37929aa5794SKyle Evans	["fbsd"] = {
3801091c8feSKyle Evans		graphic = fbsd_brand,
38129aa5794SKyle Evans	},
38229aa5794SKyle Evans	["none"] = {
38329aa5794SKyle Evans		graphic = none,
38429aa5794SKyle Evans	},
385aedd6be5SKyle Evans}
38629aa5794SKyle Evans
387a9edc01bSKyle Evanslogodefs = {
388bb26c57dSKyle Evans	-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
389752b2d40SKyle Evans	-- are: requires_color (boolean), graphic (table depicting graphic), and
390bb26c57dSKyle Evans	-- shift (table containing x and y).
391bb26c57dSKyle Evans	["tribute"] = {
3921091c8feSKyle Evans		graphic = fbsd_brand,
393bb26c57dSKyle Evans	},
394bb26c57dSKyle Evans	["tributebw"] = {
3951091c8feSKyle Evans		graphic = fbsd_brand,
396bb26c57dSKyle Evans	},
397bb26c57dSKyle Evans	["none"] = {
398752b2d40SKyle Evans		graphic = none,
399bb26c57dSKyle Evans		shift = {x = 17, y = 0},
400bb26c57dSKyle Evans	},
401aedd6be5SKyle Evans}
402bb26c57dSKyle Evans
403a9edc01bSKyle Evansbrand_position = {x = 2, y = 1}
404a9edc01bSKyle Evanslogo_position = {x = 46, y = 4}
405a9edc01bSKyle Evansmenu_position = {x = 5, y = 10}
406a9edc01bSKyle Evansframe_size = {w = 42, h = 13}
407a9edc01bSKyle Evansdefault_shift = {x = 0, y = 0}
408a9edc01bSKyle Evansshift = default_shift
409a9edc01bSKyle Evans
410a9edc01bSKyle Evans-- Module exports
411a9edc01bSKyle Evansdrawer.default_brand = 'fbsd'
4122c690e2aSKyle Evansdrawer.default_color_logodef = 'orb'
4132c690e2aSKyle Evansdrawer.default_bw_logodef = 'orbbw'
4146697f577SKyle Evans-- For when things go terribly wrong; this def should be present here in the
4156697f577SKyle Evans-- drawer module in case it's a filesystem issue.
4166697f577SKyle Evansdrawer.default_fallback_logodef = 'none'
417a9edc01bSKyle Evans
418*546f18f3SKyle Evans-- These should go away after FreeBSD 13; only available for backwards
419*546f18f3SKyle Evans-- compatibility with old logo- files.
420a9edc01bSKyle Evansfunction drawer.addBrand(name, def)
421a9edc01bSKyle Evans	branddefs[name] = def
422a9edc01bSKyle Evansend
423a9edc01bSKyle Evans
424a9edc01bSKyle Evansfunction drawer.addLogo(name, def)
425a9edc01bSKyle Evans	logodefs[name] = def
426a9edc01bSKyle Evansend
427a9edc01bSKyle Evans
428379e652eSKyle Evansdrawer.frame_styles = {
429379e652eSKyle Evans	-- Indexed by valid values for loader_menu_frame in loader.conf(5).
430379e652eSKyle Evans	-- All of the keys appearing below must be set for any menu frame style
431379e652eSKyle Evans	-- added to drawer.frame_styles.
432379e652eSKyle Evans	["ascii"] = {
433379e652eSKyle Evans		horizontal	= "-",
434379e652eSKyle Evans		vertical	= "|",
435379e652eSKyle Evans		top_left	= "+",
436379e652eSKyle Evans		bottom_left	= "+",
437379e652eSKyle Evans		top_right	= "+",
438379e652eSKyle Evans		bottom_right	= "+",
439379e652eSKyle Evans	},
440379e652eSKyle Evans	["single"] = {
44156758831SToomas Soome		horizontal	= "\xE2\x94\x80",
44256758831SToomas Soome		vertical	= "\xE2\x94\x82",
44356758831SToomas Soome		top_left	= "\xE2\x94\x8C",
44456758831SToomas Soome		bottom_left	= "\xE2\x94\x94",
44556758831SToomas Soome		top_right	= "\xE2\x94\x90",
44656758831SToomas Soome		bottom_right	= "\xE2\x94\x98",
447379e652eSKyle Evans	},
448379e652eSKyle Evans	["double"] = {
44956758831SToomas Soome		horizontal	= "\xE2\x95\x90",
45056758831SToomas Soome		vertical	= "\xE2\x95\x91",
45156758831SToomas Soome		top_left	= "\xE2\x95\x94",
45256758831SToomas Soome		bottom_left	= "\xE2\x95\x9A",
45356758831SToomas Soome		top_right	= "\xE2\x95\x97",
45456758831SToomas Soome		bottom_right	= "\xE2\x95\x9D",
455379e652eSKyle Evans	},
456379e652eSKyle Evans}
457379e652eSKyle Evans
45812eaa305SKyle Evansfunction drawer.drawscreen(menudef)
459088b4f5fSWarner Losh	-- drawlogo() must go first.
460088b4f5fSWarner Losh	-- it determines the positions of other elements
46112eaa305SKyle Evans	drawlogo()
46212eaa305SKyle Evans	drawbrand()
46312eaa305SKyle Evans	drawbox()
46412eaa305SKyle Evans	return drawmenu(menudef)
465088b4f5fSWarner Loshend
466088b4f5fSWarner Losh
467aedd6be5SKyle Evansreturn drawer
468