menu.lua (aedd6be5c7c3096828fafa6c1528f3966b9e3aa5) | menu.lua (9f71d421c89dde4e5a642f4555bcd20558fd91b0) |
---|---|
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: --- 27 unchanged lines hidden (view full) --- 36 37local menu = {} 38 39local skip 40local run 41local autoboot 42 43local OnOff = function(str, b) | 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: --- 27 unchanged lines hidden (view full) --- 36 37local menu = {} 38 39local skip 40local run 41local autoboot 42 43local OnOff = function(str, b) |
44 if (b) then | 44 if b then |
45 return str .. color.escapef(color.GREEN) .. "On" .. 46 color.escapef(color.WHITE) 47 else 48 return str .. color.escapef(color.RED) .. "off" .. 49 color.escapef(color.WHITE) 50 end 51end 52 --- 9 unchanged lines hidden (view full) --- 62 entry.func() 63 end, 64 [core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry) 65 -- carousel (rotating) functionality 66 local carid = entry.carousel_id 67 local caridx = config.getCarouselIndex(carid) 68 local choices = entry.items() 69 | 45 return str .. color.escapef(color.GREEN) .. "On" .. 46 color.escapef(color.WHITE) 47 else 48 return str .. color.escapef(color.RED) .. "off" .. 49 color.escapef(color.WHITE) 50 end 51end 52 --- 9 unchanged lines hidden (view full) --- 62 entry.func() 63 end, 64 [core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry) 65 -- carousel (rotating) functionality 66 local carid = entry.carousel_id 67 local caridx = config.getCarouselIndex(carid) 68 local choices = entry.items() 69 |
70 if (#choices > 0) then | 70 if #choices > 0 then |
71 caridx = (caridx % #choices) + 1 72 config.setCarouselIndex(carid, caridx) 73 entry.func(caridx, choices[caridx], choices) 74 end 75 end, 76 [core.MENU_SUBMENU] = function(current_menu, entry) 77 -- recurse 78 return menu.run(entry.submenu()) 79 end, 80 [core.MENU_RETURN] = function(current_menu, entry) 81 -- allow entry to have a function/side effect | 71 caridx = (caridx % #choices) + 1 72 config.setCarouselIndex(carid, caridx) 73 entry.func(caridx, choices[caridx], choices) 74 end 75 end, 76 [core.MENU_SUBMENU] = function(current_menu, entry) 77 -- recurse 78 return menu.run(entry.submenu()) 79 end, 80 [core.MENU_RETURN] = function(current_menu, entry) 81 -- allow entry to have a function/side effect |
82 if (entry.func ~= nil) then | 82 if entry.func ~= nil then |
83 entry.func() 84 end 85 return false 86 end, 87} 88-- loader menu tree is rooted at menu.welcome 89 90menu.boot_options = { --- 85 unchanged lines hidden (view full) --- 176 }, 177 }, 178} 179 180menu.welcome = { 181 entries = function() 182 local menu_entries = menu.welcome.all_entries 183 -- Swap the first two menu items on single user boot | 83 entry.func() 84 end 85 return false 86 end, 87} 88-- loader menu tree is rooted at menu.welcome 89 90menu.boot_options = { --- 85 unchanged lines hidden (view full) --- 176 }, 177 }, 178} 179 180menu.welcome = { 181 entries = function() 182 local menu_entries = menu.welcome.all_entries 183 -- Swap the first two menu items on single user boot |
184 if (core.isSingleUserBoot()) then | 184 if core.isSingleUserBoot() then |
185 -- We'll cache the swapped menu, for performance | 185 -- We'll cache the swapped menu, for performance |
186 if (menu.welcome.swapped_menu ~= nil) then | 186 if menu.welcome.swapped_menu ~= nil then |
187 return menu.welcome.swapped_menu 188 end 189 -- Shallow copy the table 190 menu_entries = core.shallowCopyTable(menu_entries) 191 192 -- Swap the first two menu entries 193 menu_entries[1], menu_entries[2] = 194 menu_entries[2], menu_entries[1] --- 87 unchanged lines hidden (view full) --- 282 }, 283 284 -- kernel options 285 { 286 entry_type = core.MENU_CAROUSEL_ENTRY, 287 carousel_id = "kernel", 288 items = core.kernelList, 289 name = function(idx, choice, all_choices) | 187 return menu.welcome.swapped_menu 188 end 189 -- Shallow copy the table 190 menu_entries = core.shallowCopyTable(menu_entries) 191 192 -- Swap the first two menu entries 193 menu_entries[1], menu_entries[2] = 194 menu_entries[2], menu_entries[1] --- 87 unchanged lines hidden (view full) --- 282 }, 283 284 -- kernel options 285 { 286 entry_type = core.MENU_CAROUSEL_ENTRY, 287 carousel_id = "kernel", 288 items = core.kernelList, 289 name = function(idx, choice, all_choices) |
290 if (#all_choices == 0) then | 290 if #all_choices == 0 then |
291 return "Kernel: " 292 end 293 294 local is_default = (idx == 1) 295 local kernel_name = "" 296 local name_color | 291 return "Kernel: " 292 end 293 294 local is_default = (idx == 1) 295 local kernel_name = "" 296 local name_color |
297 if (is_default) then | 297 if is_default then |
298 name_color = color.escapef(color.GREEN) 299 kernel_name = "default/" 300 else 301 name_color = color.escapef(color.BLUE) 302 end 303 kernel_name = kernel_name .. name_color .. 304 choice .. color.default() 305 return color.highlight("K") .. "ernel: " .. --- 18 unchanged lines hidden (view full) --- 324 end, 325 alias = {"o", "O"} 326 }, 327 }, 328} 329 330function menu.run(m) 331 | 298 name_color = color.escapef(color.GREEN) 299 kernel_name = "default/" 300 else 301 name_color = color.escapef(color.BLUE) 302 end 303 kernel_name = kernel_name .. name_color .. 304 choice .. color.default() 305 return color.highlight("K") .. "ernel: " .. --- 18 unchanged lines hidden (view full) --- 324 end, 325 alias = {"o", "O"} 326 }, 327 }, 328} 329 330function menu.run(m) 331 |
332 if (menu.skip()) then | 332 if menu.skip() then |
333 core.autoboot() 334 return false 335 end 336 | 333 core.autoboot() 334 return false 335 end 336 |
337 if (m == nil) then | 337 if m == nil then |
338 m = menu.welcome 339 end 340 341 -- redraw screen 342 screen.clear() 343 screen.defcursor() 344 local alias_table = drawer.drawscreen(m) 345 346 menu.autoboot() 347 348 cont = true | 338 m = menu.welcome 339 end 340 341 -- redraw screen 342 screen.clear() 343 screen.defcursor() 344 local alias_table = drawer.drawscreen(m) 345 346 menu.autoboot() 347 348 cont = true |
349 while (cont) do | 349 while cont do |
350 local key = io.getchar() 351 352 -- Special key behaviors | 350 local key = io.getchar() 351 352 -- Special key behaviors |
353 if ((key == core.KEY_BACKSPACE) or (key == core.KEY_DELETE)) and 354 (m ~= menu.welcome) then | 353 if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and 354 m ~= menu.welcome then |
355 break | 355 break |
356 elseif (key == core.KEY_ENTER) then | 356 elseif key == core.KEY_ENTER then |
357 core.boot() 358 -- Should not return 359 end 360 361 key = string.char(key) 362 -- check to see if key is an alias 363 local sel_entry = nil 364 for k, v in pairs(alias_table) do | 357 core.boot() 358 -- Should not return 359 end 360 361 key = string.char(key) 362 -- check to see if key is an alias 363 local sel_entry = nil 364 for k, v in pairs(alias_table) do |
365 if (key == k) then | 365 if key == k then |
366 sel_entry = v 367 end 368 end 369 370 -- if we have an alias do the assigned action: | 366 sel_entry = v 367 end 368 end 369 370 -- if we have an alias do the assigned action: |
371 if (sel_entry ~= nil) then | 371 if sel_entry ~= nil then |
372 -- Get menu handler 373 local handler = menu.handlers[sel_entry.entry_type] | 372 -- Get menu handler 373 local handler = menu.handlers[sel_entry.entry_type] |
374 if (handler ~= nil) then | 374 if handler ~= nil then |
375 -- The handler's return value indicates whether 376 -- we need to exit this menu. An omitted return 377 -- value means "continue" by default. 378 cont = handler(m, sel_entry) | 375 -- The handler's return value indicates whether 376 -- we need to exit this menu. An omitted return 377 -- value means "continue" by default. 378 cont = handler(m, sel_entry) |
379 if (cont == nil) then | 379 if cont == nil then |
380 cont = true 381 end 382 end 383 -- if we got an alias key the screen is out of date: 384 screen.clear() 385 screen.defcursor() 386 alias_table = drawer.drawscreen(m) 387 end 388 end 389 | 380 cont = true 381 end 382 end 383 -- if we got an alias key the screen is out of date: 384 screen.clear() 385 screen.defcursor() 386 alias_table = drawer.drawscreen(m) 387 end 388 end 389 |
390 if (m == menu.welcome) then | 390 if m == menu.welcome then |
391 screen.defcursor() 392 print("Exiting menu!") 393 return false 394 end 395 396 return true 397end 398 399function menu.skip() | 391 screen.defcursor() 392 print("Exiting menu!") 393 return false 394 end 395 396 return true 397end 398 399function menu.skip() |
400 if (core.isSerialBoot()) then | 400 if core.isSerialBoot() then |
401 return true 402 end 403 local c = string.lower(loader.getenv("console") or "") | 401 return true 402 end 403 local c = string.lower(loader.getenv("console") or "") |
404 if ((c:match("^efi[ ;]") or c:match("[ ;]efi[ ;]")) ~= nil) then | 404 if c:match("^efi[ ;]") ~= nil or c:match("[ ;]efi[ ;]") ~= nil then |
405 return true 406 end 407 408 c = string.lower(loader.getenv("beastie_disable") or "") 409 print("beastie_disable", c) 410 return c == "yes" 411end 412 413function menu.autoboot() | 405 return true 406 end 407 408 c = string.lower(loader.getenv("beastie_disable") or "") 409 print("beastie_disable", c) 410 return c == "yes" 411end 412 413function menu.autoboot() |
414 if (menu.already_autoboot == true) then | 414 if menu.already_autoboot == true then |
415 return 416 end 417 menu.already_autoboot = true 418 419 local ab = loader.getenv("autoboot_delay") | 415 return 416 end 417 menu.already_autoboot = true 418 419 local ab = loader.getenv("autoboot_delay") |
420 if (ab ~= nil) and (ab:lower() == "no") then | 420 if ab ~= nil and ab:lower() == "no" then |
421 return | 421 return |
422 elseif (tonumber(ab) == -1) then | 422 elseif tonumber(ab) == -1 then |
423 core.boot() 424 end 425 ab = tonumber(ab) or 10 426 427 local x = loader.getenv("loader_menu_timeout_x") or 5 428 local y = loader.getenv("loader_menu_timeout_y") or 22 429 430 local endtime = loader.time() + ab 431 local time 432 433 repeat 434 time = endtime - loader.time() 435 screen.setcursor(x, y) 436 print("Autoboot in " .. time .. 437 " seconds, hit [Enter] to boot" .. 438 " or any other key to stop ") 439 screen.defcursor() | 423 core.boot() 424 end 425 ab = tonumber(ab) or 10 426 427 local x = loader.getenv("loader_menu_timeout_x") or 5 428 local y = loader.getenv("loader_menu_timeout_y") or 22 429 430 local endtime = loader.time() + ab 431 local time 432 433 repeat 434 time = endtime - loader.time() 435 screen.setcursor(x, y) 436 print("Autoboot in " .. time .. 437 " seconds, hit [Enter] to boot" .. 438 " or any other key to stop ") 439 screen.defcursor() |
440 if (io.ischar()) then | 440 if io.ischar() then |
441 local ch = io.getchar() | 441 local ch = io.getchar() |
442 if (ch == core.KEY_ENTER) then | 442 if ch == core.KEY_ENTER then |
443 break 444 else 445 -- erase autoboot msg 446 screen.setcursor(0, y) 447 print(" " 448 .. " ") 449 screen.defcursor() 450 return 451 end 452 end 453 454 loader.delay(50000) 455 until time <= 0 456 core.boot() 457 458end 459 460return menu | 443 break 444 else 445 -- erase autoboot msg 446 screen.setcursor(0, y) 447 print(" " 448 .. " ") 449 screen.defcursor() 450 return 451 end 452 end 453 454 loader.delay(50000) 455 until time <= 0 456 core.boot() 457 458end 459 460return menu |