menu.lua (3cd5547b1bc3b7c277359ec3c1e8a7baa6d365d4) menu.lua (da9ab8270644340e074bd10a09a2fb50fcbac8fa)
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

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

76 if #choices > 0 then
77 caridx = (caridx % #choices) + 1
78 config.setCarouselIndex(carid, caridx)
79 entry.func(caridx, choices[caridx], choices)
80 end
81 end,
82 [core.MENU_SUBMENU] = function(_, entry)
83 -- recurse
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

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

76 if #choices > 0 then
77 caridx = (caridx % #choices) + 1
78 config.setCarouselIndex(carid, caridx)
79 entry.func(caridx, choices[caridx], choices)
80 end
81 end,
82 [core.MENU_SUBMENU] = function(_, entry)
83 -- recurse
84 return menu.run(entry.submenu)
84 menu.process(entry.submenu)
85 end,
86 [core.MENU_RETURN] = function(_, entry)
87 -- allow entry to have a function/side effect
88 if entry.func ~= nil then
89 entry.func()
90 end
91 return false
92 end,

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

337 submenu = menu.boot_environments,
338 alias = {"e", "E"},
339 },
340 },
341}
342
343menu.default = menu.welcome
344
85 end,
86 [core.MENU_RETURN] = function(_, entry)
87 -- allow entry to have a function/side effect
88 if entry.func ~= nil then
89 entry.func()
90 end
91 return false
92 end,

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

337 submenu = menu.boot_environments,
338 alias = {"e", "E"},
339 },
340 },
341}
342
343menu.default = menu.welcome
344
345function menu.run(m)
346
347 if menu.skip() then
348 core.autoboot()
349 return false
350 end
351
352 if m == nil then
353 m = menu.default
354 end
355
345function menu.process(m)
346 assert(m ~= nil)
356 -- redraw screen
357 screen.clear()
358 screen.defcursor()
359 local alias_table = drawer.drawscreen(m)
360
347 -- redraw screen
348 screen.clear()
349 screen.defcursor()
350 local alias_table = drawer.drawscreen(m)
351
361 -- Might return nil, that's ok
352 -- autoboot processing likely belongs better in menu.run, but we want
353 -- to draw the menu once before we do any autoboot prompting. We also
354 -- collect the alias table from the drawer, which generates the table
355 -- based on all of the 'alias' entries along with effective line numbers
356 -- that each entry is drawn at. This makes it cleaner to handle here,
357 -- for the time being.
362 local autoboot_key;
363 if m == menu.default then
364 autoboot_key = menu.autoboot()
365 end
358 local autoboot_key;
359 if m == menu.default then
360 autoboot_key = menu.autoboot()
361 end
366 local cont = true
367 while cont do
362 while true do
368 local key = autoboot_key or io.getchar()
369 autoboot_key = nil
370
371 -- Special key behaviors
372 if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and
373 m ~= menu.default then
374 break
375 elseif key == core.KEY_ENTER then

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

386 end
387 end
388
389 -- if we have an alias do the assigned action:
390 if sel_entry ~= nil then
391 -- Get menu handler
392 local handler = menu.handlers[sel_entry.entry_type]
393 if handler ~= nil then
363 local key = autoboot_key or io.getchar()
364 autoboot_key = nil
365
366 -- Special key behaviors
367 if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and
368 m ~= menu.default then
369 break
370 elseif key == core.KEY_ENTER then

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

381 end
382 end
383
384 -- if we have an alias do the assigned action:
385 if sel_entry ~= nil then
386 -- Get menu handler
387 local handler = menu.handlers[sel_entry.entry_type]
388 if handler ~= nil then
394 -- The handler's return value indicates whether
395 -- we need to exit this menu. An omitted return
396 -- value means "continue" by default.
397 cont = handler(m, sel_entry)
398 if cont == nil then
399 cont = true
389 -- The handler's return value indicates if we
390 -- need to exit this menu. An omitted or true
391 -- return value means to continue.
392 if handler(m, sel_entry) == false then
393 return
400 end
401 end
402 -- if we got an alias key the screen is out of date:
403 screen.clear()
404 screen.defcursor()
405 alias_table = drawer.drawscreen(m)
406 end
407 end
394 end
395 end
396 -- if we got an alias key the screen is out of date:
397 screen.clear()
398 screen.defcursor()
399 alias_table = drawer.drawscreen(m)
400 end
401 end
402end
408
403
409 if m == menu.default then
410 screen.defcursor()
411 print("Exiting menu!")
412 return false
404function menu.run()
405 if menu.skip() then
406 core.autoboot()
407 return
413 end
414
408 end
409
415 return true
410 menu.process(menu.default)
411
412 screen.defcursor()
413 print("Exiting menu!")
416end
417
418function menu.skip()
419 if core.isSerialBoot() then
420 return true
421 end
422 local c = string.lower(loader.getenv("console") or "")
423 if c:match("^efi[ ;]") ~= nil or c:match("[ ;]efi[ ;]") ~= nil then

--- 50 unchanged lines hidden ---
414end
415
416function menu.skip()
417 if core.isSerialBoot() then
418 return true
419 end
420 local c = string.lower(loader.getenv("console") or "")
421 if c:match("^efi[ ;]") ~= nil or c:match("[ ;]efi[ ;]") ~= nil then

--- 50 unchanged lines hidden ---