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")
46 local none_shifted = false
48 local function menuEntryName(drawing_menu, entry)
49 local name_handler = drawer.menu_name_handlers[entry.entry_type]
51 if name_handler ~= nil then
52 return name_handler(drawing_menu, entry)
54 if type(entry.name) == "function" then
60 local function shiftBrandText(shift)
61 drawer.brand_position.x = drawer.brand_position.x + shift.x
62 drawer.brand_position.y = drawer.brand_position.y + shift.y
63 drawer.menu_position.x = drawer.menu_position.x + shift.x
64 drawer.menu_position.y = drawer.menu_position.y + shift.y
65 drawer.box_pos_dim.x = drawer.box_pos_dim.x + shift.x
66 drawer.box_pos_dim.y = drawer.box_pos_dim.y + shift.y
70 " ______ ____ _____ _____ ",
71 " | ____| | _ \\ / ____| __ \\ ",
72 " | |___ _ __ ___ ___ | |_) | (___ | | | |",
73 " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |",
74 " | | | | | __/ __/| |_) |____) | |__| |",
75 " | | | | | | || | | |",
76 " |_| |_| \\___|\\___||____/|_____/|_____/ "
83 " /- \027[37m_\027[31m `-/ '",
84 " (\027[37m/\\/ \\\027[31m \\ /\\",
85 " \027[37m/ / |\027[31m ` \\",
86 " \027[34mO O \027[37m) \027[31m/ |",
87 " \027[37m`-^--'\027[31m`< '",
91 " \027[33m<----.\027[31m __ / __ \\",
92 " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
93 " \027[33m<----'\027[31m `--' `.__,' \\",
96 " \027[36m______\027[31m( (_ / \\______/",
97 " \027[36m,' ,-----' |",
98 " `--{__________)\027[37m"
113 " <----. __ / __ \\",
114 " <----|====O)))==) \\) /====|",
115 " <----' `--' `.__,' \\",
118 " ______( (_ / \\______/",
125 " | ____| __ ___ ___ ",
126 " | |__ | '__/ _ \\/ _ \\",
127 " | __|| | | __/ __/",
129 " |_| |_| \\___|\\___|",
131 " | _ \\ / ____| __ \\",
132 " | |_) | (___ | | | |",
133 " | _ < \\___ \\| | | |",
134 " | |_) |____) | |__| |",
136 " |____/|_____/|_____/"
140 " \027[31m``` \027[31;1m`\027[31m",
141 " s` `.....---...\027[31;1m....--.``` -/\027[31m",
142 " +o .--` \027[31;1m/y:` +.\027[31m",
143 " yo`:. \027[31;1m:o `+-\027[31m",
144 " y/ \027[31;1m-/` -o/\027[31m",
145 " .- \027[31;1m::/sy+:.\027[31m",
146 " / \027[31;1m`-- /\027[31m",
147 " `: \027[31;1m:`\027[31m",
148 " `: \027[31;1m:`\027[31m",
149 " / \027[31;1m/\027[31m",
150 " .- \027[31;1m-.\027[31m",
151 " -- \027[31;1m-.\027[31m",
152 " `:` \027[31;1m`:`",
153 " \027[31;1m.-- `--.",
154 " .---.....----.\027[37m"
159 " s` `.....---.......--.``` -/",
178 drawer.menu_name_handlers = {
179 -- Menu name handlers should take the menu being drawn and entry being
180 -- drawn as parameters, and return the name of the item.
181 -- This is designed so that everything, including menu separators, may
182 -- have their names derived differently. The default action for entry
183 -- types not specified here is to use entry.name directly.
184 [core.MENU_SEPARATOR] = function(_, entry)
185 if entry.name ~= nil then
186 if type(entry.name) == "function" then
193 [core.MENU_CAROUSEL_ENTRY] = function(_, entry)
194 local carid = entry.carousel_id
195 local caridx = config.getCarouselIndex(carid)
196 local choices = entry.items
197 if type(choices) == "function" then
200 if #choices < caridx then
203 return entry.name(caridx, choices[caridx], choices)
207 drawer.brand_position = {x = 2, y = 1}
208 drawer.logo_position = {x = 46, y = 1}
209 drawer.menu_position = {x = 6, y = 11}
210 drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11}
213 -- Indexed by valid values for loader_brand in loader.conf(5). Valid
214 -- keys are: graphic (table depicting graphic)
224 -- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
225 -- are: requires_color (boolean), graphic (table depicting graphic), and
226 -- shift (table containing x and y).
228 requires_color = true,
229 graphic = beastie_color,
235 graphic = fbsd_logo_v,
236 shift = {x = 5, y = 4},
239 requires_color = true,
241 shift = {x = 2, y = 4},
245 shift = {x = 2, y = 4},
255 shift = {x = 17, y = 0},
259 function drawer.drawscreen(menu_opts)
260 -- drawlogo() must go first.
261 -- it determines the positions of other elements
265 return drawer.drawmenu(menu_opts)
268 function drawer.drawmenu(m)
269 local x = drawer.menu_position.x
270 local y = drawer.menu_position.y
272 -- print the menu and build the alias table
273 local alias_table = {}
275 local menu_entries = m.entries
276 local effective_line_num = 0
277 if type(menu_entries) == "function" then
278 menu_entries = menu_entries()
280 for _, e in ipairs(menu_entries) do
281 -- Allow menu items to be conditionally visible by specifying
282 -- a visible function.
283 if e.visible ~= nil and not e.visible() then
286 effective_line_num = effective_line_num + 1
287 if e.entry_type ~= core.MENU_SEPARATOR then
288 entry_num = entry_num + 1
289 screen.setcursor(x, y + effective_line_num)
291 print(entry_num .. ". " .. menuEntryName(m, e))
293 -- fill the alias table
294 alias_table[tostring(entry_num)] = e
295 if e.alias ~= nil then
296 for _, a in ipairs(e.alias) do
301 screen.setcursor(x, y + effective_line_num)
302 print(menuEntryName(m, e))
310 function drawer.drawbox()
311 local x = drawer.box_pos_dim.x
312 local y = drawer.box_pos_dim.y
313 local w = drawer.box_pos_dim.w
314 local h = drawer.box_pos_dim.h
316 local hl = string.char(0xCD)
317 local vl = string.char(0xBA)
319 local tl = string.char(0xC9)
320 local bl = string.char(0xC8)
321 local tr = string.char(0xBB)
322 local br = string.char(0xBC)
324 screen.setcursor(x, y); print(tl)
325 screen.setcursor(x, y+h); print(bl)
326 screen.setcursor(x+w, y); print(tr)
327 screen.setcursor(x+w, y+h); print(br)
330 screen.setcursor(x+i, y)
332 screen.setcursor(x+i, y+h)
337 screen.setcursor(x, y+i)
339 screen.setcursor(x+w, y+i)
343 screen.setcursor(x+(w/2)-9, y)
344 print("Welcome to FreeBSD")
347 function drawer.draw(x, y, logo)
349 screen.setcursor(x, y + i)
354 function drawer.drawbrand()
355 local x = tonumber(loader.getenv("loader_brand_x")) or
356 drawer.brand_position.x
357 local y = tonumber(loader.getenv("loader_brand_y")) or
358 drawer.brand_position.y
360 local graphic = drawer.branddefs[loader.getenv("loader_brand")]
361 if graphic == nil then
364 drawer.draw(x, y, graphic)
367 function drawer.drawlogo()
368 local x = tonumber(loader.getenv("loader_logo_x")) or
369 drawer.logo_position.x
370 local y = tonumber(loader.getenv("loader_logo_y")) or
371 drawer.logo_position.y
373 local logo = loader.getenv("loader_logo")
374 local colored = color.isEnabled()
377 local logodef = drawer.logodefs[logo]
379 if logodef ~= nil and logodef.graphic == none then
380 -- centre brand and text if no logo
381 if not none_shifted then
382 shiftBrandText(logodef.shift)
385 elseif logodef == nil or logodef.graphic == nil or
386 (not colored and logodef.requires_color) then
387 -- Choose a sensible default
389 logodef = drawer.logodefs["orb"]
391 logodef = drawer.logodefs["orbbw"]
394 if logodef.shift ~= nil then
395 x = x + logodef.shift.x
396 y = y + logodef.shift.y
398 drawer.draw(x, y, logodef.graphic)