2 -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3 -- All rights reserved.
5 -- Redistribution and use in source and binary forms, with or without
6 -- modification, are permitted provided that the following conditions
8 -- 1. Redistributions of source code must retain the above copyright
9 -- notice, this list of conditions and the following disclaimer.
10 -- 2. Redistributions in binary form must reproduce the above copyright
11 -- notice, this list of conditions and the following disclaimer in the
12 -- documentation and/or other materials provided with the distribution.
14 -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 local color = require("color");
32 local core = require("core");
33 local screen = require("screen");
35 drawer.brand_position = {x = 2, y = 1};
37 " ______ ____ _____ _____ ",
38 " | ____| | _ \\ / ____| __ \\ ",
39 " | |___ _ __ ___ ___ | |_) | (___ | | | |",
40 " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |",
41 " | | | | | __/ __/| |_) |____) | |__| |",
42 " | | | | | | || | | |",
43 " |_| |_| \\___|\\___||____/|_____/|_____/ "
46 drawer.logo_position = {x = 46, y = 1};
47 drawer.beastie_color = {
51 " /- \027[37m_\027[31m `-/ '",
52 " (\027[37m/\\/ \\\027[31m \\ /\\",
53 " \027[37m/ / |\027[31m ` \\",
54 " \027[34mO O \027[37m) \027[31m/ |",
55 " \027[37m`-^--'\027[31m`< '",
59 " \027[33m<----.\027[31m __ / __ \\",
60 " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
61 " \027[33m<----'\027[31m `--' `.__,' \\",
64 " \027[36m______\027[31m( (_ / \\______/",
65 " \027[36m,' ,-----' |",
66 " `--{__________)\027[37m"
82 " <----|====O)))==) \\) /====|",
83 " <----' `--' `.__,' \\",
86 " ______( (_ / \\______/",
91 drawer.fbsd_logo_shift = {x = 5, y = 4};
92 drawer.fbsd_logo_v = {
94 " | ____| __ ___ ___ ",
95 " | |__ | '__/ _ \\/ _ \\",
96 " | __|| | | __/ __/",
98 " |_| |_| \\___|\\___|",
100 " | _ \\ / ____| __ \\",
101 " | |_) | (___ | | | |",
102 " | _ < \\___ \\| | | |",
103 " | |_) |____) | |__| |",
105 " |____/|_____/|_____/"
108 drawer.orb_shift = {x = 2, y = 4};
110 " \027[31m``` \027[31;1m`\027[31m",
111 " s` `.....---...\027[31;1m....--.``` -/\027[31m",
112 " +o .--` \027[31;1m/y:` +.\027[31m",
113 " yo`:. \027[31;1m:o `+-\027[31m",
114 " y/ \027[31;1m-/` -o/\027[31m",
115 " .- \027[31;1m::/sy+:.\027[31m",
116 " / \027[31;1m`-- /\027[31m",
117 " `: \027[31;1m:`\027[31m",
118 " `: \027[31;1m:`\027[31m",
119 " / \027[31;1m/\027[31m",
120 " .- \027[31;1m-.\027[31m",
121 " -- \027[31;1m-.\027[31m",
122 " `:` \027[31;1m`:`",
123 " \027[31;1m.-- `--.",
124 " .---.....----.\027[37m"
129 " s` `.....---.......--.``` -/",
147 drawer.none_shift = {x = 17, y = 0};
149 drawer.menu_position = {x = 6, y = 11};
151 drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11};
153 function drawer.drawscreen(menu_opts)
154 -- drawlogo() must go first.
155 -- it determines the positions of other elements
159 return drawer.drawmenu(menu_opts);
162 function drawer.drawmenu(m)
163 x = drawer.menu_position.x;
164 y = drawer.menu_position.y;
166 -- print the menu and build the alias table
167 local alias_table = {};
169 local menu_entries = m.entries;
170 if (type(menu_entries) == "function") then
171 menu_entries = menu_entries();
173 for line_num, e in ipairs(menu_entries) do
174 -- Allow menu items to be conditionally visible by specifying
175 -- a visible function.
176 if (e.visible ~= nil) and (not e.visible()) then
179 if (e.entry_type ~= core.MENU_SEPARATOR) then
180 entry_num = entry_num + 1;
181 screen.setcursor(x, y + line_num);
184 if (e.entry_type == core.MENU_CAROUSEL_ENTRY) then
185 local carid = e.carousel_id;
186 local caridx = menu.getCarouselIndex(carid);
187 local choices = e.items();
189 if (#choices < caridx) then
192 name = e.name(caridx, choices[caridx], choices);
196 print(entry_num .. ". "..name);
198 -- fill the alias table
199 alias_table[tostring(entry_num)] = e;
200 if (e.alias ~= nil) then
201 for n, a in ipairs(e.alias) do
206 screen.setcursor(x, y + line_num);
215 function drawer.drawbox()
216 x = drawer.box_pos_dim.x;
217 y = drawer.box_pos_dim.y;
218 w = drawer.box_pos_dim.w;
219 h = drawer.box_pos_dim.h;
221 local hl = string.char(0xCD);
222 local vl = string.char(0xBA);
224 local tl = string.char(0xC9);
225 local bl = string.char(0xC8);
226 local tr = string.char(0xBB);
227 local br = string.char(0xBC);
229 screen.setcursor(x, y); print(tl);
230 screen.setcursor(x, y+h); print(bl);
231 screen.setcursor(x+w, y); print(tr);
232 screen.setcursor(x+w, y+h); print(br);
235 screen.setcursor(x+i, y);
237 screen.setcursor(x+i, y+h);
242 screen.setcursor(x, y+i);
244 screen.setcursor(x+w, y+i);
248 screen.setcursor(x+(w/2)-9, y);
249 print("Welcome to FreeBSD");
252 function drawer.draw(x, y, logo)
254 screen.setcursor(x, y + i);
259 function drawer.drawbrand()
260 local x = tonumber(loader.getenv("loader_brand_x")) or
261 drawer.brand_position.x;
262 local y = tonumber(loader.getenv("loader_brand_y")) or
263 drawer.brand_position.y;
265 local logo = load("return " .. tostring(loader.getenv("loader_brand")))() or
267 drawer.draw(x, y, logo);
270 function drawer.drawlogo()
271 local x = tonumber(loader.getenv("loader_logo_x")) or
272 drawer.logo_position.x;
273 local y = tonumber(loader.getenv("loader_logo_y")) or
274 drawer.logo_position.y;
276 local logo = loader.getenv("loader_logo");
277 local s = {x = 0, y = 0};
278 local colored = color.isEnabled();
280 if (logo == "beastie") then
282 logo = drawer.beastie_color;
284 elseif (logo == "beastiebw") then
285 logo = drawer.beastie;
286 elseif (logo == "fbsdbw") then
287 logo = drawer.fbsd_logo_v;
288 s = drawer.fbsd_logo_shift;
289 elseif (logo == "orb") then
291 logo = drawer.orb_color;
293 s = drawer.orb_shift;
294 elseif (logo == "orbbw") then
296 s = drawer.orb_shift;
297 elseif (logo == "tribute") then
298 logo = drawer.fbsd_logo;
299 elseif (logo == "tributebw") then
300 logo = drawer.fbsd_logo;
301 elseif (logo == "none") then
302 --centre brand and text if no logo
303 drawer.brand_position.x = drawer.brand_position.x + drawer.none_shift.x;
304 drawer.brand_position.y = drawer.brand_position.y + drawer.none_shift.y;
305 drawer.menu_position.x = drawer.menu_position.x + drawer.none_shift.x;
306 drawer.menu_position.y = drawer.menu_position.y + drawer.none_shift.y;
307 drawer.box_pos_dim.x = drawer.box_pos_dim.x + drawer.none_shift.x;
308 drawer.box_pos_dim.y = drawer.box_pos_dim.y + drawer.none_shift.y;
309 --prevent redraws from moving menu further
310 drawer.none_shift.x = 0;
311 drawer.none_shift.y = 0;
316 logo = drawer.orb_color;
321 drawer.draw(x + s.x, y + s.y, logo);