2 -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5 -- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6 -- All rights reserved.
8 -- Redistribution and use in source and binary forms, with or without
9 -- modification, are permitted provided that the following conditions
11 -- 1. Redistributions of source code must retain the above copyright
12 -- notice, this list of conditions and the following disclaimer.
13 -- 2. Redistributions in binary form must reproduce the above copyright
14 -- notice, this list of conditions and the following disclaimer in the
15 -- documentation and/or other materials provided with the distribution.
17 -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 local color = require("color")
33 local config = require("config")
34 local core = require("core")
35 local screen = require("screen")
47 local function menuEntryName(drawing_menu, entry)
48 local name_handler = drawer.menu_name_handlers[entry.entry_type]
50 if name_handler ~= nil then
51 return name_handler(drawing_menu, entry)
53 if type(entry.name) == "function" then
60 " ______ ____ _____ _____ ",
61 " | ____| | _ \\ / ____| __ \\ ",
62 " | |___ _ __ ___ ___ | |_) | (___ | | | |",
63 " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |",
64 " | | | | | __/ __/| |_) |____) | |__| |",
65 " | | | | | | || | | |",
66 " |_| |_| \\___|\\___||____/|_____/|_____/ "
73 " /- \027[37m_\027[31m `-/ '",
74 " (\027[37m/\\/ \\\027[31m \\ /\\",
75 " \027[37m/ / |\027[31m ` \\",
76 " \027[34mO O \027[37m) \027[31m/ |",
77 " \027[37m`-^--'\027[31m`< '",
81 " \027[33m<----.\027[31m __ / __ \\",
82 " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
83 " \027[33m<----'\027[31m `--' `.__,' \\",
86 " \027[36m______\027[31m( (_ / \\______/",
87 " \027[36m,' ,-----' |",
88 " `--{__________)\027[37m"
103 " <----. __ / __ \\",
104 " <----|====O)))==) \\) /====|",
105 " <----' `--' `.__,' \\",
108 " ______( (_ / \\______/",
115 " | ____| __ ___ ___ ",
116 " | |__ | '__/ _ \\/ _ \\",
117 " | __|| | | __/ __/",
119 " |_| |_| \\___|\\___|",
121 " | _ \\ / ____| __ \\",
122 " | |_) | (___ | | | |",
123 " | _ < \\___ \\| | | |",
124 " | |_) |____) | |__| |",
126 " |____/|_____/|_____/"
130 " \027[31m``` \027[31;1m`\027[31m",
131 " s` `.....---...\027[31;1m....--.``` -/\027[31m",
132 " +o .--` \027[31;1m/y:` +.\027[31m",
133 " yo`:. \027[31;1m:o `+-\027[31m",
134 " y/ \027[31;1m-/` -o/\027[31m",
135 " .- \027[31;1m::/sy+:.\027[31m",
136 " / \027[31;1m`-- /\027[31m",
137 " `: \027[31;1m:`\027[31m",
138 " `: \027[31;1m:`\027[31m",
139 " / \027[31;1m/\027[31m",
140 " .- \027[31;1m-.\027[31m",
141 " -- \027[31;1m-.\027[31m",
142 " `:` \027[31;1m`:`",
143 " \027[31;1m.-- `--.",
144 " .---.....----.\027[37m"
149 " s` `.....---.......--.``` -/",
168 drawer.menu_name_handlers = {
169 -- Menu name handlers should take the menu being drawn and entry being
170 -- drawn as parameters, and return the name of the item.
171 -- This is designed so that everything, including menu separators, may
172 -- have their names derived differently. The default action for entry
173 -- types not specified here is to use entry.name directly.
174 [core.MENU_SEPARATOR] = function(_, entry)
175 if entry.name ~= nil then
176 if type(entry.name) == "function" then
183 [core.MENU_CAROUSEL_ENTRY] = function(_, entry)
184 local carid = entry.carousel_id
185 local caridx = config.getCarouselIndex(carid)
186 local choices = entry.items
187 if type(choices) == "function" then
190 if #choices < caridx then
193 return entry.name(caridx, choices[caridx], choices)
197 drawer.brand_position = {x = 2, y = 1}
198 drawer.logo_position = {x = 46, y = 4}
199 drawer.menu_position = {x = 5, y = 10}
200 drawer.frame_size = {w = 42, h = 13}
201 drawer.default_shift = {x = 0, y = 0}
202 drawer.shift = drawer.default_shift
205 -- Indexed by valid values for loader_brand in loader.conf(5). Valid
206 -- keys are: graphic (table depicting graphic)
216 -- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
217 -- are: requires_color (boolean), graphic (table depicting graphic), and
218 -- shift (table containing x and y).
220 requires_color = true,
221 graphic = beastie_color,
227 graphic = fbsd_logo_v,
228 shift = {x = 5, y = 4},
231 requires_color = true,
233 shift = {x = 2, y = 4},
237 shift = {x = 2, y = 4},
247 shift = {x = 17, y = 0},
251 drawer.frame_styles = {
252 -- Indexed by valid values for loader_menu_frame in loader.conf(5).
253 -- All of the keys appearing below must be set for any menu frame style
254 -- added to drawer.frame_styles.
267 bottom_left = "\xC0",
269 bottom_right = "\xD9",
275 bottom_left = "\xC8",
277 bottom_right = "\xBC",
281 function drawer.drawscreen(menu_opts)
282 -- drawlogo() must go first.
283 -- it determines the positions of other elements
287 return drawer.drawmenu(menu_opts)
290 function drawer.drawmenu(menudef)
291 local x = drawer.menu_position.x
292 local y = drawer.menu_position.y
294 x = x + drawer.shift.x
295 y = y + drawer.shift.y
297 -- print the menu and build the alias table
298 local alias_table = {}
300 local menu_entries = menudef.entries
301 local effective_line_num = 0
302 if type(menu_entries) == "function" then
303 menu_entries = menu_entries()
305 for _, e in ipairs(menu_entries) do
306 -- Allow menu items to be conditionally visible by specifying
307 -- a visible function.
308 if e.visible ~= nil and not e.visible() then
311 effective_line_num = effective_line_num + 1
312 if e.entry_type ~= core.MENU_SEPARATOR then
313 entry_num = entry_num + 1
314 screen.setcursor(x, y + effective_line_num)
316 printc(entry_num .. ". " .. menuEntryName(menudef, e))
318 -- fill the alias table
319 alias_table[tostring(entry_num)] = e
320 if e.alias ~= nil then
321 for _, a in ipairs(e.alias) do
326 screen.setcursor(x, y + effective_line_num)
327 printc(menuEntryName(menudef, e))
334 function drawer.drawbox()
335 local x = drawer.menu_position.x - 3
336 local y = drawer.menu_position.y - 1
337 local w = drawer.frame_size.w
338 local h = drawer.frame_size.h
340 local framestyle = loader.getenv("loader_menu_frame") or "double"
341 local framespec = drawer.frame_styles[framestyle]
342 -- If we don't have a framespec for the current frame style, just don't
344 if framespec == nil then
348 local hl = framespec.horizontal
349 local vl = framespec.vertical
351 local tl = framespec.top_left
352 local bl = framespec.bottom_left
353 local tr = framespec.top_right
354 local br = framespec.bottom_right
356 x = x + drawer.shift.x
357 y = y + drawer.shift.y
359 screen.setcursor(x, y); printc(tl)
360 screen.setcursor(x, y + h); printc(bl)
361 screen.setcursor(x + w, y); printc(tr)
362 screen.setcursor(x + w, y + h); printc(br)
364 screen.setcursor(x + 1, y)
369 screen.setcursor(x + 1, y + h)
375 screen.setcursor(x, y + i)
377 screen.setcursor(x + w, y + i)
381 local menu_header = loader.getenv("loader_menu_title") or
383 local menu_header_align = loader.getenv("loader_menu_title_align")
386 if menu_header_align ~= nil then
387 menu_header_align = menu_header_align:lower()
388 if menu_header_align == "left" then
389 -- Just inside the left border on top
390 menu_header_x = x + 1
391 elseif menu_header_align == "right" then
392 -- Just inside the right border on top
393 menu_header_x = x + w - #menu_header
396 if menu_header_x == nil then
397 menu_header_x = x + (w / 2) - (#menu_header / 2)
399 screen.setcursor(menu_header_x, y)
403 function drawer.draw(x, y, logo)
405 screen.setcursor(x, y + i - 1)
410 function drawer.drawbrand()
411 local x = tonumber(loader.getenv("loader_brand_x")) or
412 drawer.brand_position.x
413 local y = tonumber(loader.getenv("loader_brand_y")) or
414 drawer.brand_position.y
416 local graphic = drawer.branddefs[loader.getenv("loader_brand")]
417 if graphic == nil then
421 x = x + drawer.shift.x
422 y = y + drawer.shift.y
423 drawer.draw(x, y, graphic)
426 function drawer.drawlogo()
427 local x = tonumber(loader.getenv("loader_logo_x")) or
428 drawer.logo_position.x
429 local y = tonumber(loader.getenv("loader_logo_y")) or
430 drawer.logo_position.y
432 local logo = loader.getenv("loader_logo")
433 local colored = color.isEnabled()
436 local logodef = drawer.logodefs[logo]
438 if logodef == nil or logodef.graphic == nil or
439 (not colored and logodef.requires_color) then
440 -- Choose a sensible default
442 logodef = drawer.logodefs["orb"]
444 logodef = drawer.logodefs["orbbw"]
448 if logodef ~= nil and logodef.graphic == none then
449 drawer.shift = logodef.shift
451 drawer.shift = drawer.default_shift
454 x = x + drawer.shift.x
455 y = y + drawer.shift.y
457 if logodef ~= nil and logodef.shift ~= nil then
458 x = x + logodef.shift.x
459 y = y + logodef.shift.y
462 drawer.draw(x, y, logodef.graphic)