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 screen = require("screen");
34 drawer.brand_position = {x = 2, y = 1};
36 " ______ ____ _____ _____ ",
37 " | ____| | _ \\ / ____| __ \\ ",
38 " | |___ _ __ ___ ___ | |_) | (___ | | | |",
39 " | ___| '__/ _ \\/ _ \\| _ < \\___ \\| | | |",
40 " | | | | | __/ __/| |_) |____) | |__| |",
41 " | | | | | | || | | |",
42 " |_| |_| \\___|\\___||____/|_____/|_____/ "
45 drawer.logo_position = {x = 46, y = 1};
46 drawer.beastie_color = {
50 " /- \027[37m_\027[31m `-/ '",
51 " (\027[37m/\\/ \\\027[31m \\ /\\",
52 " \027[37m/ / |\027[31m ` \\",
53 " \027[34mO O \027[37m) \027[31m/ |",
54 " \027[37m`-^--'\027[31m`< '",
58 " \027[33m<----.\027[31m __ / __ \\",
59 " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|",
60 " \027[33m<----'\027[31m `--' `.__,' \\",
63 " \027[36m______\027[31m( (_ / \\______/",
64 " \027[36m,' ,-----' |",
65 " `--{__________)\027[37m"
81 " <----|====O)))==) \\) /====|",
82 " <----' `--' `.__,' \\",
85 " ______( (_ / \\______/",
90 drawer.fbsd_logo_shift = {x = 5, y = 4};
91 drawer.fbsd_logo_v = {
93 " | ____| __ ___ ___ ",
94 " | |__ | '__/ _ \\/ _ \\",
95 " | __|| | | __/ __/",
97 " |_| |_| \\___|\\___|",
99 " | _ \\ / ____| __ \\",
100 " | |_) | (___ | | | |",
101 " | _ < \\___ \\| | | |",
102 " | |_) |____) | |__| |",
104 " |____/|_____/|_____/"
107 drawer.orb_shift = {x = 2, y = 4};
109 " \027[31m``` \027[31;1m`\027[31m",
110 " s` `.....---...\027[31;1m....--.``` -/\027[31m",
111 " +o .--` \027[31;1m/y:` +.\027[31m",
112 " yo`:. \027[31;1m:o `+-\027[31m",
113 " y/ \027[31;1m-/` -o/\027[31m",
114 " .- \027[31;1m::/sy+:.\027[31m",
115 " / \027[31;1m`-- /\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`:`",
122 " \027[31;1m.-- `--.",
123 " .---.....----.\027[37m"
128 " s` `.....---.......--.``` -/",
146 drawer.none_shift = {x = 17, y = 0};
148 drawer.menu_position = {x = 6, y = 11};
150 drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11};
152 function drawer.drawscreen(menu_opts)
153 -- drawlogo() must go first.
154 -- it determines the positions of other elements
158 return drawer.drawmenu(menu_opts);
161 function drawer.drawmenu(m)
162 x = drawer.menu_position.x;
163 y = drawer.menu_position.y;
165 -- print the menu and build the alias table
166 local alias_table = {};
168 for line_num, e in ipairs(m) do
169 if (e.entry_type ~= "separator") then
170 entry_num = entry_num + 1;
171 screen.setcursor(x, y + line_num);
174 if (e.entry_type == "carousel_entry") then
175 local carid = e.carousel_id;
176 local caridx = menu.getCarouselIndex(carid);
177 local choices = e.items();
179 if (#choices < caridx) then
182 name = e.name(caridx, choices[caridx], choices);
186 print(entry_num .. ". "..name);
188 -- fill the alias table
189 alias_table[tostring(entry_num)] = e;
190 if (e.alias ~= nil) then
191 for n, a in ipairs(e.alias) do
196 screen.setcursor(x, y + line_num);
204 function drawer.drawbox()
205 x = drawer.box_pos_dim.x;
206 y = drawer.box_pos_dim.y;
207 w = drawer.box_pos_dim.w;
208 h = drawer.box_pos_dim.h;
210 local hl = string.char(0xCD);
211 local vl = string.char(0xBA);
213 local tl = string.char(0xC9);
214 local bl = string.char(0xC8);
215 local tr = string.char(0xBB);
216 local br = string.char(0xBC);
218 screen.setcursor(x, y); print(tl);
219 screen.setcursor(x, y+h); print(bl);
220 screen.setcursor(x+w, y); print(tr);
221 screen.setcursor(x+w, y+h); print(br);
224 screen.setcursor(x+i, y);
226 screen.setcursor(x+i, y+h);
231 screen.setcursor(x, y+i);
233 screen.setcursor(x+w, y+i);
237 screen.setcursor(x+(w/2)-9, y);
238 print("Welcome to FreeBSD");
241 function drawer.draw(x, y, logo)
243 screen.setcursor(x, y + i);
248 function drawer.drawbrand()
249 local x = tonumber(loader.getenv("loader_brand_x"));
250 local y = tonumber(loader.getenv("loader_brand_y"));
253 x = drawer.brand_position.x;
256 y = drawer.brand_position.y;
259 local logo = load("return " .. tostring(loader.getenv("loader_brand")))();
261 logo = drawer.fbsd_logo;
263 drawer.draw(x, y, logo);
266 function drawer.drawlogo()
267 local x = tonumber(loader.getenv("loader_logo_x"));
268 local y = tonumber(loader.getenv("loader_logo_y"));
271 x = drawer.logo_position.x;
274 y = drawer.logo_position.y;
277 local logo = loader.getenv("loader_logo");
278 local s = {x = 0, y = 0};
279 local colored = color.isEnabled();
281 if logo == "beastie" then
283 logo = drawer.beastie_color;
285 elseif logo == "beastiebw" then
286 logo = drawer.beastie;
287 elseif logo == "fbsdbw" then
288 logo = drawer.fbsd_logo_v;
289 s = drawer.fbsd_logo_shift;
290 elseif logo == "orb" then
292 logo = drawer.orb_color;
294 s = drawer.orb_shift;
295 elseif logo == "orbbw" then
297 s = drawer.orb_shift;
298 elseif logo == "tribute" then
299 logo = drawer.fbsd_logo;
300 elseif logo == "tributebw" then
301 logo = drawer.fbsd_logo;
302 elseif logo == "none" then
303 --centre brand and text if no logo
304 drawer.brand_position.x = drawer.brand_position.x + drawer.none_shift.x;
305 drawer.brand_position.y = drawer.brand_position.y + drawer.none_shift.y;
306 drawer.menu_position.x = drawer.menu_position.x + drawer.none_shift.x;
307 drawer.menu_position.y = drawer.menu_position.y + drawer.none_shift.y;
308 drawer.box_pos_dim.x = drawer.box_pos_dim.x + drawer.none_shift.x;
309 drawer.box_pos_dim.y = drawer.box_pos_dim.y + drawer.none_shift.y;
310 --prevent redraws from moving menu further
311 drawer.none_shift.x = 0;
312 drawer.none_shift.y = 0;
317 logo = drawer.orb_color;
322 drawer.draw(x + s.x, y + s.y, logo);