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
29 local color = require("color");
30 local core = require("core");
31 local screen = require("screen");
35 drawer.menu_name_handlers = {
36 -- Menu name handlers should take the menu being drawn and entry being
37 -- drawn as parameters, and return the name of the item.
38 -- This is designed so that everything, including menu separators, may
39 -- have their names derived differently. The default action for entry
40 -- types not specified here is to call and use entry.name().
41 [core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry)
42 local carid = entry.carousel_id;
43 local caridx = menu.getCarouselIndex(carid);
44 local choices = entry.items();
46 if (#choices < caridx) then
49 return entry.name(caridx, choices[caridx], choices);
53 drawer.brand_position = {x = 2, y = 1};
55 " ______ ____ _____ _____ ",
56 " | ____| | _ \\ / ____| __ \\ ",
57 " | |___ _ __ ___ ___ | |_) | (___ | | | |",
58 " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |",
59 " | | | | | __/ __/| |_) |____) | |__| |",
60 " | | | | | | || | | |",
61 " |_| |_| \\___|\\___||____/|_____/|_____/ "
64 drawer.logo_position = {x = 46, y = 1};
65 drawer.beastie_color = {
69 " /- \027[37m_\027[31m `-/ '",
70 " (\027[37m/\\/ \\\027[31m \\ /\\",
71 " \027[37m/ / |\027[31m ` \\",
72 " \027[34mO O \027[37m) \027[31m/ |",
73 " \027[37m`-^--'\027[31m`< '",
77 " \027[33m<----.\027[31m __ / __ \\",
78 " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
79 " \027[33m<----'\027[31m `--' `.__,' \\",
82 " \027[36m______\027[31m( (_ / \\______/",
83 " \027[36m,' ,-----' |",
84 " `--{__________)\027[37m"
100 " <----|====O)))==) \\) /====|",
101 " <----' `--' `.__,' \\",
104 " ______( (_ / \\______/",
109 drawer.fbsd_logo_shift = {x = 5, y = 4};
110 drawer.fbsd_logo_v = {
112 " | ____| __ ___ ___ ",
113 " | |__ | '__/ _ \\/ _ \\",
114 " | __|| | | __/ __/",
116 " |_| |_| \\___|\\___|",
118 " | _ \\ / ____| __ \\",
119 " | |_) | (___ | | | |",
120 " | _ < \\___ \\| | | |",
121 " | |_) |____) | |__| |",
123 " |____/|_____/|_____/"
126 drawer.orb_shift = {x = 2, y = 4};
128 " \027[31m``` \027[31;1m`\027[31m",
129 " s` `.....---...\027[31;1m....--.``` -/\027[31m",
130 " +o .--` \027[31;1m/y:` +.\027[31m",
131 " yo`:. \027[31;1m:o `+-\027[31m",
132 " y/ \027[31;1m-/` -o/\027[31m",
133 " .- \027[31;1m::/sy+:.\027[31m",
134 " / \027[31;1m`-- /\027[31m",
135 " `: \027[31;1m:`\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`:`",
141 " \027[31;1m.-- `--.",
142 " .---.....----.\027[37m"
147 " s` `.....---.......--.``` -/",
165 drawer.none_shift = {x = 17, y = 0};
167 drawer.menu_position = {x = 6, y = 11};
169 drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11};
171 function drawer.drawscreen(menu_opts)
172 -- drawlogo() must go first.
173 -- it determines the positions of other elements
177 return drawer.drawmenu(menu_opts);
180 function menu_entry_name(drawing_menu, entry)
181 local name_handler = drawer.menu_name_handlers[entry.entry_type];
183 if (name_handler ~= nil) then
184 return name_handler(drawing_menu, entry);
189 function drawer.drawmenu(m)
190 x = drawer.menu_position.x;
191 y = drawer.menu_position.y;
193 -- print the menu and build the alias table
194 local alias_table = {};
196 local menu_entries = m.entries;
197 if (type(menu_entries) == "function") then
198 menu_entries = menu_entries();
200 for line_num, e in ipairs(menu_entries) do
201 -- Allow menu items to be conditionally visible by specifying
202 -- a visible function.
203 if (e.visible ~= nil) and (not e.visible()) then
206 if (e.entry_type ~= core.MENU_SEPARATOR) then
207 entry_num = entry_num + 1;
208 screen.setcursor(x, y + line_num);
210 print(entry_num .. ". " .. menu_entry_name(m, e));
212 -- fill the alias table
213 alias_table[tostring(entry_num)] = e;
214 if (e.alias ~= nil) then
215 for n, a in ipairs(e.alias) do
220 screen.setcursor(x, y + line_num);
221 print(menu_entry_name(m, e));
229 function drawer.drawbox()
230 x = drawer.box_pos_dim.x;
231 y = drawer.box_pos_dim.y;
232 w = drawer.box_pos_dim.w;
233 h = drawer.box_pos_dim.h;
235 local hl = string.char(0xCD);
236 local vl = string.char(0xBA);
238 local tl = string.char(0xC9);
239 local bl = string.char(0xC8);
240 local tr = string.char(0xBB);
241 local br = string.char(0xBC);
243 screen.setcursor(x, y); print(tl);
244 screen.setcursor(x, y+h); print(bl);
245 screen.setcursor(x+w, y); print(tr);
246 screen.setcursor(x+w, y+h); print(br);
249 screen.setcursor(x+i, y);
251 screen.setcursor(x+i, y+h);
256 screen.setcursor(x, y+i);
258 screen.setcursor(x+w, y+i);
262 screen.setcursor(x+(w/2)-9, y);
263 print("Welcome to FreeBSD");
266 function drawer.draw(x, y, logo)
268 screen.setcursor(x, y + i);
273 function drawer.drawbrand()
274 local x = tonumber(loader.getenv("loader_brand_x")) or
275 drawer.brand_position.x;
276 local y = tonumber(loader.getenv("loader_brand_y")) or
277 drawer.brand_position.y;
279 local logo = load("return " .. tostring(loader.getenv("loader_brand")))() or
281 drawer.draw(x, y, logo);
284 function drawer.drawlogo()
285 local x = tonumber(loader.getenv("loader_logo_x")) or
286 drawer.logo_position.x;
287 local y = tonumber(loader.getenv("loader_logo_y")) or
288 drawer.logo_position.y;
290 local logo = loader.getenv("loader_logo");
291 local s = {x = 0, y = 0};
292 local colored = color.isEnabled();
294 if (logo == "beastie") then
296 logo = drawer.beastie_color;
298 elseif (logo == "beastiebw") then
299 logo = drawer.beastie;
300 elseif (logo == "fbsdbw") then
301 logo = drawer.fbsd_logo_v;
302 s = drawer.fbsd_logo_shift;
303 elseif (logo == "orb") then
305 logo = drawer.orb_color;
307 s = drawer.orb_shift;
308 elseif (logo == "orbbw") then
310 s = drawer.orb_shift;
311 elseif (logo == "tribute") then
312 logo = drawer.fbsd_logo;
313 elseif (logo == "tributebw") then
314 logo = drawer.fbsd_logo;
315 elseif (logo == "none") then
316 --centre brand and text if no logo
317 drawer.brand_position.x = drawer.brand_position.x + drawer.none_shift.x;
318 drawer.brand_position.y = drawer.brand_position.y + drawer.none_shift.y;
319 drawer.menu_position.x = drawer.menu_position.x + drawer.none_shift.x;
320 drawer.menu_position.y = drawer.menu_position.y + drawer.none_shift.y;
321 drawer.box_pos_dim.x = drawer.box_pos_dim.x + drawer.none_shift.x;
322 drawer.box_pos_dim.y = drawer.box_pos_dim.y + drawer.none_shift.y;
323 --prevent redraws from moving menu further
324 drawer.none_shift.x = 0;
325 drawer.none_shift.y = 0;
330 logo = drawer.orb_color;
335 drawer.draw(x + s.x, y + s.y, logo);