1088b4f5fSWarner Losh-- 2088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 321d5bcbeSKyle Evans-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org> 4088b4f5fSWarner Losh-- All rights reserved. 5088b4f5fSWarner Losh-- 6088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 7088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 8088b4f5fSWarner Losh-- are met: 9088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 10088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 11088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 12088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 13088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 14088b4f5fSWarner Losh-- 15088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25088b4f5fSWarner Losh-- SUCH DAMAGE. 26088b4f5fSWarner Losh-- 27088b4f5fSWarner Losh-- $FreeBSD$ 28088b4f5fSWarner Losh-- 29088b4f5fSWarner Losh 30088b4f5fSWarner Losh 31088b4f5fSWarner Loshlocal core = require("core"); 32088b4f5fSWarner Loshlocal color = require("color"); 33088b4f5fSWarner Loshlocal config = require("config"); 34088b4f5fSWarner Loshlocal screen = require("screen"); 35088b4f5fSWarner Loshlocal drawer = require("drawer"); 36088b4f5fSWarner Losh 37c8518398SKyle Evanslocal menu = {}; 38c8518398SKyle Evans 39088b4f5fSWarner Loshlocal skip; 40088b4f5fSWarner Loshlocal run; 41088b4f5fSWarner Loshlocal autoboot; 42088b4f5fSWarner Losh 43e15abd1fSKyle Evanslocal OnOff = function(str, b) 44e15abd1fSKyle Evans if (b) then 45e15abd1fSKyle Evans return str .. color.escapef(color.GREEN) .. "On" .. 46e15abd1fSKyle Evans color.escapef(color.WHITE); 47e15abd1fSKyle Evans else 48e15abd1fSKyle Evans return str .. color.escapef(color.RED) .. "off" .. 49e15abd1fSKyle Evans color.escapef(color.WHITE); 50e15abd1fSKyle Evans end 51e15abd1fSKyle Evansend 52e15abd1fSKyle Evans 53b5746545SKyle Evans-- Module exports 548d415029SKyle Evansmenu.handlers = { 558d415029SKyle Evans -- Menu handlers take the current menu and selected entry as parameters, 568d415029SKyle Evans -- and should return a boolean indicating whether execution should 578d415029SKyle Evans -- continue or not. The return value may be omitted if this entry should 588d415029SKyle Evans -- have no bearing on whether we continue or not, indicating that we 598d415029SKyle Evans -- should just continue after execution. 608d415029SKyle Evans [core.MENU_ENTRY] = function(current_menu, entry) 618d415029SKyle Evans -- run function 628d415029SKyle Evans entry.func(); 638d415029SKyle Evans end, 648d415029SKyle Evans [core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry) 658d415029SKyle Evans -- carousel (rotating) functionality 668d415029SKyle Evans local carid = entry.carousel_id; 6725c4c7a5SKyle Evans local caridx = config.getCarouselIndex(carid); 688d415029SKyle Evans local choices = entry.items(); 698d415029SKyle Evans 708d415029SKyle Evans if (#choices > 0) then 718d415029SKyle Evans caridx = (caridx % #choices) + 1; 7225c4c7a5SKyle Evans config.setCarouselIndex(carid, caridx); 738d415029SKyle Evans entry.func(caridx, choices[caridx], choices); 748d415029SKyle Evans end 758d415029SKyle Evans end, 768d415029SKyle Evans [core.MENU_SUBMENU] = function(current_menu, entry) 778d415029SKyle Evans -- recurse 788d415029SKyle Evans return menu.run(entry.submenu()); 798d415029SKyle Evans end, 808d415029SKyle Evans [core.MENU_RETURN] = function(current_menu, entry) 818d415029SKyle Evans -- allow entry to have a function/side effect 828d415029SKyle Evans if (entry.func ~= nil) then 838d415029SKyle Evans entry.func(); 848d415029SKyle Evans end 858d415029SKyle Evans return false; 868d415029SKyle Evans end, 878d415029SKyle Evans}; 88280e990bSKyle Evans-- loader menu tree is rooted at menu.welcome 89088b4f5fSWarner Losh 90088b4f5fSWarner Loshmenu.boot_options = { 91d8757746SKyle Evans entries = { 92088b4f5fSWarner Losh -- return to welcome menu 93088b4f5fSWarner Losh { 94a7cf0562SKyle Evans entry_type = core.MENU_RETURN, 95088b4f5fSWarner Losh name = function() 9657099121SKyle Evans return "Back to main menu" .. 9757099121SKyle Evans color.highlight(" [Backspace]"); 981666dfc0SKyle Evans end 99088b4f5fSWarner Losh }, 100088b4f5fSWarner Losh 101088b4f5fSWarner Losh -- load defaults 102088b4f5fSWarner Losh { 103a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 104088b4f5fSWarner Losh name = function() 10557099121SKyle Evans return "Load System " .. color.highlight("D") .. 10657099121SKyle Evans "efaults"; 107088b4f5fSWarner Losh end, 108088b4f5fSWarner Losh func = function() 10924a1bd54SKyle Evans core.setDefaults(); 110088b4f5fSWarner Losh end, 111088b4f5fSWarner Losh alias = {"d", "D"} 112088b4f5fSWarner Losh }, 113088b4f5fSWarner Losh 114088b4f5fSWarner Losh { 115a7cf0562SKyle Evans entry_type = core.MENU_SEPARATOR, 116088b4f5fSWarner Losh name = function() 117088b4f5fSWarner Losh return ""; 118088b4f5fSWarner Losh end 119088b4f5fSWarner Losh }, 120088b4f5fSWarner Losh 121088b4f5fSWarner Losh { 122a7cf0562SKyle Evans entry_type = core.MENU_SEPARATOR, 123088b4f5fSWarner Losh name = function() 124088b4f5fSWarner Losh return "Boot Options:"; 125088b4f5fSWarner Losh end 126088b4f5fSWarner Losh }, 127088b4f5fSWarner Losh 128088b4f5fSWarner Losh -- acpi 129088b4f5fSWarner Losh { 130a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 131*c1ab36f5SKyle Evans visible = core.isSystem386, 132088b4f5fSWarner Losh name = function() 133fd2b19b3SKyle Evans return OnOff(color.highlight("A") .. 134fd2b19b3SKyle Evans "CPI :", core.acpi); 135088b4f5fSWarner Losh end, 136088b4f5fSWarner Losh func = function() 137088b4f5fSWarner Losh core.setACPI(); 138088b4f5fSWarner Losh end, 139088b4f5fSWarner Losh alias = {"a", "A"} 140088b4f5fSWarner Losh }, 141088b4f5fSWarner Losh -- safe mode 142088b4f5fSWarner Losh { 143a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 144088b4f5fSWarner Losh name = function() 14557099121SKyle Evans return OnOff("Safe " .. color.highlight("M") .. 14657099121SKyle Evans "ode :", core.sm); 147088b4f5fSWarner Losh end, 148088b4f5fSWarner Losh func = function() 149088b4f5fSWarner Losh core.setSafeMode(); 150088b4f5fSWarner Losh end, 151088b4f5fSWarner Losh alias = {"m", "M"} 152088b4f5fSWarner Losh }, 153088b4f5fSWarner Losh -- single user 154088b4f5fSWarner Losh { 155a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 156088b4f5fSWarner Losh name = function() 157fd2b19b3SKyle Evans return OnOff(color.highlight("S") .. 158fd2b19b3SKyle Evans "ingle user:", core.su); 159088b4f5fSWarner Losh end, 160088b4f5fSWarner Losh func = function() 161088b4f5fSWarner Losh core.setSingleUser(); 162088b4f5fSWarner Losh end, 163088b4f5fSWarner Losh alias = {"s", "S"} 164088b4f5fSWarner Losh }, 165088b4f5fSWarner Losh -- verbose boot 166088b4f5fSWarner Losh { 167a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 168088b4f5fSWarner Losh name = function() 169fd2b19b3SKyle Evans return OnOff(color.highlight("V") .. 170fd2b19b3SKyle Evans "erbose :", core.verbose); 171088b4f5fSWarner Losh end, 172088b4f5fSWarner Losh func = function() 173088b4f5fSWarner Losh core.setVerbose(); 174088b4f5fSWarner Losh end, 175088b4f5fSWarner Losh alias = {"v", "V"} 176088b4f5fSWarner Losh }, 177d8757746SKyle Evans }, 178088b4f5fSWarner Losh}; 179088b4f5fSWarner Losh 180088b4f5fSWarner Loshmenu.welcome = { 181303253e5SKyle Evans entries = function() 182303253e5SKyle Evans local menu_entries = menu.welcome.all_entries; 183303253e5SKyle Evans -- Swap the first two menu items on single user boot 184303253e5SKyle Evans if (core.isSingleUserBoot()) then 1859a0904b0SKyle Evans -- We'll cache the swapped menu, for performance 1869a0904b0SKyle Evans if (menu.welcome.swapped_menu ~= nil) then 1879a0904b0SKyle Evans return menu.welcome.swapped_menu; 1889a0904b0SKyle Evans end 1895c1b5165SKyle Evans -- Shallow copy the table 1905c1b5165SKyle Evans menu_entries = core.shallowCopyTable(menu_entries); 1915c1b5165SKyle Evans 1929a0904b0SKyle Evans -- Swap the first two menu entries 1934b6da14cSKyle Evans menu_entries[1], menu_entries[2] = 1944b6da14cSKyle Evans menu_entries[2], menu_entries[1]; 195303253e5SKyle Evans 1969a0904b0SKyle Evans -- Then set their names to their alternate names 1979a0904b0SKyle Evans menu_entries[1].name, menu_entries[2].name = 1989a0904b0SKyle Evans menu_entries[1].alternate_name, 1999a0904b0SKyle Evans menu_entries[2].alternate_name; 2009a0904b0SKyle Evans menu.welcome.swapped_menu = menu_entries; 201303253e5SKyle Evans end 202303253e5SKyle Evans return menu_entries; 203303253e5SKyle Evans end, 204303253e5SKyle Evans all_entries = { 205088b4f5fSWarner Losh -- boot multi user 206088b4f5fSWarner Losh { 207a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 208088b4f5fSWarner Losh name = function() 209fd2b19b3SKyle Evans return color.highlight("B") .. 210fd2b19b3SKyle Evans "oot Multi user " .. 21157099121SKyle Evans color.highlight("[Enter]"); 212088b4f5fSWarner Losh end, 2135c1b5165SKyle Evans -- Not a standard menu entry function! 2145c1b5165SKyle Evans alternate_name = function() 2155c1b5165SKyle Evans return color.highlight("B") .. 2165c1b5165SKyle Evans "oot Multi user"; 2175c1b5165SKyle Evans end, 218088b4f5fSWarner Losh func = function() 219088b4f5fSWarner Losh core.setSingleUser(false); 220088b4f5fSWarner Losh core.boot(); 221088b4f5fSWarner Losh end, 222b458bf0dSKyle Evans alias = {"b", "B"} 223088b4f5fSWarner Losh }, 224088b4f5fSWarner Losh 225088b4f5fSWarner Losh -- boot single user 226088b4f5fSWarner Losh { 227a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 228088b4f5fSWarner Losh name = function() 229fd2b19b3SKyle Evans return "Boot " .. color.highlight("S") .. 230fd2b19b3SKyle Evans "ingle user"; 231088b4f5fSWarner Losh end, 2325c1b5165SKyle Evans -- Not a standard menu entry function! 2335c1b5165SKyle Evans alternate_name = function() 2345c1b5165SKyle Evans return "Boot " .. color.highlight("S") .. 2355c1b5165SKyle Evans "ingle user " .. color.highlight("[Enter]"); 2365c1b5165SKyle Evans end, 237088b4f5fSWarner Losh func = function() 238088b4f5fSWarner Losh core.setSingleUser(true); 239088b4f5fSWarner Losh core.boot(); 240088b4f5fSWarner Losh end, 241088b4f5fSWarner Losh alias = {"s", "S"} 242088b4f5fSWarner Losh }, 243088b4f5fSWarner Losh 244088b4f5fSWarner Losh -- escape to interpreter 245088b4f5fSWarner Losh { 246a7cf0562SKyle Evans entry_type = core.MENU_RETURN, 247088b4f5fSWarner Losh name = function() 248fd2b19b3SKyle Evans return color.highlight("Esc") .. 249fd2b19b3SKyle Evans "ape to loader prompt"; 250088b4f5fSWarner Losh end, 251ef625845SKyle Evans func = function() 25224a1bd54SKyle Evans loader.setenv("autoboot_delay", "NO"); 253ef625845SKyle Evans end, 25439006570SKyle Evans alias = {core.KEYSTR_ESCAPE} 255088b4f5fSWarner Losh }, 256088b4f5fSWarner Losh 257088b4f5fSWarner Losh -- reboot 258088b4f5fSWarner Losh { 259a7cf0562SKyle Evans entry_type = core.MENU_ENTRY, 260088b4f5fSWarner Losh name = function() 261088b4f5fSWarner Losh return color.highlight("R") .. "eboot"; 262088b4f5fSWarner Losh end, 263088b4f5fSWarner Losh func = function() 264088b4f5fSWarner Losh loader.perform("reboot"); 265088b4f5fSWarner Losh end, 266088b4f5fSWarner Losh alias = {"r", "R"} 267088b4f5fSWarner Losh }, 268088b4f5fSWarner Losh 269088b4f5fSWarner Losh 270088b4f5fSWarner Losh { 271a7cf0562SKyle Evans entry_type = core.MENU_SEPARATOR, 272088b4f5fSWarner Losh name = function() 273088b4f5fSWarner Losh return ""; 274088b4f5fSWarner Losh end 275088b4f5fSWarner Losh }, 276088b4f5fSWarner Losh 277088b4f5fSWarner Losh { 278a7cf0562SKyle Evans entry_type = core.MENU_SEPARATOR, 279088b4f5fSWarner Losh name = function() 280088b4f5fSWarner Losh return "Options:"; 281088b4f5fSWarner Losh end 282088b4f5fSWarner Losh }, 283088b4f5fSWarner Losh 284088b4f5fSWarner Losh -- kernel options 285088b4f5fSWarner Losh { 286a7cf0562SKyle Evans entry_type = core.MENU_CAROUSEL_ENTRY, 287ada26c4aSKyle Evans carousel_id = "kernel", 288ada26c4aSKyle Evans items = core.kernelList, 289ada26c4aSKyle Evans name = function(idx, choice, all_choices) 29024a1bd54SKyle Evans if (#all_choices == 0) then 291b1b1f2b8SKyle Evans return "Kernel: "; 292088b4f5fSWarner Losh end 293b1b1f2b8SKyle Evans 294bcf48a15SKyle Evans local is_default = (idx == 1); 295bcf48a15SKyle Evans local kernel_name = ""; 296bcf48a15SKyle Evans local name_color; 29724a1bd54SKyle Evans if (is_default) then 298bcf48a15SKyle Evans name_color = color.escapef(color.GREEN); 299bcf48a15SKyle Evans kernel_name = "default/"; 300bcf48a15SKyle Evans else 301bcf48a15SKyle Evans name_color = color.escapef(color.BLUE); 302b1b1f2b8SKyle Evans end 303fd2b19b3SKyle Evans kernel_name = kernel_name .. name_color .. 304fd2b19b3SKyle Evans choice .. color.default(); 305fd2b19b3SKyle Evans return color.highlight("K") .. "ernel: " .. 306fd2b19b3SKyle Evans kernel_name .. " (" .. idx .. " of " .. 307fd2b19b3SKyle Evans #all_choices .. ")"; 308088b4f5fSWarner Losh end, 3095d1e2f83SKyle Evans func = function(idx, choice, all_choices) 310fa4a2394SKyle Evans config.selectkernel(choice); 311088b4f5fSWarner Losh end, 312088b4f5fSWarner Losh alias = {"k", "K"} 313088b4f5fSWarner Losh }, 314088b4f5fSWarner Losh 315088b4f5fSWarner Losh -- boot options 316088b4f5fSWarner Losh { 317a7cf0562SKyle Evans entry_type = core.MENU_SUBMENU, 318088b4f5fSWarner Losh name = function() 319fd2b19b3SKyle Evans return "Boot " .. color.highlight("O") .. 320fd2b19b3SKyle Evans "ptions"; 321088b4f5fSWarner Losh end, 322088b4f5fSWarner Losh submenu = function() 323088b4f5fSWarner Losh return menu.boot_options; 324088b4f5fSWarner Losh end, 325088b4f5fSWarner Losh alias = {"o", "O"} 326d8757746SKyle Evans }, 327d8757746SKyle Evans }, 328088b4f5fSWarner Losh}; 329088b4f5fSWarner Losh 330088b4f5fSWarner Loshfunction menu.run(m) 331088b4f5fSWarner Losh 332088b4f5fSWarner Losh if (menu.skip()) then 333088b4f5fSWarner Losh core.autoboot(); 334088b4f5fSWarner Losh return false; 335088b4f5fSWarner Losh end 336088b4f5fSWarner Losh 337088b4f5fSWarner Losh if (m == nil) then 338088b4f5fSWarner Losh m = menu.welcome; 339088b4f5fSWarner Losh end 340088b4f5fSWarner Losh 341088b4f5fSWarner Losh -- redraw screen 342088b4f5fSWarner Losh screen.clear(); 343088b4f5fSWarner Losh screen.defcursor(); 344088b4f5fSWarner Losh local alias_table = drawer.drawscreen(m); 345088b4f5fSWarner Losh 3463a0a07d0SKyle Evans menu.autoboot(); 347088b4f5fSWarner Losh 348088b4f5fSWarner Losh cont = true; 34924a1bd54SKyle Evans while (cont) do 350abc4f7e7SKyle Evans local key = io.getchar(); 351088b4f5fSWarner Losh 352b458bf0dSKyle Evans -- Special key behaviors 3531504bce3SKyle Evans if ((key == core.KEY_BACKSPACE) or (key == core.KEY_DELETE)) and 3541504bce3SKyle Evans (m ~= menu.welcome) then 3551f5696c7SKyle Evans break; 356fe672a15SKyle Evans elseif (key == core.KEY_ENTER) then 357b458bf0dSKyle Evans core.boot(); 358b458bf0dSKyle Evans -- Should not return 359abc4f7e7SKyle Evans end 360abc4f7e7SKyle Evans 361abc4f7e7SKyle Evans key = string.char(key) 362088b4f5fSWarner Losh -- check to see if key is an alias 363088b4f5fSWarner Losh local sel_entry = nil; 364088b4f5fSWarner Losh for k, v in pairs(alias_table) do 365088b4f5fSWarner Losh if (key == k) then 366088b4f5fSWarner Losh sel_entry = v; 367088b4f5fSWarner Losh end 368088b4f5fSWarner Losh end 369088b4f5fSWarner Losh 370088b4f5fSWarner Losh -- if we have an alias do the assigned action: 371088b4f5fSWarner Losh if (sel_entry ~= nil) then 3728d415029SKyle Evans -- Get menu handler 3738d415029SKyle Evans local handler = menu.handlers[sel_entry.entry_type]; 3748d415029SKyle Evans if (handler ~= nil) then 3758d415029SKyle Evans -- The handler's return value indicates whether 3768d415029SKyle Evans -- we need to exit this menu. An omitted return 3778d415029SKyle Evans -- value means "continue" by default. 3788d415029SKyle Evans cont = handler(m, sel_entry); 3798d415029SKyle Evans if (cont == nil) then 3808d415029SKyle Evans cont = true; 381aefcaa7eSKyle Evans end 382088b4f5fSWarner Losh end 383088b4f5fSWarner Losh -- if we got an alias key the screen is out of date: 384088b4f5fSWarner Losh screen.clear(); 385088b4f5fSWarner Losh screen.defcursor(); 386088b4f5fSWarner Losh alias_table = drawer.drawscreen(m); 387088b4f5fSWarner Losh end 388088b4f5fSWarner Losh end 389088b4f5fSWarner Losh 390088b4f5fSWarner Losh if (m == menu.welcome) then 391088b4f5fSWarner Losh screen.defcursor(); 392088b4f5fSWarner Losh print("Exiting menu!"); 393fa4a2394SKyle Evans config.loadelf(); 394088b4f5fSWarner Losh return false; 395088b4f5fSWarner Losh end 396088b4f5fSWarner Losh 397088b4f5fSWarner Losh return true; 398088b4f5fSWarner Loshend 399088b4f5fSWarner Losh 400088b4f5fSWarner Loshfunction menu.skip() 401b140d14bSKyle Evans if (core.isSerialBoot()) then 402088b4f5fSWarner Losh return true; 403088b4f5fSWarner Losh end 404088b4f5fSWarner Losh local c = string.lower(loader.getenv("console") or ""); 40524a1bd54SKyle Evans if ((c:match("^efi[ ;]") or c:match("[ ;]efi[ ;]")) ~= nil) then 406088b4f5fSWarner Losh return true; 407088b4f5fSWarner Losh end 408088b4f5fSWarner Losh 409088b4f5fSWarner Losh c = string.lower(loader.getenv("beastie_disable") or ""); 410088b4f5fSWarner Losh print("beastie_disable", c); 411088b4f5fSWarner Losh return c == "yes"; 412088b4f5fSWarner Loshend 413088b4f5fSWarner Losh 414088b4f5fSWarner Loshfunction menu.autoboot() 41524a1bd54SKyle Evans if (menu.already_autoboot == true) then 416088b4f5fSWarner Losh return; 417088b4f5fSWarner Losh end 418088b4f5fSWarner Losh menu.already_autoboot = true; 419088b4f5fSWarner Losh 420088b4f5fSWarner Losh local ab = loader.getenv("autoboot_delay"); 421702b460dSKyle Evans if (ab ~= nil) and (ab:lower() == "no") then 422702b460dSKyle Evans return; 423702b460dSKyle Evans elseif (tonumber(ab) == -1) then 424088b4f5fSWarner Losh core.boot(); 425088b4f5fSWarner Losh end 426088b4f5fSWarner Losh ab = tonumber(ab) or 10; 427088b4f5fSWarner Losh 428088b4f5fSWarner Losh local x = loader.getenv("loader_menu_timeout_x") or 5; 429088b4f5fSWarner Losh local y = loader.getenv("loader_menu_timeout_y") or 22; 430088b4f5fSWarner Losh 431088b4f5fSWarner Losh local endtime = loader.time() + ab; 432088b4f5fSWarner Losh local time; 433088b4f5fSWarner Losh 434088b4f5fSWarner Losh repeat 435088b4f5fSWarner Losh time = endtime - loader.time(); 436088b4f5fSWarner Losh screen.setcursor(x, y); 43757099121SKyle Evans print("Autoboot in " .. time .. 43857099121SKyle Evans " seconds, hit [Enter] to boot" .. 43957099121SKyle Evans " or any other key to stop "); 440088b4f5fSWarner Losh screen.defcursor(); 44124a1bd54SKyle Evans if (io.ischar()) then 442088b4f5fSWarner Losh local ch = io.getchar(); 44324a1bd54SKyle Evans if (ch == core.KEY_ENTER) then 444088b4f5fSWarner Losh break; 445088b4f5fSWarner Losh else 446088b4f5fSWarner Losh -- erase autoboot msg 447088b4f5fSWarner Losh screen.setcursor(0, y); 448088b4f5fSWarner Losh print(" " 449088b4f5fSWarner Losh .. " "); 450088b4f5fSWarner Losh screen.defcursor(); 451088b4f5fSWarner Losh return; 452088b4f5fSWarner Losh end 453088b4f5fSWarner Losh end 454088b4f5fSWarner Losh 455088b4f5fSWarner Losh loader.delay(50000); 4561f5696c7SKyle Evans until time <= 0; 457088b4f5fSWarner Losh core.boot(); 458088b4f5fSWarner Losh 459088b4f5fSWarner Loshend 460088b4f5fSWarner Losh 46124a1bd54SKyle Evansreturn menu; 462