2018-02-12 15:32:00 +00:00
|
|
|
--
|
2018-02-23 02:51:35 +00:00
|
|
|
-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
--
|
2018-02-12 15:32:00 +00:00
|
|
|
-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
|
2018-02-19 18:11:35 +00:00
|
|
|
-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org>
|
2018-02-12 15:32:00 +00:00
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- Redistribution and use in source and binary forms, with or without
|
|
|
|
-- modification, are permitted provided that the following conditions
|
|
|
|
-- are met:
|
|
|
|
-- 1. Redistributions of source code must retain the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer.
|
|
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer in the
|
|
|
|
-- documentation and/or other materials provided with the distribution.
|
|
|
|
--
|
|
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
-- SUCH DAMAGE.
|
|
|
|
--
|
|
|
|
-- $FreeBSD$
|
|
|
|
--
|
|
|
|
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local core = require("core")
|
|
|
|
local color = require("color")
|
|
|
|
local config = require("config")
|
|
|
|
local screen = require("screen")
|
|
|
|
local drawer = require("drawer")
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local menu = {}
|
2018-02-19 17:54:22 +00:00
|
|
|
|
2018-02-25 17:02:50 +00:00
|
|
|
local drawn_menu
|
2018-03-01 02:04:26 +00:00
|
|
|
local return_menu_entry = {
|
|
|
|
entry_type = core.MENU_RETURN,
|
|
|
|
name = "Back to main menu" .. color.highlight(" [Backspace]"),
|
|
|
|
}
|
2018-02-25 05:00:54 +00:00
|
|
|
|
2018-02-26 04:08:54 +00:00
|
|
|
local function OnOff(str, value)
|
|
|
|
if value then
|
2018-03-21 15:09:47 +00:00
|
|
|
return str .. color.escapefg(color.GREEN) .. "On" ..
|
|
|
|
color.escapefg(color.WHITE)
|
2018-02-20 14:36:28 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
return str .. color.escapefg(color.RED) .. "off" ..
|
|
|
|
color.escapefg(color.WHITE)
|
2018-02-20 14:36:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-23 04:03:07 +00:00
|
|
|
local function bootenvSet(env)
|
2018-02-21 16:50:41 +00:00
|
|
|
loader.setenv("vfs.root.mountfrom", env)
|
|
|
|
loader.setenv("currdev", env .. ":")
|
|
|
|
config.reload()
|
|
|
|
end
|
|
|
|
|
2018-02-20 14:45:58 +00:00
|
|
|
-- Module exports
|
2018-02-20 03:40:16 +00:00
|
|
|
menu.handlers = {
|
|
|
|
-- Menu handlers take the current menu and selected entry as parameters,
|
|
|
|
-- and should return a boolean indicating whether execution should
|
|
|
|
-- continue or not. The return value may be omitted if this entry should
|
|
|
|
-- have no bearing on whether we continue or not, indicating that we
|
|
|
|
-- should just continue after execution.
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_ENTRY] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- run function
|
2018-02-21 01:10:03 +00:00
|
|
|
entry.func()
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- carousel (rotating) functionality
|
2018-02-21 01:10:03 +00:00
|
|
|
local carid = entry.carousel_id
|
|
|
|
local caridx = config.getCarouselIndex(carid)
|
2018-02-21 05:04:58 +00:00
|
|
|
local choices = entry.items
|
|
|
|
if type(choices) == "function" then
|
|
|
|
choices = choices()
|
|
|
|
end
|
2018-02-21 01:35:19 +00:00
|
|
|
if #choices > 0 then
|
2018-02-21 01:10:03 +00:00
|
|
|
caridx = (caridx % #choices) + 1
|
|
|
|
config.setCarouselIndex(carid, caridx)
|
|
|
|
entry.func(caridx, choices[caridx], choices)
|
2018-02-20 03:40:16 +00:00
|
|
|
end
|
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_SUBMENU] = function(_, entry)
|
2018-02-25 04:11:08 +00:00
|
|
|
menu.process(entry.submenu)
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
[core.MENU_RETURN] = function(_, entry)
|
2018-02-20 03:40:16 +00:00
|
|
|
-- allow entry to have a function/side effect
|
2018-02-21 01:35:19 +00:00
|
|
|
if entry.func ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
entry.func()
|
2018-02-20 03:40:16 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
return false
|
2018-02-20 03:40:16 +00:00
|
|
|
end,
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-19 15:49:27 +00:00
|
|
|
-- loader menu tree is rooted at menu.welcome
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 16:50:41 +00:00
|
|
|
menu.boot_environments = {
|
|
|
|
entries = {
|
|
|
|
-- return to welcome menu
|
2018-03-01 02:04:26 +00:00
|
|
|
return_menu_entry,
|
2018-02-21 16:50:41 +00:00
|
|
|
{
|
|
|
|
entry_type = core.MENU_CAROUSEL_ENTRY,
|
|
|
|
carousel_id = "be_active",
|
|
|
|
items = core.bootenvList,
|
|
|
|
name = function(idx, choice, all_choices)
|
|
|
|
if #all_choices == 0 then
|
|
|
|
return "Active: "
|
|
|
|
end
|
|
|
|
|
|
|
|
local is_default = (idx == 1)
|
|
|
|
local bootenv_name = ""
|
|
|
|
local name_color
|
|
|
|
if is_default then
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.GREEN)
|
2018-02-21 16:50:41 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.BLUE)
|
2018-02-21 16:50:41 +00:00
|
|
|
end
|
|
|
|
bootenv_name = bootenv_name .. name_color ..
|
2018-03-21 15:09:47 +00:00
|
|
|
choice .. color.resetfg()
|
2018-02-21 16:50:41 +00:00
|
|
|
return color.highlight("A").."ctive: " ..
|
|
|
|
bootenv_name .. " (" .. idx .. " of " ..
|
|
|
|
#all_choices .. ")"
|
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
func = function(_, choice, _)
|
2018-02-21 16:50:41 +00:00
|
|
|
bootenvSet(choice)
|
|
|
|
end,
|
|
|
|
alias = {"a", "A"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
|
|
|
return color.highlight("b") .. "ootfs: " ..
|
|
|
|
core.bootenvDefault()
|
|
|
|
end,
|
|
|
|
func = function()
|
|
|
|
-- Reset active boot environment to the default
|
|
|
|
config.setCarouselIndex("be_active", 1)
|
|
|
|
bootenvSet(core.bootenvDefault())
|
|
|
|
end,
|
|
|
|
alias = {"b", "B"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-12 15:32:00 +00:00
|
|
|
menu.boot_options = {
|
2018-02-19 16:25:43 +00:00
|
|
|
entries = {
|
|
|
|
-- return to welcome menu
|
2018-03-01 02:04:26 +00:00
|
|
|
return_menu_entry,
|
2018-02-19 16:25:43 +00:00
|
|
|
-- load defaults
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Load System " .. color.highlight("D") ..
|
|
|
|
"efaults",
|
|
|
|
func = core.setDefaults,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"d", "D"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot Options:",
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- acpi
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-20 19:21:34 +00:00
|
|
|
visible = core.isSystem386,
|
2018-02-19 16:25:43 +00:00
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("A") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"CPI :", core.acpi)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setACPI,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"a", "A"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- safe mode
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
|
|
|
return OnOff("Safe " .. color.highlight("M") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"ode :", core.sm)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setSafeMode,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"m", "M"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- single user
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("S") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"ingle user:", core.su)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setSingleUser,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"s", "S"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- verbose boot
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
|
|
|
name = function()
|
2018-02-19 16:42:06 +00:00
|
|
|
return OnOff(color.highlight("V") ..
|
2018-02-21 01:10:03 +00:00
|
|
|
"erbose :", core.verbose)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-21 04:48:37 +00:00
|
|
|
func = core.setVerbose,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"v", "V"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2018-02-12 15:32:00 +00:00
|
|
|
},
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-12 15:32:00 +00:00
|
|
|
|
|
|
|
menu.welcome = {
|
2018-02-19 16:36:29 +00:00
|
|
|
entries = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
local menu_entries = menu.welcome.all_entries
|
2018-02-19 16:36:29 +00:00
|
|
|
-- Swap the first two menu items on single user boot
|
2018-02-21 01:35:19 +00:00
|
|
|
if core.isSingleUserBoot() then
|
2018-02-19 22:29:16 +00:00
|
|
|
-- We'll cache the swapped menu, for performance
|
2018-02-21 01:35:19 +00:00
|
|
|
if menu.welcome.swapped_menu ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
return menu.welcome.swapped_menu
|
2018-02-19 22:29:16 +00:00
|
|
|
end
|
2018-02-19 17:40:19 +00:00
|
|
|
-- Shallow copy the table
|
2018-02-23 03:18:24 +00:00
|
|
|
menu_entries = core.deepCopyTable(menu_entries)
|
2018-02-19 17:40:19 +00:00
|
|
|
|
2018-02-19 22:29:16 +00:00
|
|
|
-- Swap the first two menu entries
|
2018-02-19 22:56:04 +00:00
|
|
|
menu_entries[1], menu_entries[2] =
|
2018-02-21 01:10:03 +00:00
|
|
|
menu_entries[2], menu_entries[1]
|
2018-02-19 17:40:19 +00:00
|
|
|
|
2018-02-19 22:29:16 +00:00
|
|
|
-- Then set their names to their alternate names
|
|
|
|
menu_entries[1].name, menu_entries[2].name =
|
|
|
|
menu_entries[1].alternate_name,
|
2018-02-21 01:10:03 +00:00
|
|
|
menu_entries[2].alternate_name
|
|
|
|
menu.welcome.swapped_menu = menu_entries
|
2018-02-19 16:36:29 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
return menu_entries
|
2018-02-19 16:36:29 +00:00
|
|
|
end,
|
|
|
|
all_entries = {
|
2018-02-19 16:25:43 +00:00
|
|
|
-- boot multi user
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("B") .. "oot Multi user " ..
|
|
|
|
color.highlight("[Enter]"),
|
2018-02-19 17:40:19 +00:00
|
|
|
-- Not a standard menu entry function!
|
2018-02-21 04:48:37 +00:00
|
|
|
alternate_name = color.highlight("B") ..
|
|
|
|
"oot Multi user",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
core.setSingleUser(false)
|
|
|
|
core.boot()
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"b", "B"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- boot single user
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot " .. color.highlight("S") .. "ingle user",
|
2018-02-19 17:40:19 +00:00
|
|
|
-- Not a standard menu entry function!
|
2018-02-21 04:48:37 +00:00
|
|
|
alternate_name = "Boot " .. color.highlight("S") ..
|
|
|
|
"ingle user " .. color.highlight("[Enter]"),
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
core.setSingleUser(true)
|
|
|
|
core.boot()
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"s", "S"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- escape to interpreter
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_RETURN,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("Esc") .. "ape to loader prompt",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.setenv("autoboot_delay", "NO")
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {core.KEYSTR_ESCAPE},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- reboot
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_ENTRY,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = color.highlight("R") .. "eboot",
|
2018-02-19 16:25:43 +00:00
|
|
|
func = function()
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.perform("reboot")
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"r", "R"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SEPARATOR,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Options:",
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- kernel options
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_CAROUSEL_ENTRY,
|
|
|
|
carousel_id = "kernel",
|
|
|
|
items = core.kernelList,
|
|
|
|
name = function(idx, choice, all_choices)
|
2018-02-21 01:35:19 +00:00
|
|
|
if #all_choices == 0 then
|
2018-02-21 01:10:03 +00:00
|
|
|
return "Kernel: "
|
2018-02-19 16:25:43 +00:00
|
|
|
end
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local is_default = (idx == 1)
|
|
|
|
local kernel_name = ""
|
|
|
|
local name_color
|
2018-02-21 01:35:19 +00:00
|
|
|
if is_default then
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.GREEN)
|
2018-02-21 01:10:03 +00:00
|
|
|
kernel_name = "default/"
|
2018-02-19 16:25:43 +00:00
|
|
|
else
|
2018-03-21 15:09:47 +00:00
|
|
|
name_color = color.escapefg(color.BLUE)
|
2018-02-19 16:25:43 +00:00
|
|
|
end
|
2018-02-19 16:42:06 +00:00
|
|
|
kernel_name = kernel_name .. name_color ..
|
2018-03-21 15:09:47 +00:00
|
|
|
choice .. color.resetfg()
|
2018-02-19 17:51:33 +00:00
|
|
|
return color.highlight("K") .. "ernel: " ..
|
2018-02-19 16:42:06 +00:00
|
|
|
kernel_name .. " (" .. idx .. " of " ..
|
2018-02-21 01:10:03 +00:00
|
|
|
#all_choices .. ")"
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-22 04:15:02 +00:00
|
|
|
func = function(_, choice, _)
|
2018-02-24 20:21:21 +00:00
|
|
|
config.selectKernel(choice)
|
2018-02-19 16:25:43 +00:00
|
|
|
end,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"k", "K"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
|
|
|
-- boot options
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SUBMENU,
|
2018-02-21 04:48:37 +00:00
|
|
|
name = "Boot " .. color.highlight("O") .. "ptions",
|
2018-02-21 04:23:13 +00:00
|
|
|
submenu = menu.boot_options,
|
2018-02-25 03:33:25 +00:00
|
|
|
alias = {"o", "O"},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2018-02-21 16:50:41 +00:00
|
|
|
-- boot environments
|
|
|
|
{
|
|
|
|
entry_type = core.MENU_SUBMENU,
|
|
|
|
visible = function()
|
|
|
|
return core.isZFSBoot() and
|
|
|
|
#core.bootenvList() > 1
|
|
|
|
end,
|
|
|
|
name = "Boot " .. color.highlight("E") .. "nvironments",
|
|
|
|
submenu = menu.boot_environments,
|
|
|
|
alias = {"e", "E"},
|
|
|
|
},
|
2018-02-19 16:25:43 +00:00
|
|
|
},
|
2018-02-21 01:10:03 +00:00
|
|
|
}
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 03:37:46 +00:00
|
|
|
menu.default = menu.welcome
|
2018-02-25 04:44:45 +00:00
|
|
|
-- current_alias_table will be used to keep our alias table consistent across
|
|
|
|
-- screen redraws, instead of relying on whatever triggered the redraw to update
|
|
|
|
-- the local alias_table in menu.process.
|
|
|
|
menu.current_alias_table = {}
|
2018-02-21 03:37:46 +00:00
|
|
|
|
2018-02-26 03:46:17 +00:00
|
|
|
function menu.draw(menudef)
|
2018-02-25 17:02:50 +00:00
|
|
|
-- Clear the screen, reset the cursor, then draw
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.clear()
|
2018-02-26 03:46:17 +00:00
|
|
|
menu.current_alias_table = drawer.drawscreen(menudef)
|
|
|
|
drawn_menu = menudef
|
2018-03-02 17:07:08 +00:00
|
|
|
screen.defcursor()
|
2018-02-25 04:44:45 +00:00
|
|
|
end
|
|
|
|
|
2018-02-25 05:00:54 +00:00
|
|
|
-- 'keypress' allows the caller to indicate that a key has been pressed that we
|
|
|
|
-- should process as our initial input.
|
2018-02-26 03:46:17 +00:00
|
|
|
function menu.process(menudef, keypress)
|
|
|
|
assert(menudef ~= nil)
|
2018-02-25 04:44:45 +00:00
|
|
|
|
2018-02-26 03:46:17 +00:00
|
|
|
if drawn_menu ~= menudef then
|
|
|
|
menu.draw(menudef)
|
2018-02-21 17:33:01 +00:00
|
|
|
end
|
2018-02-25 05:00:54 +00:00
|
|
|
|
2018-02-25 04:11:08 +00:00
|
|
|
while true do
|
2018-02-25 05:00:54 +00:00
|
|
|
local key = keypress or io.getchar()
|
|
|
|
keypress = nil
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-15 18:16:16 +00:00
|
|
|
-- Special key behaviors
|
2018-02-21 01:35:19 +00:00
|
|
|
if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and
|
2018-02-26 03:46:17 +00:00
|
|
|
menudef ~= menu.default then
|
2018-02-21 01:10:03 +00:00
|
|
|
break
|
2018-02-21 01:35:19 +00:00
|
|
|
elseif key == core.KEY_ENTER then
|
2018-02-21 01:10:03 +00:00
|
|
|
core.boot()
|
2018-02-15 18:16:16 +00:00
|
|
|
-- Should not return
|
2018-02-14 20:18:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
key = string.char(key)
|
2018-02-12 15:32:00 +00:00
|
|
|
-- check to see if key is an alias
|
2018-02-21 01:10:03 +00:00
|
|
|
local sel_entry = nil
|
2018-02-25 04:44:45 +00:00
|
|
|
for k, v in pairs(menu.current_alias_table) do
|
2018-02-21 01:35:19 +00:00
|
|
|
if key == k then
|
2018-02-21 01:10:03 +00:00
|
|
|
sel_entry = v
|
2018-02-25 04:44:45 +00:00
|
|
|
break
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if we have an alias do the assigned action:
|
2018-02-21 01:35:19 +00:00
|
|
|
if sel_entry ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
local handler = menu.handlers[sel_entry.entry_type]
|
2018-02-26 03:46:17 +00:00
|
|
|
assert(handler ~= nil)
|
|
|
|
-- The handler's return value indicates if we
|
|
|
|
-- need to exit this menu. An omitted or true
|
|
|
|
-- return value means to continue.
|
|
|
|
if handler(menudef, sel_entry) == false then
|
|
|
|
return
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-25 04:44:45 +00:00
|
|
|
-- If we got an alias key the screen is out of date...
|
|
|
|
-- redraw it.
|
2018-02-26 03:46:17 +00:00
|
|
|
menu.draw(menudef)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
2018-02-25 04:11:08 +00:00
|
|
|
end
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-25 04:11:08 +00:00
|
|
|
function menu.run()
|
2018-02-25 17:02:50 +00:00
|
|
|
menu.draw(menu.default)
|
2018-02-25 05:00:54 +00:00
|
|
|
local autoboot_key = menu.autoboot()
|
|
|
|
|
|
|
|
menu.process(menu.default, autoboot_key)
|
2018-02-25 17:02:50 +00:00
|
|
|
drawn_menu = nil
|
2018-02-25 04:11:08 +00:00
|
|
|
|
|
|
|
screen.defcursor()
|
|
|
|
print("Exiting menu!")
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function menu.autoboot()
|
2018-02-21 01:10:03 +00:00
|
|
|
local ab = loader.getenv("autoboot_delay")
|
2018-02-21 01:35:19 +00:00
|
|
|
if ab ~= nil and ab:lower() == "no" then
|
2018-02-21 14:37:49 +00:00
|
|
|
return nil
|
2018-02-21 01:35:19 +00:00
|
|
|
elseif tonumber(ab) == -1 then
|
2018-02-21 01:10:03 +00:00
|
|
|
core.boot()
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
ab = tonumber(ab) or 10
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-03-03 18:13:14 +00:00
|
|
|
local x = loader.getenv("loader_menu_timeout_x") or 4
|
|
|
|
local y = loader.getenv("loader_menu_timeout_y") or 23
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local endtime = loader.time() + ab
|
|
|
|
local time
|
2018-03-09 18:45:13 +00:00
|
|
|
local last
|
2018-02-12 15:32:00 +00:00
|
|
|
repeat
|
2018-02-21 01:10:03 +00:00
|
|
|
time = endtime - loader.time()
|
2018-03-09 18:45:13 +00:00
|
|
|
if last == nil or last ~= time then
|
|
|
|
last = time
|
|
|
|
screen.setcursor(x, y)
|
|
|
|
print("Autoboot in " .. time ..
|
|
|
|
" seconds, hit [Enter] to boot" ..
|
|
|
|
" or any other key to stop ")
|
|
|
|
screen.defcursor()
|
|
|
|
end
|
2018-02-21 01:35:19 +00:00
|
|
|
if io.ischar() then
|
2018-02-21 01:10:03 +00:00
|
|
|
local ch = io.getchar()
|
2018-02-21 01:35:19 +00:00
|
|
|
if ch == core.KEY_ENTER then
|
2018-02-21 01:10:03 +00:00
|
|
|
break
|
2018-02-12 15:32:00 +00:00
|
|
|
else
|
|
|
|
-- erase autoboot msg
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.setcursor(0, y)
|
2018-02-22 20:10:23 +00:00
|
|
|
print(string.rep(" ", 80))
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.defcursor()
|
2018-02-21 14:37:49 +00:00
|
|
|
return ch
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.delay(50000)
|
|
|
|
until time <= 0
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-03-03 17:18:40 +00:00
|
|
|
local cmd = loader.getenv("menu_timeout_command") or "boot"
|
2018-03-07 18:31:01 +00:00
|
|
|
cli_execute_unparsed(cmd)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
return menu
|