xref: /freebsd/stand/lua/drawer.lua (revision 379e652e1b775820acdde1b52b4157d21dfc5128)
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
39aedd6be5SKyle Evanslocal fbsd_logo
40aedd6be5SKyle Evanslocal beastie_color
41aedd6be5SKyle Evanslocal beastie
42aedd6be5SKyle Evanslocal fbsd_logo_v
43e2df27e3SKyle Evanslocal orb_color
44aedd6be5SKyle Evanslocal orb
45aedd6be5SKyle Evanslocal none
46aedd6be5SKyle Evanslocal none_shifted = false
4702122e53SKyle Evans
48322a2dddSKyle Evanslocal function menuEntryName(drawing_menu, entry)
49aedd6be5SKyle Evans	local name_handler = drawer.menu_name_handlers[entry.entry_type]
50e15abd1fSKyle Evans
519f71d421SKyle Evans	if name_handler ~= nil then
52aedd6be5SKyle Evans		return name_handler(drawing_menu, entry)
53e15abd1fSKyle Evans	end
54a51f9f0cSKyle Evans	if type(entry.name) == "function" then
55aedd6be5SKyle Evans		return entry.name()
56e15abd1fSKyle Evans	end
57a51f9f0cSKyle Evans	return entry.name
58a51f9f0cSKyle Evansend
59e15abd1fSKyle Evans
60322a2dddSKyle Evanslocal function shiftBrandText(shift)
61aedd6be5SKyle Evans	drawer.brand_position.x = drawer.brand_position.x + shift.x
62aedd6be5SKyle Evans	drawer.brand_position.y = drawer.brand_position.y + shift.y
63aedd6be5SKyle Evans	drawer.menu_position.x = drawer.menu_position.x + shift.x
64aedd6be5SKyle Evans	drawer.menu_position.y = drawer.menu_position.y + shift.y
65aedd6be5SKyle Evans	drawer.box_pos_dim.x = drawer.box_pos_dim.x + shift.x
66aedd6be5SKyle Evans	drawer.box_pos_dim.y = drawer.box_pos_dim.y + shift.y
67e15abd1fSKyle Evansend
68e15abd1fSKyle Evans
6902122e53SKyle Evansfbsd_logo = {
70088b4f5fSWarner Losh"  ______               ____   _____ _____  ",
71088b4f5fSWarner Losh" |  ____|             |  _ \\ / ____|  __ \\ ",
72088b4f5fSWarner Losh" | |___ _ __ ___  ___ | |_) | (___ | |  | |",
73088b4f5fSWarner Losh" |  ___| '__/ _ \\/ _ \\|  _ < \\___ \\| |  | |",
74088b4f5fSWarner Losh" | |   | | |  __/  __/| |_) |____) | |__| |",
75088b4f5fSWarner Losh" | |   | | |    |    ||     |      |      |",
76088b4f5fSWarner Losh" |_|   |_|  \\___|\\___||____/|_____/|_____/ "
77aedd6be5SKyle Evans}
78088b4f5fSWarner Losh
7902122e53SKyle Evansbeastie_color = {
80088b4f5fSWarner Losh"               \027[31m,        ,",
81088b4f5fSWarner Losh"              /(        )`",
82088b4f5fSWarner Losh"              \\ \\___   / |",
83088b4f5fSWarner Losh"              /- \027[37m_\027[31m  `-/  '",
84088b4f5fSWarner Losh"             (\027[37m/\\/ \\\027[31m \\   /\\",
85088b4f5fSWarner Losh"             \027[37m/ /   |\027[31m `    \\",
86088b4f5fSWarner Losh"             \027[34mO O   \027[37m) \027[31m/    |",
87088b4f5fSWarner Losh"             \027[37m`-^--'\027[31m`<     '",
88088b4f5fSWarner Losh"            (_.)  _  )   /",
89088b4f5fSWarner Losh"             `.___/`    /",
90088b4f5fSWarner Losh"               `-----' /",
91088b4f5fSWarner Losh"  \027[33m<----.\027[31m     __ / __   \\",
92088b4f5fSWarner Losh"  \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
93088b4f5fSWarner Losh"  \027[33m<----'\027[31m    `--' `.__,' \\",
94088b4f5fSWarner Losh"               |        |",
95088b4f5fSWarner Losh"                \\       /       /\\",
96088b4f5fSWarner Losh"           \027[36m______\027[31m( (_  / \\______/",
97088b4f5fSWarner Losh"         \027[36m,'  ,-----'   |",
98088b4f5fSWarner Losh"         `--{__________)\027[37m"
99aedd6be5SKyle Evans}
100088b4f5fSWarner Losh
10102122e53SKyle Evansbeastie = {
102088b4f5fSWarner Losh"               ,        ,",
103088b4f5fSWarner Losh"              /(        )`",
104088b4f5fSWarner Losh"              \\ \\___   / |",
105088b4f5fSWarner Losh"              /- _  `-/  '",
106088b4f5fSWarner Losh"             (/\\/ \\ \\   /\\",
107088b4f5fSWarner Losh"             / /   | `    \\",
108088b4f5fSWarner Losh"             O O   ) /    |",
109088b4f5fSWarner Losh"             `-^--'`<     '",
110088b4f5fSWarner Losh"            (_.)  _  )   /",
111088b4f5fSWarner Losh"             `.___/`    /",
112088b4f5fSWarner Losh"               `-----' /",
113088b4f5fSWarner Losh"  <----.     __ / __   \\",
114088b4f5fSWarner Losh"  <----|====O)))==) \\) /====|",
115088b4f5fSWarner Losh"  <----'    `--' `.__,' \\",
116088b4f5fSWarner Losh"               |        |",
117088b4f5fSWarner Losh"                \\       /       /\\",
118088b4f5fSWarner Losh"           ______( (_  / \\______/",
119088b4f5fSWarner Losh"         ,'  ,-----'   |",
120088b4f5fSWarner Losh"         `--{__________)"
121aedd6be5SKyle Evans}
122088b4f5fSWarner Losh
12302122e53SKyle Evansfbsd_logo_v = {
124088b4f5fSWarner Losh"  ______",
125088b4f5fSWarner Losh" |  ____| __ ___  ___ ",
126088b4f5fSWarner Losh" | |__ | '__/ _ \\/ _ \\",
127088b4f5fSWarner Losh" |  __|| | |  __/  __/",
128088b4f5fSWarner Losh" | |   | | |    |    |",
129088b4f5fSWarner Losh" |_|   |_|  \\___|\\___|",
130088b4f5fSWarner Losh"  ____   _____ _____",
131088b4f5fSWarner Losh" |  _ \\ / ____|  __ \\",
132088b4f5fSWarner Losh" | |_) | (___ | |  | |",
133088b4f5fSWarner Losh" |  _ < \\___ \\| |  | |",
134088b4f5fSWarner Losh" | |_) |____) | |__| |",
135088b4f5fSWarner Losh" |     |      |      |",
136088b4f5fSWarner Losh" |____/|_____/|_____/"
137aedd6be5SKyle Evans}
138088b4f5fSWarner Losh
13902122e53SKyle Evansorb_color = {
140088b4f5fSWarner Losh"  \027[31m```                        \027[31;1m`\027[31m",
141088b4f5fSWarner Losh" s` `.....---...\027[31;1m....--.```   -/\027[31m",
142088b4f5fSWarner Losh" +o   .--`         \027[31;1m/y:`      +.\027[31m",
143088b4f5fSWarner Losh"  yo`:.            \027[31;1m:o      `+-\027[31m",
144088b4f5fSWarner Losh"   y/               \027[31;1m-/`   -o/\027[31m",
145088b4f5fSWarner Losh"  .-                  \027[31;1m::/sy+:.\027[31m",
146088b4f5fSWarner Losh"  /                     \027[31;1m`--  /\027[31m",
147088b4f5fSWarner Losh" `:                          \027[31;1m:`\027[31m",
148088b4f5fSWarner Losh" `:                          \027[31;1m:`\027[31m",
149088b4f5fSWarner Losh"  /                          \027[31;1m/\027[31m",
150088b4f5fSWarner Losh"  .-                        \027[31;1m-.\027[31m",
151088b4f5fSWarner Losh"   --                      \027[31;1m-.\027[31m",
152088b4f5fSWarner Losh"    `:`                  \027[31;1m`:`",
153088b4f5fSWarner Losh"      \027[31;1m.--             `--.",
154088b4f5fSWarner Losh"         .---.....----.\027[37m"
155aedd6be5SKyle Evans}
156088b4f5fSWarner Losh
15702122e53SKyle Evansorb = {
158088b4f5fSWarner Losh"  ```                        `",
159088b4f5fSWarner Losh" s` `.....---.......--.```   -/",
160088b4f5fSWarner Losh" +o   .--`         /y:`      +.",
161088b4f5fSWarner Losh"  yo`:.            :o      `+-",
162088b4f5fSWarner Losh"   y/               -/`   -o/",
163088b4f5fSWarner Losh"  .-                  ::/sy+:.",
164088b4f5fSWarner Losh"  /                     `--  /",
165088b4f5fSWarner Losh" `:                          :`",
166088b4f5fSWarner Losh" `:                          :`",
167088b4f5fSWarner Losh"  /                          /",
168088b4f5fSWarner Losh"  .-                        -.",
169088b4f5fSWarner Losh"   --                      -.",
170088b4f5fSWarner Losh"    `:`                  `:`",
171088b4f5fSWarner Losh"      .--             `--.",
172088b4f5fSWarner Losh"         .---.....----."
173aedd6be5SKyle Evans}
174088b4f5fSWarner Losh
175aedd6be5SKyle Evansnone = {""}
176088b4f5fSWarner Losh
177b5746545SKyle Evans-- Module exports
178b5746545SKyle Evansdrawer.menu_name_handlers = {
179b5746545SKyle Evans	-- Menu name handlers should take the menu being drawn and entry being
180b5746545SKyle Evans	-- drawn as parameters, and return the name of the item.
181b5746545SKyle Evans	-- This is designed so that everything, including menu separators, may
182b5746545SKyle Evans	-- have their names derived differently. The default action for entry
183a51f9f0cSKyle Evans	-- types not specified here is to use entry.name directly.
184e2df27e3SKyle Evans	[core.MENU_SEPARATOR] = function(_, entry)
185dd65496aSKyle Evans		if entry.name ~= nil then
186a51f9f0cSKyle Evans			if type(entry.name) == "function" then
187dd65496aSKyle Evans				return entry.name()
188dd65496aSKyle Evans			end
189a51f9f0cSKyle Evans			return entry.name
190a51f9f0cSKyle Evans		end
191dd65496aSKyle Evans		return ""
192dd65496aSKyle Evans	end,
193e2df27e3SKyle Evans	[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
194aedd6be5SKyle Evans		local carid = entry.carousel_id
195aedd6be5SKyle Evans		local caridx = config.getCarouselIndex(carid)
1964f437f9eSKyle Evans		local choices = entry.items
1974f437f9eSKyle Evans		if type(choices) == "function" then
1984f437f9eSKyle Evans			choices = choices()
1994f437f9eSKyle Evans		end
2009f71d421SKyle Evans		if #choices < caridx then
201aedd6be5SKyle Evans			caridx = 1
202b5746545SKyle Evans		end
203aedd6be5SKyle Evans		return entry.name(caridx, choices[caridx], choices)
204b5746545SKyle Evans	end,
205aedd6be5SKyle Evans}
206b5746545SKyle Evans
207aedd6be5SKyle Evansdrawer.brand_position = {x = 2, y = 1}
208aedd6be5SKyle Evansdrawer.logo_position = {x = 46, y = 1}
209aedd6be5SKyle Evansdrawer.menu_position = {x = 6, y = 11}
210aedd6be5SKyle Evansdrawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11}
211b5746545SKyle Evans
21229aa5794SKyle Evansdrawer.branddefs = {
213699578a6SKyle Evans	-- Indexed by valid values for loader_brand in loader.conf(5). Valid
214699578a6SKyle Evans	-- keys are: graphic (table depicting graphic)
21529aa5794SKyle Evans	["fbsd"] = {
21629aa5794SKyle Evans		graphic = fbsd_logo,
21729aa5794SKyle Evans	},
21829aa5794SKyle Evans	["none"] = {
21929aa5794SKyle Evans		graphic = none,
22029aa5794SKyle Evans	},
221aedd6be5SKyle Evans}
22229aa5794SKyle Evans
223bb26c57dSKyle Evansdrawer.logodefs = {
224bb26c57dSKyle Evans	-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
225752b2d40SKyle Evans	-- are: requires_color (boolean), graphic (table depicting graphic), and
226bb26c57dSKyle Evans	-- shift (table containing x and y).
227bb26c57dSKyle Evans	["beastie"] = {
228bb26c57dSKyle Evans		requires_color = true,
229752b2d40SKyle Evans		graphic = beastie_color,
230bb26c57dSKyle Evans	},
231bb26c57dSKyle Evans	["beastiebw"] = {
232752b2d40SKyle Evans		graphic = beastie,
233bb26c57dSKyle Evans	},
234bb26c57dSKyle Evans	["fbsdbw"] = {
235752b2d40SKyle Evans		graphic = fbsd_logo_v,
236bb26c57dSKyle Evans		shift = {x = 5, y = 4},
237bb26c57dSKyle Evans	},
238bb26c57dSKyle Evans	["orb"] = {
239bb26c57dSKyle Evans		requires_color = true,
240752b2d40SKyle Evans		graphic = orb_color,
241bb26c57dSKyle Evans		shift = {x = 2, y = 4},
242bb26c57dSKyle Evans	},
243bb26c57dSKyle Evans	["orbbw"] = {
244752b2d40SKyle Evans		graphic = orb,
245bb26c57dSKyle Evans		shift = {x = 2, y = 4},
246bb26c57dSKyle Evans	},
247bb26c57dSKyle Evans	["tribute"] = {
248752b2d40SKyle Evans		graphic = fbsd_logo,
249bb26c57dSKyle Evans	},
250bb26c57dSKyle Evans	["tributebw"] = {
251752b2d40SKyle Evans		graphic = fbsd_logo,
252bb26c57dSKyle Evans	},
253bb26c57dSKyle Evans	["none"] = {
254752b2d40SKyle Evans		graphic = none,
255bb26c57dSKyle Evans		shift = {x = 17, y = 0},
256bb26c57dSKyle Evans	},
257aedd6be5SKyle Evans}
258bb26c57dSKyle Evans
259*379e652eSKyle Evansdrawer.frame_styles = {
260*379e652eSKyle Evans	-- Indexed by valid values for loader_menu_frame in loader.conf(5).
261*379e652eSKyle Evans	-- All of the keys appearing below must be set for any menu frame style
262*379e652eSKyle Evans	-- added to drawer.frame_styles.
263*379e652eSKyle Evans	["ascii"] = {
264*379e652eSKyle Evans		horizontal	= "-",
265*379e652eSKyle Evans		vertical	= "|",
266*379e652eSKyle Evans		top_left	= "+",
267*379e652eSKyle Evans		bottom_left	= "+",
268*379e652eSKyle Evans		top_right	= "+",
269*379e652eSKyle Evans		bottom_right	= "+",
270*379e652eSKyle Evans	},
271*379e652eSKyle Evans	["single"] = {
272*379e652eSKyle Evans		horizontal	= "\xC4",
273*379e652eSKyle Evans		vertical	= "\xB3",
274*379e652eSKyle Evans		top_left	= "\xDA",
275*379e652eSKyle Evans		bottom_left	= "\xC0",
276*379e652eSKyle Evans		top_right	= "\xBF",
277*379e652eSKyle Evans		bottom_right	= "\xD9",
278*379e652eSKyle Evans	},
279*379e652eSKyle Evans	["double"] = {
280*379e652eSKyle Evans		horizontal	= "\xCD",
281*379e652eSKyle Evans		vertical	= "\xBA",
282*379e652eSKyle Evans		top_left	= "\xC9",
283*379e652eSKyle Evans		bottom_left	= "\xC8",
284*379e652eSKyle Evans		top_right	= "\xBB",
285*379e652eSKyle Evans		bottom_right	= "\xBC",
286*379e652eSKyle Evans	},
287*379e652eSKyle Evans}
288*379e652eSKyle Evans
289088b4f5fSWarner Loshfunction drawer.drawscreen(menu_opts)
290088b4f5fSWarner Losh	-- drawlogo() must go first.
291088b4f5fSWarner Losh	-- it determines the positions of other elements
292aedd6be5SKyle Evans	drawer.drawlogo()
293aedd6be5SKyle Evans	drawer.drawbrand()
294aedd6be5SKyle Evans	drawer.drawbox()
295aedd6be5SKyle Evans	return drawer.drawmenu(menu_opts)
296088b4f5fSWarner Loshend
297088b4f5fSWarner Losh
29804af4229SKyle Evansfunction drawer.drawmenu(menudef)
299e2df27e3SKyle Evans	local x = drawer.menu_position.x
300e2df27e3SKyle Evans	local y = drawer.menu_position.y
301088b4f5fSWarner Losh
302088b4f5fSWarner Losh	-- print the menu and build the alias table
303aedd6be5SKyle Evans	local alias_table = {}
304aedd6be5SKyle Evans	local entry_num = 0
30504af4229SKyle Evans	local menu_entries = menudef.entries
3061afbc37aSKyle Evans	local effective_line_num = 0
3079f71d421SKyle Evans	if type(menu_entries) == "function" then
308aedd6be5SKyle Evans		menu_entries = menu_entries()
3092e716cecSKyle Evans	end
310d709f254SKyle Evans	for _, e in ipairs(menu_entries) do
3114a4fb4f8SKyle Evans		-- Allow menu items to be conditionally visible by specifying
3124a4fb4f8SKyle Evans		-- a visible function.
3139f71d421SKyle Evans		if e.visible ~= nil and not e.visible() then
314aedd6be5SKyle Evans			goto continue
3154a4fb4f8SKyle Evans		end
3161afbc37aSKyle Evans		effective_line_num = effective_line_num + 1
3179f71d421SKyle Evans		if e.entry_type ~= core.MENU_SEPARATOR then
318aedd6be5SKyle Evans			entry_num = entry_num + 1
3191afbc37aSKyle Evans			screen.setcursor(x, y + effective_line_num)
320ada26c4aSKyle Evans
32104af4229SKyle Evans			print(entry_num .. ". " .. menuEntryName(menudef, e))
322088b4f5fSWarner Losh
323088b4f5fSWarner Losh			-- fill the alias table
324aedd6be5SKyle Evans			alias_table[tostring(entry_num)] = e
3259f71d421SKyle Evans			if e.alias ~= nil then
326e2df27e3SKyle Evans				for _, a in ipairs(e.alias) do
327aedd6be5SKyle Evans					alias_table[a] = e
328088b4f5fSWarner Losh				end
329196ba166SKyle Evans			end
330088b4f5fSWarner Losh		else
3311afbc37aSKyle Evans			screen.setcursor(x, y + effective_line_num)
33204af4229SKyle Evans			print(menuEntryName(menudef, e))
333088b4f5fSWarner Losh		end
3344a4fb4f8SKyle Evans		::continue::
335088b4f5fSWarner Losh	end
336aedd6be5SKyle Evans	return alias_table
337088b4f5fSWarner Loshend
338088b4f5fSWarner Losh
339088b4f5fSWarner Loshfunction drawer.drawbox()
340e2df27e3SKyle Evans	local x = drawer.box_pos_dim.x
341e2df27e3SKyle Evans	local y = drawer.box_pos_dim.y
342e2df27e3SKyle Evans	local w = drawer.box_pos_dim.w
343e2df27e3SKyle Evans	local h = drawer.box_pos_dim.h
344088b4f5fSWarner Losh
345*379e652eSKyle Evans	local framestyle = loader.getenv("loader_menu_frame") or "double"
346*379e652eSKyle Evans	local framespec = drawer.frame_styles[framestyle]
347*379e652eSKyle Evans	-- If we don't have a framespec for the current frame style, just don't
348*379e652eSKyle Evans	-- draw a box.
349*379e652eSKyle Evans	if framespec == nil then
350*379e652eSKyle Evans		return
351*379e652eSKyle Evans	end
352088b4f5fSWarner Losh
353*379e652eSKyle Evans	local hl = framespec.horizontal
354*379e652eSKyle Evans	local vl = framespec.vertical
355088b4f5fSWarner Losh
356*379e652eSKyle Evans	local tl = framespec.top_left
357*379e652eSKyle Evans	local bl = framespec.bottom_left
358*379e652eSKyle Evans	local tr = framespec.top_right
359*379e652eSKyle Evans	local br = framespec.bottom_right
360088b4f5fSWarner Losh
361*379e652eSKyle Evans	screen.setcursor(x, y); loader.printc(tl)
362*379e652eSKyle Evans	screen.setcursor(x, y + h); loader.printc(bl)
363*379e652eSKyle Evans	screen.setcursor(x + w, y); loader.printc(tr)
364*379e652eSKyle Evans	screen.setcursor(x + w, y + h); loader.printc(br)
365*379e652eSKyle Evans
366*379e652eSKyle Evans	screen.setcursor(x + 1, y)
367*379e652eSKyle Evans	for _ = 1, w - 1 do
368*379e652eSKyle Evans		loader.printc(hl)
369*379e652eSKyle Evans	end
370*379e652eSKyle Evans
371*379e652eSKyle Evans	screen.setcursor(x + 1, y + h)
372*379e652eSKyle Evans	for _ = 1, w - 1 do
373*379e652eSKyle Evans		loader.printc(hl)
374088b4f5fSWarner Losh	end
375088b4f5fSWarner Losh
376088b4f5fSWarner Losh	for i = 1, h - 1 do
377aedd6be5SKyle Evans		screen.setcursor(x, y + i)
378*379e652eSKyle Evans		loader.printc(vl)
379aedd6be5SKyle Evans		screen.setcursor(x + w, y + i)
380*379e652eSKyle Evans		loader.printc(vl)
381088b4f5fSWarner Losh	end
382088b4f5fSWarner Losh
383aedd6be5SKyle Evans	screen.setcursor(x + (w / 2) - 9, y)
384*379e652eSKyle Evans	loader.printc("Welcome to FreeBSD")
385088b4f5fSWarner Loshend
386088b4f5fSWarner Losh
387088b4f5fSWarner Loshfunction drawer.draw(x, y, logo)
388088b4f5fSWarner Losh	for i = 1, #logo do
389aedd6be5SKyle Evans		screen.setcursor(x, y + i)
390aedd6be5SKyle Evans		print(logo[i])
391088b4f5fSWarner Losh	end
392088b4f5fSWarner Loshend
393088b4f5fSWarner Losh
394088b4f5fSWarner Loshfunction drawer.drawbrand()
39524a1bd54SKyle Evans	local x = tonumber(loader.getenv("loader_brand_x")) or
396aedd6be5SKyle Evans	    drawer.brand_position.x
39724a1bd54SKyle Evans	local y = tonumber(loader.getenv("loader_brand_y")) or
398aedd6be5SKyle Evans	    drawer.brand_position.y
399088b4f5fSWarner Losh
400aedd6be5SKyle Evans	local graphic = drawer.branddefs[loader.getenv("loader_brand")]
4019f71d421SKyle Evans	if graphic == nil then
402aedd6be5SKyle Evans		graphic = fbsd_logo
40329aa5794SKyle Evans	end
404aedd6be5SKyle Evans	drawer.draw(x, y, graphic)
405088b4f5fSWarner Loshend
406088b4f5fSWarner Losh
407088b4f5fSWarner Loshfunction drawer.drawlogo()
40824a1bd54SKyle Evans	local x = tonumber(loader.getenv("loader_logo_x")) or
409aedd6be5SKyle Evans	    drawer.logo_position.x
41024a1bd54SKyle Evans	local y = tonumber(loader.getenv("loader_logo_y")) or
411aedd6be5SKyle Evans	    drawer.logo_position.y
412088b4f5fSWarner Losh
413aedd6be5SKyle Evans	local logo = loader.getenv("loader_logo")
414aedd6be5SKyle Evans	local colored = color.isEnabled()
415088b4f5fSWarner Losh
416bb26c57dSKyle Evans	-- Lookup
417aedd6be5SKyle Evans	local logodef = drawer.logodefs[logo]
418bb26c57dSKyle Evans
4199f71d421SKyle Evans	if logodef ~= nil and logodef.graphic == none then
420088b4f5fSWarner Losh		-- centre brand and text if no logo
4219f71d421SKyle Evans		if not none_shifted then
422322a2dddSKyle Evans			shiftBrandText(logodef.shift)
423aedd6be5SKyle Evans			none_shifted = true
424088b4f5fSWarner Losh		end
4259f71d421SKyle Evans	elseif logodef == nil or logodef.graphic == nil or
4269f71d421SKyle Evans	    (not colored and logodef.requires_color) then
427bb26c57dSKyle Evans		-- Choose a sensible default
4289f71d421SKyle Evans		if colored then
429aedd6be5SKyle Evans			logodef = drawer.logodefs["orb"]
430088b4f5fSWarner Losh		else
431aedd6be5SKyle Evans			logodef = drawer.logodefs["orbbw"]
432088b4f5fSWarner Losh		end
433088b4f5fSWarner Losh	end
4349f71d421SKyle Evans	if logodef.shift ~= nil then
435aedd6be5SKyle Evans		x = x + logodef.shift.x
436aedd6be5SKyle Evans		y = y + logodef.shift.y
437bb26c57dSKyle Evans	end
438aedd6be5SKyle Evans	drawer.draw(x, y, logodef.graphic)
439088b4f5fSWarner Loshend
440088b4f5fSWarner Losh
441aedd6be5SKyle Evansreturn drawer
442