1*088b4f5fSWarner Losh-- 2*088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3*088b4f5fSWarner Losh-- All rights reserved. 4*088b4f5fSWarner Losh-- 5*088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 6*088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 7*088b4f5fSWarner Losh-- are met: 8*088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 9*088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 10*088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 11*088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 12*088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 13*088b4f5fSWarner Losh-- 14*088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*088b4f5fSWarner Losh-- SUCH DAMAGE. 25*088b4f5fSWarner Losh-- 26*088b4f5fSWarner Losh-- $FreeBSD$ 27*088b4f5fSWarner Losh-- 28*088b4f5fSWarner Losh 29*088b4f5fSWarner Loshlocal drawer = {}; 30*088b4f5fSWarner Losh 31*088b4f5fSWarner Loshlocal color = require("color"); 32*088b4f5fSWarner Loshlocal screen = require("screen"); 33*088b4f5fSWarner Losh 34*088b4f5fSWarner Loshdrawer.brand_position = {x = 2, y = 1}; 35*088b4f5fSWarner Loshdrawer.fbsd_logo = { 36*088b4f5fSWarner Losh " ______ ____ _____ _____ ", 37*088b4f5fSWarner Losh " | ____| | _ \\ / ____| __ \\ ", 38*088b4f5fSWarner Losh " | |___ _ __ ___ ___ | |_) | (___ | | | |", 39*088b4f5fSWarner Losh " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |", 40*088b4f5fSWarner Losh " | | | | | __/ __/| |_) |____) | |__| |", 41*088b4f5fSWarner Losh " | | | | | | || | | |", 42*088b4f5fSWarner Losh " |_| |_| \\___|\\___||____/|_____/|_____/ " 43*088b4f5fSWarner Losh}; 44*088b4f5fSWarner Losh 45*088b4f5fSWarner Loshdrawer.logo_position = {x = 46, y = 1}; 46*088b4f5fSWarner Loshdrawer.beastie_color = { 47*088b4f5fSWarner Losh " \027[31m, ,", 48*088b4f5fSWarner Losh " /( )`", 49*088b4f5fSWarner Losh " \\ \\___ / |", 50*088b4f5fSWarner Losh " /- \027[37m_\027[31m `-/ '", 51*088b4f5fSWarner Losh " (\027[37m/\\/ \\\027[31m \\ /\\", 52*088b4f5fSWarner Losh " \027[37m/ / |\027[31m ` \\", 53*088b4f5fSWarner Losh " \027[34mO O \027[37m) \027[31m/ |", 54*088b4f5fSWarner Losh " \027[37m`-^--'\027[31m`< '", 55*088b4f5fSWarner Losh " (_.) _ ) /", 56*088b4f5fSWarner Losh " `.___/` /", 57*088b4f5fSWarner Losh " `-----' /", 58*088b4f5fSWarner Losh " \027[33m<----.\027[31m __ / __ \\", 59*088b4f5fSWarner Losh " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|", 60*088b4f5fSWarner Losh " \027[33m<----'\027[31m `--' `.__,' \\", 61*088b4f5fSWarner Losh " | |", 62*088b4f5fSWarner Losh " \\ / /\\", 63*088b4f5fSWarner Losh " \027[36m______\027[31m( (_ / \\______/", 64*088b4f5fSWarner Losh " \027[36m,' ,-----' |", 65*088b4f5fSWarner Losh " `--{__________)\027[37m" 66*088b4f5fSWarner Losh}; 67*088b4f5fSWarner Losh 68*088b4f5fSWarner Loshdrawer.beastie = { 69*088b4f5fSWarner Losh " , ,", 70*088b4f5fSWarner Losh " /( )`", 71*088b4f5fSWarner Losh " \\ \\___ / |", 72*088b4f5fSWarner Losh " /- _ `-/ '", 73*088b4f5fSWarner Losh " (/\\/ \\ \\ /\\", 74*088b4f5fSWarner Losh " / / | ` \\", 75*088b4f5fSWarner Losh " O O ) / |", 76*088b4f5fSWarner Losh " `-^--'`< '", 77*088b4f5fSWarner Losh " (_.) _ ) /", 78*088b4f5fSWarner Losh " `.___/` /", 79*088b4f5fSWarner Losh " `-----' /", 80*088b4f5fSWarner Losh " <----. __ / __ \\", 81*088b4f5fSWarner Losh " <----|====O)))==) \\) /====|", 82*088b4f5fSWarner Losh " <----' `--' `.__,' \\", 83*088b4f5fSWarner Losh " | |", 84*088b4f5fSWarner Losh " \\ / /\\", 85*088b4f5fSWarner Losh " ______( (_ / \\______/", 86*088b4f5fSWarner Losh " ,' ,-----' |", 87*088b4f5fSWarner Losh " `--{__________)" 88*088b4f5fSWarner Losh}; 89*088b4f5fSWarner Losh 90*088b4f5fSWarner Loshdrawer.fbsd_logo_shift = {x = 5, y = 4}; 91*088b4f5fSWarner Loshdrawer.fbsd_logo_v = { 92*088b4f5fSWarner Losh " ______", 93*088b4f5fSWarner Losh " | ____| __ ___ ___ ", 94*088b4f5fSWarner Losh " | |__ | '__/ _ \\/ _ \\", 95*088b4f5fSWarner Losh " | __|| | | __/ __/", 96*088b4f5fSWarner Losh " | | | | | | |", 97*088b4f5fSWarner Losh " |_| |_| \\___|\\___|", 98*088b4f5fSWarner Losh " ____ _____ _____", 99*088b4f5fSWarner Losh " | _ \\ / ____| __ \\", 100*088b4f5fSWarner Losh " | |_) | (___ | | | |", 101*088b4f5fSWarner Losh " | _ < \\___ \\| | | |", 102*088b4f5fSWarner Losh " | |_) |____) | |__| |", 103*088b4f5fSWarner Losh " | | | |", 104*088b4f5fSWarner Losh " |____/|_____/|_____/" 105*088b4f5fSWarner Losh}; 106*088b4f5fSWarner Losh 107*088b4f5fSWarner Loshdrawer.orb_shift = {x = 2, y = 4}; 108*088b4f5fSWarner Loshdrawer.orb_color = { 109*088b4f5fSWarner Losh " \027[31m``` \027[31;1m`\027[31m", 110*088b4f5fSWarner Losh " s` `.....---...\027[31;1m....--.``` -/\027[31m", 111*088b4f5fSWarner Losh " +o .--` \027[31;1m/y:` +.\027[31m", 112*088b4f5fSWarner Losh " yo`:. \027[31;1m:o `+-\027[31m", 113*088b4f5fSWarner Losh " y/ \027[31;1m-/` -o/\027[31m", 114*088b4f5fSWarner Losh " .- \027[31;1m::/sy+:.\027[31m", 115*088b4f5fSWarner Losh " / \027[31;1m`-- /\027[31m", 116*088b4f5fSWarner Losh " `: \027[31;1m:`\027[31m", 117*088b4f5fSWarner Losh " `: \027[31;1m:`\027[31m", 118*088b4f5fSWarner Losh " / \027[31;1m/\027[31m", 119*088b4f5fSWarner Losh " .- \027[31;1m-.\027[31m", 120*088b4f5fSWarner Losh " -- \027[31;1m-.\027[31m", 121*088b4f5fSWarner Losh " `:` \027[31;1m`:`", 122*088b4f5fSWarner Losh " \027[31;1m.-- `--.", 123*088b4f5fSWarner Losh " .---.....----.\027[37m" 124*088b4f5fSWarner Losh}; 125*088b4f5fSWarner Losh 126*088b4f5fSWarner Loshdrawer.orb = { 127*088b4f5fSWarner Losh " ``` `", 128*088b4f5fSWarner Losh " s` `.....---.......--.``` -/", 129*088b4f5fSWarner Losh " +o .--` /y:` +.", 130*088b4f5fSWarner Losh " yo`:. :o `+-", 131*088b4f5fSWarner Losh " y/ -/` -o/", 132*088b4f5fSWarner Losh " .- ::/sy+:.", 133*088b4f5fSWarner Losh " / `-- /", 134*088b4f5fSWarner Losh " `: :`", 135*088b4f5fSWarner Losh " `: :`", 136*088b4f5fSWarner Losh " / /", 137*088b4f5fSWarner Losh " .- -.", 138*088b4f5fSWarner Losh " -- -.", 139*088b4f5fSWarner Losh " `:` `:`", 140*088b4f5fSWarner Losh " .-- `--.", 141*088b4f5fSWarner Losh " .---.....----." 142*088b4f5fSWarner Losh}; 143*088b4f5fSWarner Losh 144*088b4f5fSWarner Loshdrawer.none = {""}; 145*088b4f5fSWarner Losh 146*088b4f5fSWarner Loshdrawer.none_shift = {x = 17, y = 0}; 147*088b4f5fSWarner Losh 148*088b4f5fSWarner Loshdrawer.menu_position = {x = 6, y = 11}; 149*088b4f5fSWarner Losh 150*088b4f5fSWarner Loshdrawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11}; 151*088b4f5fSWarner Losh 152*088b4f5fSWarner Loshfunction drawer.drawscreen(menu_opts) 153*088b4f5fSWarner Losh -- drawlogo() must go first. 154*088b4f5fSWarner Losh -- it determines the positions of other elements 155*088b4f5fSWarner Losh drawer.drawlogo(); 156*088b4f5fSWarner Losh drawer.drawbrand(); 157*088b4f5fSWarner Losh drawer.drawbox(); 158*088b4f5fSWarner Losh return drawer.drawmenu(menu_opts); 159*088b4f5fSWarner Loshend 160*088b4f5fSWarner Losh 161*088b4f5fSWarner Loshfunction drawer.drawmenu(m) 162*088b4f5fSWarner Losh x = drawer.menu_position.x; 163*088b4f5fSWarner Losh y = drawer.menu_position.y; 164*088b4f5fSWarner Losh 165*088b4f5fSWarner Losh -- print the menu and build the alias table 166*088b4f5fSWarner Losh local alias_table = {}; 167*088b4f5fSWarner Losh local entry_num = 0; 168*088b4f5fSWarner Losh for line_num, e in ipairs(m) do 169*088b4f5fSWarner Losh if (e.entry_type ~= "separator") then 170*088b4f5fSWarner Losh entry_num = entry_num + 1; 171*088b4f5fSWarner Losh screen.setcursor(x, y + line_num); 172*088b4f5fSWarner Losh print(entry_num .. ". "..e.name()); 173*088b4f5fSWarner Losh 174*088b4f5fSWarner Losh -- fill the alias table 175*088b4f5fSWarner Losh alias_table[tostring(entry_num)] = e; 176*088b4f5fSWarner Losh for n, a in ipairs(e.alias) do 177*088b4f5fSWarner Losh alias_table[a] = e; 178*088b4f5fSWarner Losh end 179*088b4f5fSWarner Losh else 180*088b4f5fSWarner Losh screen.setcursor(x, y + line_num); 181*088b4f5fSWarner Losh print(e.name()); 182*088b4f5fSWarner Losh end 183*088b4f5fSWarner Losh end 184*088b4f5fSWarner Losh return alias_table; 185*088b4f5fSWarner Loshend 186*088b4f5fSWarner Losh 187*088b4f5fSWarner Losh 188*088b4f5fSWarner Loshfunction drawer.drawbox() 189*088b4f5fSWarner Losh x = drawer.box_pos_dim.x; 190*088b4f5fSWarner Losh y = drawer.box_pos_dim.y; 191*088b4f5fSWarner Losh w = drawer.box_pos_dim.w; 192*088b4f5fSWarner Losh h = drawer.box_pos_dim.h; 193*088b4f5fSWarner Losh 194*088b4f5fSWarner Losh local hl = string.char(0xCD); 195*088b4f5fSWarner Losh local vl = string.char(0xBA); 196*088b4f5fSWarner Losh 197*088b4f5fSWarner Losh local tl = string.char(0xC9); 198*088b4f5fSWarner Losh local bl = string.char(0xC8); 199*088b4f5fSWarner Losh local tr = string.char(0xBB); 200*088b4f5fSWarner Losh local br = string.char(0xBC); 201*088b4f5fSWarner Losh 202*088b4f5fSWarner Losh screen.setcursor(x, y); print(tl); 203*088b4f5fSWarner Losh screen.setcursor(x, y+h); print(bl); 204*088b4f5fSWarner Losh screen.setcursor(x+w, y); print(tr); 205*088b4f5fSWarner Losh screen.setcursor(x+w, y+h); print(br); 206*088b4f5fSWarner Losh 207*088b4f5fSWarner Losh for i = 1, w-1 do 208*088b4f5fSWarner Losh screen.setcursor(x+i, y); 209*088b4f5fSWarner Losh print(hl); 210*088b4f5fSWarner Losh screen.setcursor(x+i, y+h); 211*088b4f5fSWarner Losh print(hl); 212*088b4f5fSWarner Losh end 213*088b4f5fSWarner Losh 214*088b4f5fSWarner Losh for i = 1, h-1 do 215*088b4f5fSWarner Losh screen.setcursor(x, y+i); 216*088b4f5fSWarner Losh print(vl); 217*088b4f5fSWarner Losh screen.setcursor(x+w, y+i); 218*088b4f5fSWarner Losh print(vl); 219*088b4f5fSWarner Losh end 220*088b4f5fSWarner Losh 221*088b4f5fSWarner Losh screen.setcursor(x+(w/2)-9, y); 222*088b4f5fSWarner Losh print("Welcome to FreeBSD"); 223*088b4f5fSWarner Loshend 224*088b4f5fSWarner Losh 225*088b4f5fSWarner Loshfunction drawer.draw(x, y, logo) 226*088b4f5fSWarner Losh for i = 1, #logo do 227*088b4f5fSWarner Losh screen.setcursor(x, y + i); 228*088b4f5fSWarner Losh print(logo[i]); 229*088b4f5fSWarner Losh end 230*088b4f5fSWarner Loshend 231*088b4f5fSWarner Losh 232*088b4f5fSWarner Loshfunction drawer.drawbrand() 233*088b4f5fSWarner Losh local x = tonumber(loader.getenv("loader_brand_x")); 234*088b4f5fSWarner Losh local y = tonumber(loader.getenv("loader_brand_y")); 235*088b4f5fSWarner Losh 236*088b4f5fSWarner Losh if not x then 237*088b4f5fSWarner Losh x = drawer.brand_position.x; 238*088b4f5fSWarner Losh end 239*088b4f5fSWarner Losh if not y then 240*088b4f5fSWarner Losh y = drawer.brand_position.y; 241*088b4f5fSWarner Losh end 242*088b4f5fSWarner Losh 243*088b4f5fSWarner Losh local logo = load("return " .. tostring(loader.getenv("loader_brand")))(); 244*088b4f5fSWarner Losh if not logo then 245*088b4f5fSWarner Losh logo = drawer.fbsd_logo; 246*088b4f5fSWarner Losh end 247*088b4f5fSWarner Losh drawer.draw(x, y, logo); 248*088b4f5fSWarner Loshend 249*088b4f5fSWarner Losh 250*088b4f5fSWarner Loshfunction drawer.drawlogo() 251*088b4f5fSWarner Losh local x = tonumber(loader.getenv("loader_logo_x")); 252*088b4f5fSWarner Losh local y = tonumber(loader.getenv("loader_logo_y")); 253*088b4f5fSWarner Losh 254*088b4f5fSWarner Losh if not x then 255*088b4f5fSWarner Losh x = drawer.logo_position.x; 256*088b4f5fSWarner Losh end 257*088b4f5fSWarner Losh if not y then 258*088b4f5fSWarner Losh y = drawer.logo_position.y; 259*088b4f5fSWarner Losh end 260*088b4f5fSWarner Losh 261*088b4f5fSWarner Losh local logo = loader.getenv("loader_logo"); 262*088b4f5fSWarner Losh local s = {x = 0, y = 0}; 263*088b4f5fSWarner Losh local colored = color.isEnabled(); 264*088b4f5fSWarner Losh 265*088b4f5fSWarner Losh if logo == "beastie" then 266*088b4f5fSWarner Losh if colored then 267*088b4f5fSWarner Losh logo = drawer.beastie_color; 268*088b4f5fSWarner Losh end 269*088b4f5fSWarner Losh elseif logo == "beastiebw" then 270*088b4f5fSWarner Losh logo = drawer.beastie; 271*088b4f5fSWarner Losh elseif logo == "fbsdbw" then 272*088b4f5fSWarner Losh logo = drawer.fbsd_logo_v; 273*088b4f5fSWarner Losh s = drawer.fbsd_logo_shift; 274*088b4f5fSWarner Losh elseif logo == "orb" then 275*088b4f5fSWarner Losh if colored then 276*088b4f5fSWarner Losh logo = drawer.orb_color; 277*088b4f5fSWarner Losh end 278*088b4f5fSWarner Losh s = drawer.orb_shift; 279*088b4f5fSWarner Losh elseif logo == "orbbw" then 280*088b4f5fSWarner Losh logo = drawer.orb; 281*088b4f5fSWarner Losh s = drawer.orb_shift; 282*088b4f5fSWarner Losh elseif logo == "tribute" then 283*088b4f5fSWarner Losh logo = drawer.fbsd_logo; 284*088b4f5fSWarner Losh elseif logo == "tributebw" then 285*088b4f5fSWarner Losh logo = drawer.fbsd_logo; 286*088b4f5fSWarner Losh elseif logo == "none" then 287*088b4f5fSWarner Losh --centre brand and text if no logo 288*088b4f5fSWarner Losh drawer.brand_position.x = drawer.brand_position.x + drawer.none_shift.x; 289*088b4f5fSWarner Losh drawer.brand_position.y = drawer.brand_position.y + drawer.none_shift.y; 290*088b4f5fSWarner Losh drawer.menu_position.x = drawer.menu_position.x + drawer.none_shift.x; 291*088b4f5fSWarner Losh drawer.menu_position.y = drawer.menu_position.y + drawer.none_shift.y; 292*088b4f5fSWarner Losh drawer.box_pos_dim.x = drawer.box_pos_dim.x + drawer.none_shift.x; 293*088b4f5fSWarner Losh drawer.box_pos_dim.y = drawer.box_pos_dim.y + drawer.none_shift.y; 294*088b4f5fSWarner Losh --prevent redraws from moving menu further 295*088b4f5fSWarner Losh drawer.none_shift.x = 0; 296*088b4f5fSWarner Losh drawer.none_shift.y = 0; 297*088b4f5fSWarner Losh logo = drawer.none; 298*088b4f5fSWarner Losh end 299*088b4f5fSWarner Losh if not logo then 300*088b4f5fSWarner Losh if colored then 301*088b4f5fSWarner Losh logo = drawer.orb_color; 302*088b4f5fSWarner Losh else 303*088b4f5fSWarner Losh logo = drawer.orb; 304*088b4f5fSWarner Losh end 305*088b4f5fSWarner Losh end 306*088b4f5fSWarner Losh drawer.draw(x + s.x, y + s.y, logo); 307*088b4f5fSWarner Loshend 308*088b4f5fSWarner Losh 309*088b4f5fSWarner Loshreturn drawer 310