menu.lua (4b6da14cfa1ee9b815f80ca8077839f65bb6b3be) | menu.lua (8d415029e18f7364a1f05208031384fca6cade8d) |
---|---|
1-- 2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org> 4-- All rights reserved. 5-- 6-- Redistribution and use in source and binary forms, with or without 7-- modification, are permitted provided that the following conditions 8-- are met: --- 28 unchanged lines hidden (view full) --- 37local menu = {}; 38 39local OnOff; 40local skip; 41local run; 42local autoboot; 43local carousel_choices = {}; 44 | 1-- 2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org> 4-- All rights reserved. 5-- 6-- Redistribution and use in source and binary forms, with or without 7-- modification, are permitted provided that the following conditions 8-- are met: --- 28 unchanged lines hidden (view full) --- 37local menu = {}; 38 39local OnOff; 40local skip; 41local run; 42local autoboot; 43local carousel_choices = {}; 44 |
45menu.handlers = { 46 -- Menu handlers take the current menu and selected entry as parameters, 47 -- and should return a boolean indicating whether execution should 48 -- continue or not. The return value may be omitted if this entry should 49 -- have no bearing on whether we continue or not, indicating that we 50 -- should just continue after execution. 51 [core.MENU_ENTRY] = function(current_menu, entry) 52 -- run function 53 entry.func(); 54 end, 55 [core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry) 56 -- carousel (rotating) functionality 57 local carid = entry.carousel_id; 58 local caridx = menu.getCarouselIndex(carid); 59 local choices = entry.items(); 60 61 if (#choices > 0) then 62 caridx = (caridx % #choices) + 1; 63 menu.setCarouselIndex(carid, caridx); 64 entry.func(caridx, choices[caridx], choices); 65 end 66 end, 67 [core.MENU_SUBMENU] = function(current_menu, entry) 68 -- recurse 69 return menu.run(entry.submenu()); 70 end, 71 [core.MENU_RETURN] = function(current_menu, entry) 72 -- allow entry to have a function/side effect 73 if (entry.func ~= nil) then 74 entry.func(); 75 end 76 return false; 77 end, 78}; |
|
45-- loader menu tree is rooted at menu.welcome 46 47menu.boot_options = { 48 entries = { 49 -- return to welcome menu 50 { 51 entry_type = core.MENU_RETURN, 52 name = function() --- 280 unchanged lines hidden (view full) --- 333 for k, v in pairs(alias_table) do 334 if (key == k) then 335 sel_entry = v; 336 end 337 end 338 339 -- if we have an alias do the assigned action: 340 if (sel_entry ~= nil) then | 79-- loader menu tree is rooted at menu.welcome 80 81menu.boot_options = { 82 entries = { 83 -- return to welcome menu 84 { 85 entry_type = core.MENU_RETURN, 86 name = function() --- 280 unchanged lines hidden (view full) --- 367 for k, v in pairs(alias_table) do 368 if (key == k) then 369 sel_entry = v; 370 end 371 end 372 373 -- if we have an alias do the assigned action: 374 if (sel_entry ~= nil) then |
341 if (sel_entry.entry_type == core.MENU_ENTRY) then 342 -- run function 343 sel_entry.func(); 344 elseif (sel_entry.entry_type == core.MENU_CAROUSEL_ENTRY) then 345 -- carousel (rotating) functionality 346 local carid = sel_entry.carousel_id; 347 local caridx = menu.getCarouselIndex(carid); 348 local choices = sel_entry.items(); 349 350 if (#choices > 0) then 351 caridx = (caridx % #choices) + 1; 352 menu.setCarouselIndex(carid, caridx); 353 sel_entry.func(caridx, choices[caridx], 354 choices); | 375 -- Get menu handler 376 local handler = menu.handlers[sel_entry.entry_type]; 377 if (handler ~= nil) then 378 -- The handler's return value indicates whether 379 -- we need to exit this menu. An omitted return 380 -- value means "continue" by default. 381 cont = handler(m, sel_entry); 382 if (cont == nil) then 383 cont = true; |
355 end | 384 end |
356 elseif (sel_entry.entry_type == core.MENU_SUBMENU) then 357 -- recurse 358 cont = menu.run(sel_entry.submenu()); 359 elseif (sel_entry.entry_type == core.MENU_RETURN) then 360 -- allow entry to have a function/side effect 361 if (sel_entry.func ~= nil) then 362 sel_entry.func(); 363 end 364 -- break recurse 365 cont = false; | |
366 end 367 -- if we got an alias key the screen is out of date: 368 screen.clear(); 369 screen.defcursor(); 370 alias_table = drawer.drawscreen(m); 371 end 372 end 373 --- 82 unchanged lines hidden --- | 385 end 386 -- if we got an alias key the screen is out of date: 387 screen.clear(); 388 screen.defcursor(); 389 alias_table = drawer.drawscreen(m); 390 end 391 end 392 --- 82 unchanged lines hidden --- |