menu.lua (39006570a401ef5fb6d7d8029089fb11280bfd24) menu.lua (ada26c4a885910e0b07367b260ba049cfbae4a10)
1--
2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3-- All rights reserved.
4--
5-- Redistribution and use in source and binary forms, with or without
6-- modification, are permitted provided that the following conditions
7-- are met:
8-- 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34local config = require("config");
35local screen = require("screen");
36local drawer = require("drawer");
37
38local OnOff;
39local skip;
40local run;
41local autoboot;
1--
2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3-- All rights reserved.
4--
5-- Redistribution and use in source and binary forms, with or without
6-- modification, are permitted provided that the following conditions
7-- are met:
8-- 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34local config = require("config");
35local screen = require("screen");
36local drawer = require("drawer");
37
38local OnOff;
39local skip;
40local run;
41local autoboot;
42local current_kernel_index = 1;
42local carousel_choices = {};
43
44--loader menu tree:
45--rooted at menu.welcome
46--submenu declarations:
47local boot_options;
48local welcome;
49
50menu.boot_options = {

--- 137 unchanged lines hidden (view full) ---

188 entry_type = "separator",
189 name = function()
190 return "Options:";
191 end
192 },
193
194 -- kernel options
195 {
43
44--loader menu tree:
45--rooted at menu.welcome
46--submenu declarations:
47local boot_options;
48local welcome;
49
50menu.boot_options = {

--- 137 unchanged lines hidden (view full) ---

188 entry_type = "separator",
189 name = function()
190 return "Options:";
191 end
192 },
193
194 -- kernel options
195 {
196 entry_type = "entry",
197 name = function()
198 local kernels = core.kernelList();
199 if #kernels == 0 then
196 entry_type = "carousel_entry",
197 carousel_id = "kernel",
198 items = core.kernelList,
199 name = function(idx, choice, all_choices)
200 if #all_choices == 0 then
200 return "Kernel: ";
201 end
202
203 local kernel_name = color.escapef(color.GREEN) ..
201 return "Kernel: ";
202 end
203
204 local kernel_name = color.escapef(color.GREEN) ..
204 kernels[current_kernel_index] .. color.default();
205 if (current_kernel_index == 1) then
205 choice .. color.default();
206 if (idx == 1) then
206 kernel_name = "default/" .. kernel_name;
207 end
208 return color.highlight("K").."ernel: " .. kernel_name ..
207 kernel_name = "default/" .. kernel_name;
208 end
209 return color.highlight("K").."ernel: " .. kernel_name ..
209 " (" .. current_kernel_index ..
210 " of " .. #kernels .. ")";
210 " (" .. idx ..
211 " of " .. #all_choices .. ")";
211 end,
212 end,
212 func = function()
213
214 -- dynamically build the kernel menu:
215 local kernels = core.kernelList();
216 -- Don't do anything if we don't have multiple kernels
217 if #kernels <= 1 then
218 return nil;
219 end
220 current_kernel_index = (current_kernel_index % #kernels)
221 + 1;
222 local current_kernel = kernels[current_kernel_index];
223 config.reload(current_kernel)
213 func = function(choice)
214 config.reload(choice);
224 end,
225 alias = {"k", "K"}
226 },
227
228 -- boot options
229 {
230 entry_type = "submenu",
231 name = function()
232 return "Boot "..color.highlight("O").."ptions";
233 end,
234 submenu = function()
235 return menu.boot_options;
236 end,
237 alias = {"o", "O"}
238 }
239
240};
241
215 end,
216 alias = {"k", "K"}
217 },
218
219 -- boot options
220 {
221 entry_type = "submenu",
222 name = function()
223 return "Boot "..color.highlight("O").."ptions";
224 end,
225 submenu = function()
226 return menu.boot_options;
227 end,
228 alias = {"o", "O"}
229 }
230
231};
232
233-- The first item in every carousel is always the default item.
234function menu.getCarouselIndex(id)
235 local val = carousel_choices[id];
236 if (val == nil) then
237 return 1;
238 end
239 return val;
240end
241
242function menu.setCarouselIndex(id, idx)
243 carousel_choices[id] = idx;
244end
245
242function menu.run(m)
243
244 if (menu.skip()) then
245 core.autoboot();
246 return false;
247 end
248
249 if (m == nil) then

--- 28 unchanged lines hidden (view full) ---

278 end
279 end
280
281 -- if we have an alias do the assigned action:
282 if(sel_entry ~= nil) then
283 if (sel_entry.entry_type == "entry") then
284 -- run function
285 sel_entry.func();
246function menu.run(m)
247
248 if (menu.skip()) then
249 core.autoboot();
250 return false;
251 end
252
253 if (m == nil) then

--- 28 unchanged lines hidden (view full) ---

282 end
283 end
284
285 -- if we have an alias do the assigned action:
286 if(sel_entry ~= nil) then
287 if (sel_entry.entry_type == "entry") then
288 -- run function
289 sel_entry.func();
290 elseif (sel_entry.entry_type == "carousel_entry") then
291 -- carousel (rotating) functionality
292 local carid = sel_entry.carousel_id;
293 local caridx = menu.getCarouselIndex(carid);
294 local choices = sel_entry.items();
295
296 caridx = (caridx % #choices) + 1;
297 menu.setCarouselIndex(carid, caridx);
298 sel_entry.func(choices[caridx]);
286 elseif (sel_entry.entry_type == "submenu") then
287 -- recurse
288 cont = menu.run(sel_entry.submenu());
289 elseif (sel_entry.entry_type == "return") then
290 -- break recurse
291 cont = false;
292 end
293 -- if we got an alias key the screen is out of date:

--- 84 unchanged lines hidden ---
299 elseif (sel_entry.entry_type == "submenu") then
300 -- recurse
301 cont = menu.run(sel_entry.submenu());
302 elseif (sel_entry.entry_type == "return") then
303 -- break recurse
304 cont = false;
305 end
306 -- if we got an alias key the screen is out of date:

--- 84 unchanged lines hidden ---