1088b4f5fSWarner Losh-- 2088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3088b4f5fSWarner Losh-- All rights reserved. 4088b4f5fSWarner Losh-- 5088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 6088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 7088b4f5fSWarner Losh-- are met: 8088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 9088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 10088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 11088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 12088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 13088b4f5fSWarner Losh-- 14088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24088b4f5fSWarner Losh-- SUCH DAMAGE. 25088b4f5fSWarner Losh-- 26088b4f5fSWarner Losh-- $FreeBSD$ 27088b4f5fSWarner Losh-- 28088b4f5fSWarner Losh 29088b4f5fSWarner Loshlocal color = require("color"); 30a7cf0562SKyle Evanslocal core = require("core"); 31088b4f5fSWarner Loshlocal screen = require("screen"); 32088b4f5fSWarner Losh 33c8518398SKyle Evanslocal drawer = {}; 34c8518398SKyle Evans 3502122e53SKyle Evanslocal fbsd_logo; 3602122e53SKyle Evanslocal beastie_color; 3702122e53SKyle Evanslocal beastie; 3802122e53SKyle Evanslocal fbsd_logo_v; 3902122e53SKyle Evanslocal orb; 4002122e53SKyle Evanslocal none; 41bb26c57dSKyle Evanslocal none_shifted = false; 4202122e53SKyle Evans 43da56fe38SKyle Evansdrawer.menu_name_handlers = { 44da56fe38SKyle Evans -- Menu name handlers should take the menu being drawn and entry being 45da56fe38SKyle Evans -- drawn as parameters, and return the name of the item. 46da56fe38SKyle Evans -- This is designed so that everything, including menu separators, may 47da56fe38SKyle Evans -- have their names derived differently. The default action for entry 48da56fe38SKyle Evans -- types not specified here is to call and use entry.name(). 49da56fe38SKyle Evans [core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry) 50da56fe38SKyle Evans local carid = entry.carousel_id; 51da56fe38SKyle Evans local caridx = menu.getCarouselIndex(carid); 52da56fe38SKyle Evans local choices = entry.items(); 53da56fe38SKyle Evans 54da56fe38SKyle Evans if (#choices < caridx) then 55da56fe38SKyle Evans caridx = 1; 56da56fe38SKyle Evans end 57da56fe38SKyle Evans return entry.name(caridx, choices[caridx], choices); 58da56fe38SKyle Evans end, 59da56fe38SKyle Evans}; 60da56fe38SKyle Evans 61088b4f5fSWarner Loshdrawer.brand_position = {x = 2, y = 1}; 6202122e53SKyle Evansdrawer.logo_position = {x = 46, y = 1}; 6302122e53SKyle Evansdrawer.menu_position = {x = 6, y = 11}; 6402122e53SKyle Evansdrawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11}; 6502122e53SKyle Evans 6602122e53SKyle Evansfbsd_logo = { 67088b4f5fSWarner Losh " ______ ____ _____ _____ ", 68088b4f5fSWarner Losh " | ____| | _ \\ / ____| __ \\ ", 69088b4f5fSWarner Losh " | |___ _ __ ___ ___ | |_) | (___ | | | |", 70088b4f5fSWarner Losh " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |", 71088b4f5fSWarner Losh " | | | | | __/ __/| |_) |____) | |__| |", 72088b4f5fSWarner Losh " | | | | | | || | | |", 73088b4f5fSWarner Losh " |_| |_| \\___|\\___||____/|_____/|_____/ " 74088b4f5fSWarner Losh}; 75088b4f5fSWarner Losh 7602122e53SKyle Evansbeastie_color = { 77088b4f5fSWarner Losh " \027[31m, ,", 78088b4f5fSWarner Losh " /( )`", 79088b4f5fSWarner Losh " \\ \\___ / |", 80088b4f5fSWarner Losh " /- \027[37m_\027[31m `-/ '", 81088b4f5fSWarner Losh " (\027[37m/\\/ \\\027[31m \\ /\\", 82088b4f5fSWarner Losh " \027[37m/ / |\027[31m ` \\", 83088b4f5fSWarner Losh " \027[34mO O \027[37m) \027[31m/ |", 84088b4f5fSWarner Losh " \027[37m`-^--'\027[31m`< '", 85088b4f5fSWarner Losh " (_.) _ ) /", 86088b4f5fSWarner Losh " `.___/` /", 87088b4f5fSWarner Losh " `-----' /", 88088b4f5fSWarner Losh " \027[33m<----.\027[31m __ / __ \\", 89088b4f5fSWarner Losh " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|", 90088b4f5fSWarner Losh " \027[33m<----'\027[31m `--' `.__,' \\", 91088b4f5fSWarner Losh " | |", 92088b4f5fSWarner Losh " \\ / /\\", 93088b4f5fSWarner Losh " \027[36m______\027[31m( (_ / \\______/", 94088b4f5fSWarner Losh " \027[36m,' ,-----' |", 95088b4f5fSWarner Losh " `--{__________)\027[37m" 96088b4f5fSWarner Losh}; 97088b4f5fSWarner Losh 9802122e53SKyle Evansbeastie = { 99088b4f5fSWarner Losh " , ,", 100088b4f5fSWarner Losh " /( )`", 101088b4f5fSWarner Losh " \\ \\___ / |", 102088b4f5fSWarner Losh " /- _ `-/ '", 103088b4f5fSWarner Losh " (/\\/ \\ \\ /\\", 104088b4f5fSWarner Losh " / / | ` \\", 105088b4f5fSWarner Losh " O O ) / |", 106088b4f5fSWarner Losh " `-^--'`< '", 107088b4f5fSWarner Losh " (_.) _ ) /", 108088b4f5fSWarner Losh " `.___/` /", 109088b4f5fSWarner Losh " `-----' /", 110088b4f5fSWarner Losh " <----. __ / __ \\", 111088b4f5fSWarner Losh " <----|====O)))==) \\) /====|", 112088b4f5fSWarner Losh " <----' `--' `.__,' \\", 113088b4f5fSWarner Losh " | |", 114088b4f5fSWarner Losh " \\ / /\\", 115088b4f5fSWarner Losh " ______( (_ / \\______/", 116088b4f5fSWarner Losh " ,' ,-----' |", 117088b4f5fSWarner Losh " `--{__________)" 118088b4f5fSWarner Losh}; 119088b4f5fSWarner Losh 12002122e53SKyle Evansfbsd_logo_v = { 121088b4f5fSWarner Losh " ______", 122088b4f5fSWarner Losh " | ____| __ ___ ___ ", 123088b4f5fSWarner Losh " | |__ | '__/ _ \\/ _ \\", 124088b4f5fSWarner Losh " | __|| | | __/ __/", 125088b4f5fSWarner Losh " | | | | | | |", 126088b4f5fSWarner Losh " |_| |_| \\___|\\___|", 127088b4f5fSWarner Losh " ____ _____ _____", 128088b4f5fSWarner Losh " | _ \\ / ____| __ \\", 129088b4f5fSWarner Losh " | |_) | (___ | | | |", 130088b4f5fSWarner Losh " | _ < \\___ \\| | | |", 131088b4f5fSWarner Losh " | |_) |____) | |__| |", 132088b4f5fSWarner Losh " | | | |", 133088b4f5fSWarner Losh " |____/|_____/|_____/" 134088b4f5fSWarner Losh}; 135088b4f5fSWarner Losh 13602122e53SKyle Evansorb_color = { 137088b4f5fSWarner Losh " \027[31m``` \027[31;1m`\027[31m", 138088b4f5fSWarner Losh " s` `.....---...\027[31;1m....--.``` -/\027[31m", 139088b4f5fSWarner Losh " +o .--` \027[31;1m/y:` +.\027[31m", 140088b4f5fSWarner Losh " yo`:. \027[31;1m:o `+-\027[31m", 141088b4f5fSWarner Losh " y/ \027[31;1m-/` -o/\027[31m", 142088b4f5fSWarner Losh " .- \027[31;1m::/sy+:.\027[31m", 143088b4f5fSWarner Losh " / \027[31;1m`-- /\027[31m", 144088b4f5fSWarner Losh " `: \027[31;1m:`\027[31m", 145088b4f5fSWarner Losh " `: \027[31;1m:`\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`:`", 150088b4f5fSWarner Losh " \027[31;1m.-- `--.", 151088b4f5fSWarner Losh " .---.....----.\027[37m" 152088b4f5fSWarner Losh}; 153088b4f5fSWarner Losh 15402122e53SKyle Evansorb = { 155088b4f5fSWarner Losh " ``` `", 156088b4f5fSWarner Losh " s` `.....---.......--.``` -/", 157088b4f5fSWarner Losh " +o .--` /y:` +.", 158088b4f5fSWarner Losh " yo`:. :o `+-", 159088b4f5fSWarner Losh " y/ -/` -o/", 160088b4f5fSWarner Losh " .- ::/sy+:.", 161088b4f5fSWarner Losh " / `-- /", 162088b4f5fSWarner Losh " `: :`", 163088b4f5fSWarner Losh " `: :`", 164088b4f5fSWarner Losh " / /", 165088b4f5fSWarner Losh " .- -.", 166088b4f5fSWarner Losh " -- -.", 167088b4f5fSWarner Losh " `:` `:`", 168088b4f5fSWarner Losh " .-- `--.", 169088b4f5fSWarner Losh " .---.....----." 170088b4f5fSWarner Losh}; 171088b4f5fSWarner Losh 17202122e53SKyle Evansnone = {""}; 173088b4f5fSWarner Losh 17429aa5794SKyle Evansdrawer.branddefs = { 17529aa5794SKyle Evans ["fbsd"] = { 17629aa5794SKyle Evans graphic = fbsd_logo, 17729aa5794SKyle Evans }, 17829aa5794SKyle Evans ["none"] = { 17929aa5794SKyle Evans graphic = none, 18029aa5794SKyle Evans }, 18129aa5794SKyle Evans}; 18229aa5794SKyle Evans 183bb26c57dSKyle Evansdrawer.logodefs = { 184bb26c57dSKyle Evans -- Indexed by valid values for loader_logo in loader.conf(5). Valid keys 185*752b2d40SKyle Evans -- are: requires_color (boolean), graphic (table depicting graphic), and 186bb26c57dSKyle Evans -- shift (table containing x and y). 187bb26c57dSKyle Evans ["beastie"] = { 188bb26c57dSKyle Evans requires_color = true, 189*752b2d40SKyle Evans graphic = beastie_color, 190bb26c57dSKyle Evans }, 191bb26c57dSKyle Evans ["beastiebw"] = { 192*752b2d40SKyle Evans graphic = beastie, 193bb26c57dSKyle Evans }, 194bb26c57dSKyle Evans ["fbsdbw"] = { 195*752b2d40SKyle Evans graphic = fbsd_logo_v, 196bb26c57dSKyle Evans shift = {x = 5, y = 4}, 197bb26c57dSKyle Evans }, 198bb26c57dSKyle Evans ["orb"] = { 199bb26c57dSKyle Evans requires_color = true, 200*752b2d40SKyle Evans graphic = orb_color, 201bb26c57dSKyle Evans shift = {x = 2, y = 4}, 202bb26c57dSKyle Evans }, 203bb26c57dSKyle Evans ["orbbw"] = { 204*752b2d40SKyle Evans graphic = orb, 205bb26c57dSKyle Evans shift = {x = 2, y = 4}, 206bb26c57dSKyle Evans }, 207bb26c57dSKyle Evans ["tribute"] = { 208*752b2d40SKyle Evans graphic = fbsd_logo, 209bb26c57dSKyle Evans }, 210bb26c57dSKyle Evans ["tributebw"] = { 211*752b2d40SKyle Evans graphic = fbsd_logo, 212bb26c57dSKyle Evans }, 213bb26c57dSKyle Evans ["none"] = { 214*752b2d40SKyle Evans graphic = none, 215bb26c57dSKyle Evans shift = {x = 17, y = 0}, 216bb26c57dSKyle Evans }, 217bb26c57dSKyle Evans}; 218bb26c57dSKyle Evans 219088b4f5fSWarner Loshfunction drawer.drawscreen(menu_opts) 220088b4f5fSWarner Losh -- drawlogo() must go first. 221088b4f5fSWarner Losh -- it determines the positions of other elements 222088b4f5fSWarner Losh drawer.drawlogo(); 223088b4f5fSWarner Losh drawer.drawbrand(); 224088b4f5fSWarner Losh drawer.drawbox(); 225088b4f5fSWarner Losh return drawer.drawmenu(menu_opts); 226088b4f5fSWarner Loshend 227088b4f5fSWarner Losh 2282413c411SKyle Evansfunction menu_entry_name(drawing_menu, entry) 2292413c411SKyle Evans local name_handler = drawer.menu_name_handlers[entry.entry_type]; 2302413c411SKyle Evans 2312413c411SKyle Evans if (name_handler ~= nil) then 2322413c411SKyle Evans return name_handler(drawing_menu, entry); 2332413c411SKyle Evans end 2342413c411SKyle Evans return entry.name(); 2352413c411SKyle Evansend 2362413c411SKyle Evans 237088b4f5fSWarner Loshfunction drawer.drawmenu(m) 238088b4f5fSWarner Losh x = drawer.menu_position.x; 239088b4f5fSWarner Losh y = drawer.menu_position.y; 240088b4f5fSWarner Losh 241088b4f5fSWarner Losh -- print the menu and build the alias table 242088b4f5fSWarner Losh local alias_table = {}; 243088b4f5fSWarner Losh local entry_num = 0; 244d8757746SKyle Evans local menu_entries = m.entries; 2452e716cecSKyle Evans if (type(menu_entries) == "function") then 2462e716cecSKyle Evans menu_entries = menu_entries(); 2472e716cecSKyle Evans end 248d8757746SKyle Evans for line_num, e in ipairs(menu_entries) do 2494a4fb4f8SKyle Evans -- Allow menu items to be conditionally visible by specifying 2504a4fb4f8SKyle Evans -- a visible function. 2514a4fb4f8SKyle Evans if (e.visible ~= nil) and (not e.visible()) then 252ddb76e07SKyle Evans goto continue; 2534a4fb4f8SKyle Evans end 254a7cf0562SKyle Evans if (e.entry_type ~= core.MENU_SEPARATOR) then 255088b4f5fSWarner Losh entry_num = entry_num + 1; 256088b4f5fSWarner Losh screen.setcursor(x, y + line_num); 257ada26c4aSKyle Evans 2582413c411SKyle Evans print(entry_num .. ". " .. menu_entry_name(m, e)); 259088b4f5fSWarner Losh 260088b4f5fSWarner Losh -- fill the alias table 261088b4f5fSWarner Losh alias_table[tostring(entry_num)] = e; 262196ba166SKyle Evans if (e.alias ~= nil) then 263088b4f5fSWarner Losh for n, a in ipairs(e.alias) do 264088b4f5fSWarner Losh alias_table[a] = e; 265088b4f5fSWarner Losh end 266196ba166SKyle Evans end 267088b4f5fSWarner Losh else 268088b4f5fSWarner Losh screen.setcursor(x, y + line_num); 2692413c411SKyle Evans print(menu_entry_name(m, e)); 270088b4f5fSWarner Losh end 2714a4fb4f8SKyle Evans ::continue:: 272088b4f5fSWarner Losh end 273088b4f5fSWarner Losh return alias_table; 274088b4f5fSWarner Loshend 275088b4f5fSWarner Losh 276088b4f5fSWarner Losh 277088b4f5fSWarner Loshfunction drawer.drawbox() 278088b4f5fSWarner Losh x = drawer.box_pos_dim.x; 279088b4f5fSWarner Losh y = drawer.box_pos_dim.y; 280088b4f5fSWarner Losh w = drawer.box_pos_dim.w; 281088b4f5fSWarner Losh h = drawer.box_pos_dim.h; 282088b4f5fSWarner Losh 283088b4f5fSWarner Losh local hl = string.char(0xCD); 284088b4f5fSWarner Losh local vl = string.char(0xBA); 285088b4f5fSWarner Losh 286088b4f5fSWarner Losh local tl = string.char(0xC9); 287088b4f5fSWarner Losh local bl = string.char(0xC8); 288088b4f5fSWarner Losh local tr = string.char(0xBB); 289088b4f5fSWarner Losh local br = string.char(0xBC); 290088b4f5fSWarner Losh 291088b4f5fSWarner Losh screen.setcursor(x, y); print(tl); 292088b4f5fSWarner Losh screen.setcursor(x, y+h); print(bl); 293088b4f5fSWarner Losh screen.setcursor(x+w, y); print(tr); 294088b4f5fSWarner Losh screen.setcursor(x+w, y+h); print(br); 295088b4f5fSWarner Losh 296088b4f5fSWarner Losh for i = 1, w-1 do 297088b4f5fSWarner Losh screen.setcursor(x+i, y); 298088b4f5fSWarner Losh print(hl); 299088b4f5fSWarner Losh screen.setcursor(x+i, y+h); 300088b4f5fSWarner Losh print(hl); 301088b4f5fSWarner Losh end 302088b4f5fSWarner Losh 303088b4f5fSWarner Losh for i = 1, h-1 do 304088b4f5fSWarner Losh screen.setcursor(x, y+i); 305088b4f5fSWarner Losh print(vl); 306088b4f5fSWarner Losh screen.setcursor(x+w, y+i); 307088b4f5fSWarner Losh print(vl); 308088b4f5fSWarner Losh end 309088b4f5fSWarner Losh 310088b4f5fSWarner Losh screen.setcursor(x+(w/2)-9, y); 311088b4f5fSWarner Losh print("Welcome to FreeBSD"); 312088b4f5fSWarner Loshend 313088b4f5fSWarner Losh 314088b4f5fSWarner Loshfunction drawer.draw(x, y, logo) 315088b4f5fSWarner Losh for i = 1, #logo do 316088b4f5fSWarner Losh screen.setcursor(x, y + i); 317088b4f5fSWarner Losh print(logo[i]); 318088b4f5fSWarner Losh end 319088b4f5fSWarner Loshend 320088b4f5fSWarner Losh 321088b4f5fSWarner Loshfunction drawer.drawbrand() 32224a1bd54SKyle Evans local x = tonumber(loader.getenv("loader_brand_x")) or 32324a1bd54SKyle Evans drawer.brand_position.x; 32424a1bd54SKyle Evans local y = tonumber(loader.getenv("loader_brand_y")) or 32524a1bd54SKyle Evans drawer.brand_position.y; 326088b4f5fSWarner Losh 32729aa5794SKyle Evans local graphic = drawer.branddefs[loader.getenv("loader_brand")]; 32829aa5794SKyle Evans if (graphic == nil) then 32929aa5794SKyle Evans graphic = fbsd_logo; 33029aa5794SKyle Evans end 33129aa5794SKyle Evans drawer.draw(x, y, graphic); 332088b4f5fSWarner Loshend 333088b4f5fSWarner Losh 334bb26c57dSKyle Evansfunction shift_brand_text(shift) 335bb26c57dSKyle Evans drawer.brand_position.x = drawer.brand_position.x + shift.x; 336bb26c57dSKyle Evans drawer.brand_position.y = drawer.brand_position.y + shift.y; 337bb26c57dSKyle Evans drawer.menu_position.x = drawer.menu_position.x + shift.x; 338bb26c57dSKyle Evans drawer.menu_position.y = drawer.menu_position.y + shift.y; 339bb26c57dSKyle Evans drawer.box_pos_dim.x = drawer.box_pos_dim.x + shift.x; 340bb26c57dSKyle Evans drawer.box_pos_dim.y = drawer.box_pos_dim.y + shift.y; 341bb26c57dSKyle Evansend 342bb26c57dSKyle Evans 343088b4f5fSWarner Loshfunction drawer.drawlogo() 34424a1bd54SKyle Evans local x = tonumber(loader.getenv("loader_logo_x")) or 34524a1bd54SKyle Evans drawer.logo_position.x; 34624a1bd54SKyle Evans local y = tonumber(loader.getenv("loader_logo_y")) or 34724a1bd54SKyle Evans drawer.logo_position.y; 348088b4f5fSWarner Losh 349088b4f5fSWarner Losh local logo = loader.getenv("loader_logo"); 350088b4f5fSWarner Losh local colored = color.isEnabled(); 351088b4f5fSWarner Losh 352bb26c57dSKyle Evans -- Lookup 353bb26c57dSKyle Evans local logodef = drawer.logodefs[logo]; 354bb26c57dSKyle Evans 355*752b2d40SKyle Evans if (logodef ~= nil) and (logodef.graphic == none) then 356088b4f5fSWarner Losh -- centre brand and text if no logo 357bb26c57dSKyle Evans if (not none_shifted) then 358bb26c57dSKyle Evans shift_brand_text(logodef.shift); 359bb26c57dSKyle Evans none_shifted = true; 360088b4f5fSWarner Losh end 361*752b2d40SKyle Evans elseif (logodef == nil) or (logodef.graphic == nil) or 362bb26c57dSKyle Evans ((not colored) and logodef.requires_color) then 363bb26c57dSKyle Evans -- Choose a sensible default 36424a1bd54SKyle Evans if (colored) then 365bb26c57dSKyle Evans logodef = drawer.logodefs["orb"]; 366088b4f5fSWarner Losh else 367bb26c57dSKyle Evans logodef = drawer.logodefs["orbbw"]; 368088b4f5fSWarner Losh end 369088b4f5fSWarner Losh end 370bb26c57dSKyle Evans if (logodef.shift ~= nil) then 371bb26c57dSKyle Evans x = x + logodef.shift.x; 372bb26c57dSKyle Evans y = y + logodef.shift.y; 373bb26c57dSKyle Evans end 374*752b2d40SKyle Evans drawer.draw(x, y, logodef.graphic); 375088b4f5fSWarner Loshend 376088b4f5fSWarner Losh 37724a1bd54SKyle Evansreturn drawer; 378