Changeset View
Standalone View
stand/lua/menu.lua
| -- | -- | ||||
| -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD | -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
| -- | -- | ||||
| -- Copyright (c) 2023 The SmartixOS Project <ip@smartix.llc> | |||||
| -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> | -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> | ||||
| -- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> | -- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> | ||||
| -- All rights reserved. | -- All rights reserved. | ||||
| -- | -- | ||||
| -- Redistribution and use in source and binary forms, with or without | -- Redistribution and use in source and binary forms, with or without | ||||
| Context not available. | |||||
| -- $FreeBSD$ | -- $FreeBSD$ | ||||
| -- | -- | ||||
| -- Required libraries | |||||
| local cli = require("cli") | local cli = require("cli") | ||||
| local core = require("core") | local core = require("core") | ||||
| local color = require("color") | local color = require("color") | ||||
| Context not available. | |||||
| local screen = require("screen") | local screen = require("screen") | ||||
| local drawer = require("drawer") | local drawer = require("drawer") | ||||
| -- LOCAL VARIABLES | |||||
| local theme = color.getTheme(color.MENU) | |||||
| -- The list of Initials to highlight. | |||||
| -- The initials of certain phrases ( messages ) on the loader menu have been removed and made separate from the original sentences | |||||
| -- to allow separate colorization of those initials. On the loader prompt, these | |||||
| -- initials are also keyboard shortcuts that the user can type to access specific items on the loader menu. | |||||
| -- The variables are declared as functions to take advantage of the immutability property of strings in Lua. | |||||
| -- This trick allows for instantaneous change and near instantaneous rendition of the those initials after they have been stylized/colorized based on a theme. | |||||
| -- Each section/portion of the loader menu is independently controlled by a bootloader variable. | |||||
| -- These bootloader variables are declared in the script 'color.lua' and are listed here for reference: | |||||
| -- loader_brand_theme : controls the theme/color of the brand | |||||
| -- loader_menu_theme : controls the theme/color of the menu | |||||
| -- loader_logo_theme : controls the theme/color of the logo | |||||
| local MSG_A = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "A" .. color.resetfg() | |||||
| end | |||||
| local MSG_B = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "B" .. color.resetfg() | |||||
| end | |||||
| local MSG_C = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "C" .. color.resetfg() | |||||
| end | |||||
| local MSG_D = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "D" .. color.resetfg() | |||||
| end | |||||
| local MSG_E = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "E" .. color.resetfg() | |||||
| end | |||||
| local MSG_L = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "L".. color.resetfg() | |||||
| end | |||||
| local MSG_K = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "K" .. color.resetfg() | |||||
| end | |||||
| local MSG_M = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "M" .. color.resetfg() | |||||
| end | |||||
| local MSG_O = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "O" .. color.resetfg() | |||||
| end | |||||
| local MSG_R = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "R" .. color.resetfg() | |||||
| end | |||||
| local MSG_S = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "S".. color.resetfg() | |||||
| end | |||||
| local MSG_V = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "V" .. color.resetfg() | |||||
| end | |||||
| local MSG_b = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "b" .. color.resetfg() | |||||
| end | |||||
| local MSG_ENTER= function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "Enter" .. color.resetfg() | |||||
| end | |||||
| local MSG_ESC = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "Esc" .. color.resetfg() | |||||
| end | |||||
| local MSG_BACKSPACE = function() | |||||
| return color.escapefg(color.getTheme(color.MENU)) .. "Backspace" .. color.resetfg() | |||||
| end | |||||
| -- The list of messages displayed on the loader menu prompt. | |||||
| -- [B]"oot Multi user" | |||||
| local MSG_OOT_MULTI_USER_ = "oot into Multi user " | |||||
| --local OLD_MSG_OOT_MULTI_USER_ = "oot Multi user " | |||||
| local MSG_BOOT_INTO_ = "Boot into " | |||||
| -- local OLD_MSG_BOOT__ = "Boot " | |||||
| -- [S]"ingle user" | |||||
| local MSG_INGLE_USER = "ingle user" | |||||
| -- [C]"ons: " | |||||
| local MSG_ONS_ = "onsole mode: " | |||||
| -- local OLD_MSG_ONS_ = "ons: " | |||||
| -- [E]"scape to loader prompt" | |||||
| local MSG_ESC_LOADER_PROMPT ="ape to loader prompt" | |||||
| -- "Reboot" | |||||
| local MSG_EBOOT ="eboot" | |||||
| -- [K]"ernel list: " | |||||
| local MSG_ERNEL_ ="ernel list: " | |||||
| -- local OLD_MSG_ERNEL_ ="ernel: " | |||||
| local MSG_BOOT_ = "Boot " | |||||
| -- [O]"ptions | |||||
| local MSG_PTIONS = "ptions" | |||||
| local MSG_LOAD_SYSTEM_ = "Load System " | |||||
| -- [D]"efaults" | |||||
| local MSG_EFAULTS = "efaults" | |||||
| -- [A]"CPI :" | |||||
| local MSG_CPI_ = "CPI :" | |||||
| local MSG_SAFE_ = "Safe " | |||||
| -- [M]"ode :" | |||||
| local MSG_ODE_ = "ode :" | |||||
| local MSG_BCKTO_MAIN_MENU = "Back to main menu" | |||||
| local MSG_ACTIVE_ = "Active: " | |||||
| -- [V]"erbose :" | |||||
| local MSG_ERBOSE_ ="erbose :" | |||||
| -- [A]"ctive: " | |||||
| local MSG_CTIVE_ = "ctive: " | |||||
| -- [b]"ootfs: " | |||||
| local MSG_OOTFS_ ="ootfs: " | |||||
| local MSG_SPACE="Space" | |||||
| local menu = {} | local menu = {} | ||||
| local drawn_menu | local drawn_menu | ||||
| local return_menu_entry = { | local return_menu_entry = { | ||||
| entry_type = core.MENU_RETURN, | entry_type = core.MENU_RETURN, | ||||
| name = "Back to main menu" .. color.highlight(" [Backspace]"), | name = function() | ||||
| } | return MSG_BCKTO_MAIN_MENU .. color.highlight(" [" .. MSG_BACKSPACE() .. "]") | ||||
| end, | |||||
| } -- end return_menu_entry | |||||
| local function OnOff(str, value) | local function OnOff(str, value) | ||||
| if value then | if value then | ||||
| return str .. color.escapefg(color.GREEN) .. "On" .. | return str .. color.escapefg(color.GREEN) .. "On" .. color.resetfg() | ||||
| color.resetfg() | |||||
| else | else | ||||
| return str .. color.escapefg(color.RED) .. "off" .. | return str .. color.escapefg(color.RED) .. "off" .. color.resetfg() | ||||
| color.resetfg() | |||||
| end | end | ||||
| end | end -- function OnOff | ||||
| local function bootenvSet(env) | local function bootenvSet(env) | ||||
| loader.setenv("vfs.root.mountfrom", env) | loader.setenv("vfs.root.mountfrom", env) | ||||
| Context not available. | |||||
| -- have no bearing on whether we continue or not, indicating that we | -- have no bearing on whether we continue or not, indicating that we | ||||
| -- should just continue after execution. | -- should just continue after execution. | ||||
| [core.MENU_ENTRY] = function(_, entry) | [core.MENU_ENTRY] = function(_, entry) | ||||
| -- run function | -- run function | ||||
| entry.func() | entry.func() | ||||
| end, | end, -- end [core.MENU_ENTRY] | ||||
| [core.MENU_CAROUSEL_ENTRY] = function(_, entry) | [core.MENU_CAROUSEL_ENTRY] = function(_, entry) | ||||
| -- carousel (rotating) functionality | -- carousel (rotating) functionality | ||||
| local carid = entry.carousel_id | local carousel_id = entry.carousel_id | ||||
| local caridx = config.getCarouselIndex(carid) | local carousel_index = config.getCarouselIndex(carousel_id) | ||||
| local choices = entry.items | local choices = entry.items | ||||
| if type(choices) == "function" then | if type(choices) == "function" then | ||||
| choices = choices() | choices = choices() | ||||
| end | end | ||||
| if #choices > 0 then | |||||
| caridx = (caridx % #choices) + 1 | if #choices > 0 then | ||||
| config.setCarouselIndex(carid, caridx) | carousel_index = (carousel_index % #choices) + 1 | ||||
| entry.func(caridx, choices[caridx], choices) | config.setCarouselIndex(carousel_id, carousel_index) | ||||
| end | entry.func(carousel_index, choices[carousel_index], choices) | ||||
| end, | end | ||||
| end, -- end [core.MENU_CAROUSEL_ENTRY] | |||||
| [core.MENU_SUBMENU] = function(_, entry) | [core.MENU_SUBMENU] = function(_, entry) | ||||
| menu.process(entry.submenu) | menu.process(entry.submenu) | ||||
| end, | end, | ||||
| [core.MENU_RETURN] = function(_, entry) | [core.MENU_RETURN] = function(_, entry) | ||||
| -- allow entry to have a function/side effect | -- allow entry to have a function/side effect | ||||
| if entry.func ~= nil then | if entry.func ~= nil then | ||||
| entry.func() | entry.func() | ||||
| end | end | ||||
| return false | return false | ||||
| end, | end, | ||||
| } | |||||
| -- loader menu tree is rooted at menu.welcome | |||||
| menu.boot_environments = { | } -- end menu.handlers | ||||
| entries = { | |||||
| -- return to welcome menu | |||||
| return_menu_entry, | |||||
| { | |||||
| 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 | |||||
| name_color = color.escapefg(color.GREEN) | |||||
| else | |||||
| name_color = color.escapefg(color.BLUE) | |||||
| end | |||||
| bootenv_name = bootenv_name .. name_color .. | |||||
| choice .. color.resetfg() | |||||
| return color.highlight("A").."ctive: " .. | |||||
| bootenv_name .. " (" .. idx .. " of " .. | |||||
| #all_choices .. ")" | |||||
| end, | |||||
| func = function(_, choice, _) | |||||
| bootenvSet(choice) | |||||
| end, | |||||
| alias = {"a", "A"}, | |||||
| }, | |||||
| { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| visible = function() | |||||
| return core.isRewinded() == false | |||||
| end, | |||||
| 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"}, | |||||
| }, | |||||
| }, | |||||
| } | |||||
| -- loader menu tree is rooted at (start with the node ) menu.welcome | |||||
| menu.boot_environments = { | |||||
| entries = { | |||||
| -- return to welcome menu | |||||
| return_menu_entry, | |||||
| { -- core.MENU_CAROUSEL_ENTRY | |||||
| entry_type = core.MENU_CAROUSEL_ENTRY, | |||||
| carousel_id = "be_active", | |||||
| items = core.bootenvList, | |||||
| name = function(idx, choice, all_choices) | |||||
| if #all_choices == 0 then | |||||
| -- MSG_ACTIVE_ = "Active: " | |||||
| return MSG_ACTIVE_ | |||||
| end | |||||
| local is_default = (idx == 1) | |||||
| local bootenv_name = "" | |||||
| local name_color | |||||
| if is_default then | |||||
| name_color = color.escapefg(color.GREEN) | |||||
| else | |||||
| name_color = color.escapefg(color.BLUE) | |||||
| end | |||||
| bootenv_name = bootenv_name .. name_color .. choice .. color.resetfg() | |||||
| -- MSG_CTIVE_ = "ctive: " | |||||
| return color.highlight(MSG_A()) .. MSG_CTIVE_ .. bootenv_name .. " (" .. idx .. " of " .. #all_choices .. ")" | |||||
| end, | |||||
| -- The function parameters are carousel_index, choice, choices | |||||
| func = function(_, choice, _) | |||||
| bootenvSet(choice) | |||||
| end, | |||||
| alias = {"a", "A"}, | |||||
| }, -- end core.MENU_CAROUSEL_ENTRY | |||||
| { -- core.MENU_ENTRY | |||||
| entry_type = core.MENU_ENTRY, | |||||
| visible = function() | |||||
| return core.isRewinded() == false | |||||
| end, | |||||
| name = function() | |||||
| -- MSG_OOTFS_ ="ootfs: " | |||||
| return color.highlight(MSG_b()) .. MSG_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"}, | |||||
| }, -- end core.MENU_ENTRY | |||||
| }, -- end entries | |||||
| } -- end menu.boot_environments | |||||
| -- option 7 in the boot menu | |||||
| menu.boot_options = { | menu.boot_options = { | ||||
| entries = { | entries = { | ||||
| -- return to welcome menu | -- Back to main menu | ||||
| return_menu_entry, | return_menu_entry, | ||||
| -- load defaults | -- Load System Defaults | ||||
| { | { | ||||
| entry_type = core.MENU_ENTRY, | |||||
| name = "Load System " .. color.highlight("D") .. | entry_type = core.MENU_ENTRY, | ||||
| "efaults", | name = function() | ||||
| func = core.setDefaults, | -- MSG_EFAULTS = "efaults" | ||||
| alias = {"d", "D"}, | return MSG_LOAD_SYSTEM_ .. color.highlight(MSG_D()) .. MSG_EFAULTS | ||||
| }, | end, | ||||
| { | func = core.setDefaults, | ||||
| entry_type = core.MENU_SEPARATOR, | alias = {"d", "D"}, | ||||
| }, | }, | ||||
| { | |||||
| entry_type = core.MENU_SEPARATOR, | { | ||||
| name = "Boot Options:", | entry_type = core.MENU_SEPARATOR, | ||||
| }, | }, | ||||
| -- acpi | |||||
| { | { | ||||
| entry_type = core.MENU_ENTRY, | entry_type = core.MENU_SEPARATOR, | ||||
| visible = core.isSystem386, | name = "Boot Options:", | ||||
| name = function() | }, | ||||
| return OnOff(color.highlight("A") .. | |||||
| "CPI :", core.acpi) | -- acpi | ||||
| end, | { | ||||
| func = core.setACPI, | entry_type = core.MENU_ENTRY, | ||||
| alias = {"a", "A"}, | visible = core.isSystem386, | ||||
| }, | name = function() | ||||
| -- safe mode | -- MSG_CPI_ = "CPI :" | ||||
| { | return OnOff( color.highlight(MSG_A()) .. MSG_CPI_, core.acpi) | ||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | end, | ||||
| return OnOff("Safe " .. color.highlight("M") .. | func = core.setACPI, | ||||
| "ode :", core.sm) | alias = {"a", "A"}, | ||||
| end, | }, | ||||
| func = core.setSafeMode, | |||||
| alias = {"m", "M"}, | -- safe mode | ||||
| }, | { | ||||
| -- single user | entry_type = core.MENU_ENTRY, | ||||
| { | |||||
| entry_type = core.MENU_ENTRY, | name = function() | ||||
| name = function() | |||||
| return OnOff(color.highlight("S") .. | return OnOff(MSG_SAFE_ .. color.highlight(MSG_M()) .. MSG_ODE_, core.sm) | ||||
| "ingle user:", core.su) | |||||
| end, | end, | ||||
| func = core.setSingleUser, | func = core.setSafeMode, | ||||
| alias = {"s", "S"}, | alias = {"m", "M"}, | ||||
| }, | }, | ||||
| -- verbose boot | -- single user | ||||
| { | { | ||||
| entry_type = core.MENU_ENTRY, | entry_type = core.MENU_ENTRY, | ||||
| name = function() | name = function() | ||||
| return OnOff(color.highlight("V") .. | -- MSG_INGLE_USER = "ingle user" | ||||
| "erbose :", core.verbose) | return OnOff( color.highlight(MSG_S()) .. MSG_INGLE_USER .. ":" , core.su) | ||||
| end, | |||||
| func = core.setVerbose, | end, | ||||
| alias = {"v", "V"}, | func = core.setSingleUser, | ||||
| }, | alias = {"s", "S"}, | ||||
| }, | }, | ||||
| } | -- verbose boot | ||||
| { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| return OnOff( color.highlight(MSG_V()) .. MSG_ERBOSE_ , core.verbose) | |||||
| end, | |||||
| func = core.setVerbose, | |||||
| alias = {"v", "V"}, | |||||
| }, | |||||
| }, --end entries | |||||
| } -- end menu.boot_options | |||||
| menu.welcome = { | menu.welcome = { | ||||
| entries = function() | |||||
| local menu_entries = menu.welcome.all_entries | |||||
| local multi_user = menu_entries.multi_user | |||||
| local single_user = menu_entries.single_user | |||||
| local boot_entry_1, boot_entry_2 | |||||
| if core.isSingleUserBoot() then | |||||
| -- Swap the first two menu items on single user boot. | |||||
| -- We'll cache the alternate entries for performance. | |||||
| local alts = menu_entries.alts | |||||
| if alts == nil then | |||||
| single_user = core.deepCopyTable(single_user) | |||||
| multi_user = core.deepCopyTable(multi_user) | |||||
| single_user.name = single_user.alternate_name | |||||
| multi_user.name = multi_user.alternate_name | |||||
| menu_entries.alts = { | |||||
| single_user = single_user, | |||||
| multi_user = multi_user, | |||||
| } | |||||
| else | |||||
| single_user = alts.single_user | |||||
| multi_user = alts.multi_user | |||||
| end | |||||
| boot_entry_1, boot_entry_2 = single_user, multi_user | |||||
| else | |||||
| boot_entry_1, boot_entry_2 = multi_user, single_user | |||||
| end | |||||
| return { | |||||
| boot_entry_1, | |||||
| boot_entry_2, | |||||
| menu_entries.prompt, | |||||
| menu_entries.reboot, | |||||
| menu_entries.console, | |||||
| { | |||||
| entry_type = core.MENU_SEPARATOR, | |||||
| }, | |||||
| { | |||||
| entry_type = core.MENU_SEPARATOR, | |||||
| name = "Options:", | |||||
| }, | |||||
| menu_entries.kernel_options, | |||||
| menu_entries.boot_options, | |||||
| menu_entries.zpool_checkpoints, | |||||
| menu_entries.boot_envs, | |||||
| menu_entries.chainload, | |||||
| menu_entries.vendor, | |||||
| } | |||||
| end, | |||||
| all_entries = { | |||||
| multi_user = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| return color.highlight("B") .. "oot " .. | |||||
| multiUserPrompt() .. " " .. | |||||
jrtc27: I'll let others comment on all the other changes rather than sharing my own thoughts which I… | |||||
ghislain_smartix.llcAuthorUnsubmitted Done Inline ActionsThanks for the prompt reply. Well, I will be looking closely into it while others take time to review the changes. But in case this breaks certain configuration messages, the optimistic side of me wants to believe that few lines of code after the discussion we are already having should help fix the issue to some extent. ghislain_smartix.llc: Thanks for the prompt reply. Well, I will be looking closely into it while others take time to… | |||||
jrtc27Unsubmitted Not Done Inline ActionsIf you want people to properly review your changes I suggest you read https://wiki.freebsd.org/Phabricator and follow what it says. In particular this is not a revision that does one thing and one thing only, nor have you included more than the default few lines of context. Plus skimming the changes here shows a bunch of gratuitous reorganising and renaming of questionable value. Each logical part of the revision needs to be its own revision and be adequately justified. jrtc27: If you want people to properly review your changes I suggest you read https://wiki.freebsd. | |||||
ghislain_smartix.llcAuthorUnsubmitted Done Inline ActionsThanks for the pointer. Having this information scattered in the Developer Primer and other places make finding the most relevant information a bit slow. your suggestions have been noted for future code review submissions. I agree that, these changes touch on several files at once but they were all inter-related; and changing one aspect/file necessarily implied touching on few others. My apologies for any extra work this may have created or will be creating in case things move along. The change in the names of certain variables and the refactoring in certain places were mostly added for clarity; a term that may be relative of course but the purpose was to help boost developers productivity by reducing the time it takes to figure out the logic and the use of certain variables. ghislain_smartix.llc: Thanks for the pointer. Having this information scattered in the Developer Primer and other… | |||||
impUnsubmitted Not Done Inline ActionsI'm struggling myself with how to give this sort of feedback. The current code review is too large for me to give meaningful commentary on it. It mixes a number of style changes (some good, some bad) with a number of functional additions and some changes to the APIs that need some careful study (which given the size of this review is a lot harder than it needs to be and would likely take more time than I have to devote to this). I understand that having things scattered a bit is frustrating. We've been trying to make sure all the information is at least there, but it could use a pass to make sure that it's easy to find. There's a lot of good things in this review. I'd like to focus on those, but will likely do so by suggesting you split this or that feature out into its own review so people can focus on the change, use their time more efficiently and give you better feedback for what needs to change and to maximize chances things will wind up in the tree more quickly rather than less so. I've taken a first look, but am out of time for today (my teenager has her spring concert tonight in 2 hours, and it's almost time to leave for dinner). I'll try to get back to this tomorrow though. imp: I'm struggling myself with how to give this sort of feedback. The current code review is too… | |||||
ghislain_smartix.llcAuthorUnsubmitted Done Inline ActionsCarefully noted! Thanks for the feedback. The documentation still rocks despite everything; we can do better as a community though and i have no doubt this is one of the chief goals. Looking very much forward to resolving all the issues. A bit late to send out warn wishes but i hope you had a blast with your teenager; engineering is great but family is everything. ghislain_smartix.llc: Carefully noted! Thanks for the feedback.
The documentation still rocks despite everything… | |||||
| color.highlight("[Enter]") | |||||
| end, | |||||
| -- Not a standard menu entry function! | |||||
| alternate_name = function() | |||||
| return color.highlight("B") .. "oot " .. | |||||
| multiUserPrompt() | |||||
| end, | |||||
| func = function() | |||||
| core.setSingleUser(false) | |||||
| core.boot() | |||||
| end, | |||||
| alias = {"b", "B"}, | |||||
| }, | |||||
| single_user = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = "Boot " .. color.highlight("S") .. "ingle user", | |||||
| -- Not a standard menu entry function! | |||||
| alternate_name = "Boot " .. color.highlight("S") .. | |||||
| "ingle user " .. color.highlight("[Enter]"), | |||||
| func = function() | |||||
| core.setSingleUser(true) | |||||
| core.boot() | |||||
| end, | |||||
| alias = {"s", "S"}, | |||||
| }, | |||||
| console = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| return color.highlight("C") .. "ons: " .. core.getConsoleName() | |||||
| end, | |||||
| func = function() | |||||
| core.nextConsoleChoice() | |||||
| end, | |||||
| alias = {"c", "C"}, | |||||
| }, | |||||
| prompt = { | |||||
| entry_type = core.MENU_RETURN, | |||||
| name = color.highlight("Esc") .. "ape to loader prompt", | |||||
| func = function() | |||||
| loader.setenv("autoboot_delay", "NO") | |||||
| end, | |||||
| alias = {core.KEYSTR_ESCAPE}, | |||||
| }, | |||||
| reboot = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = color.highlight("R") .. "eboot", | |||||
| func = function() | |||||
| loader.perform("reboot") | |||||
| end, | |||||
| alias = {"r", "R"}, | |||||
| }, | |||||
| kernel_options = { | |||||
| entry_type = core.MENU_CAROUSEL_ENTRY, | |||||
| carousel_id = "kernel", | |||||
| items = core.kernelList, | |||||
| name = function(idx, choice, all_choices) | |||||
| if #all_choices == 0 then | |||||
| return "Kernel: " | |||||
| end | |||||
| local is_default = (idx == 1) | entries = function() | ||||
| local kernel_name = "" | local menu_entries = menu.welcome.all_entries | ||||
| local name_color | local multi_user = menu_entries.multi_user | ||||
| if is_default then | local single_user = menu_entries.single_user | ||||
| name_color = color.escapefg(color.GREEN) | local boot_entry_1, boot_entry_2 | ||||
| kernel_name = "default/" | if core.isSingleUserBoot() then | ||||
| -- Swap the first two menu items on single user boot. | |||||
| -- We'll cache the alternate entries for performance. | |||||
| local alts = menu_entries.alts | |||||
| if alts == nil then | |||||
| single_user = core.deepCopyTable(single_user) | |||||
| multi_user = core.deepCopyTable(multi_user) | |||||
| single_user.name = single_user.alternate_name | |||||
| multi_user.name = multi_user.alternate_name | |||||
| menu_entries.alts = { | |||||
| single_user = single_user, | |||||
| multi_user = multi_user, | |||||
| } | |||||
| else | else | ||||
| name_color = color.escapefg(color.BLUE) | single_user = alts.single_user | ||||
| end | multi_user = alts.multi_user | ||||
| kernel_name = kernel_name .. name_color .. | |||||
| choice .. color.resetfg() | |||||
| return color.highlight("K") .. "ernel: " .. | |||||
| kernel_name .. " (" .. idx .. " of " .. | |||||
| #all_choices .. ")" | |||||
| end, | |||||
| func = function(_, choice, _) | |||||
| if loader.getenv("kernelname") ~= nil then | |||||
| loader.perform("unload") | |||||
| end | end | ||||
| config.selectKernel(choice) | boot_entry_1, boot_entry_2 = single_user, multi_user | ||||
| end, | else | ||||
| alias = {"k", "K"}, | boot_entry_1, boot_entry_2 = multi_user, single_user | ||||
| }, | |||||
| boot_options = { | |||||
| entry_type = core.MENU_SUBMENU, | |||||
| name = "Boot " .. color.highlight("O") .. "ptions", | |||||
| submenu = menu.boot_options, | |||||
| alias = {"o", "O"}, | |||||
| }, | |||||
| zpool_checkpoints = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| local rewind = "No" | |||||
| if core.isRewinded() then | |||||
| rewind = "Yes" | |||||
| end | |||||
| return "Rewind ZFS " .. color.highlight("C") .. | |||||
| "heckpoint: " .. rewind | |||||
| end, | |||||
| func = function() | |||||
| core.changeRewindCheckpoint() | |||||
| if core.isRewinded() then | |||||
| bootenvSet( | |||||
| core.bootenvDefaultRewinded()) | |||||
| else | |||||
| bootenvSet(core.bootenvDefault()) | |||||
| end | |||||
| config.setCarouselIndex("be_active", 1) | |||||
| end, | |||||
| visible = function() | |||||
| return core.isZFSBoot() and | |||||
| core.isCheckpointed() | |||||
| end, | |||||
| alias = {"c", "C"}, | |||||
| }, | |||||
| boot_envs = { | |||||
| 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"}, | |||||
| }, | |||||
| chainload = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| return 'Chain' .. color.highlight("L") .. | |||||
| "oad " .. loader.getenv('chain_disk') | |||||
| end, | |||||
| func = function() | |||||
| loader.perform("chain " .. | |||||
| loader.getenv('chain_disk')) | |||||
| end, | |||||
| visible = function() | |||||
| return loader.getenv('chain_disk') ~= nil | |||||
| end, | |||||
| alias = {"l", "L"}, | |||||
| }, | |||||
| vendor = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| visible = function() | |||||
| return false | |||||
| end | end | ||||
| }, | return { | ||||
| }, | boot_entry_1, | ||||
| } | boot_entry_2, | ||||
| menu_entries.prompt, | |||||
| menu_entries.reboot, | |||||
| menu_entries.console, | |||||
| { | |||||
| entry_type = core.MENU_SEPARATOR, | |||||
| }, | |||||
| { | |||||
| entry_type = core.MENU_SEPARATOR, | |||||
| name = "Advanced Options:", | |||||
| }, | |||||
| menu_entries.kernel_options, | |||||
| menu_entries.boot_options, | |||||
| menu_entries.zpool_checkpoints, | |||||
| menu_entries.boot_envs, | |||||
| menu_entries.chainload, | |||||
| menu_entries.vendor, | |||||
| } | |||||
| end, -- end entries | |||||
| all_entries = { | |||||
| multi_user = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| -- MSG_OOT_MULTI_USER_ = "oot Multi user " | |||||
| return color.highlight(MSG_B() ) .. MSG_OOT_MULTI_USER_ .. color.highlight("[" .. MSG_ENTER() .. "]") | |||||
| end, | |||||
| -- Not a standard menu entry function! | |||||
| alternate_name = function() | |||||
| return color.highlight( MSG_B() ) .. MSG_OOT_MULTI_USER_ | |||||
| end, | |||||
| func = function() | |||||
| core.setSingleUser(false) | |||||
| core.boot() | |||||
| end, | |||||
| alias = {"b", "B"}, | |||||
| }, -- end multi_user | |||||
| single_user = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| -- MSG_INGLE_USER = "ingle user" | |||||
| return MSG_BOOT_INTO_ .. color.highlight(MSG_S()) .. MSG_INGLE_USER | |||||
| end, | |||||
| -- Not a standard menu entry function! | |||||
| alternate_name = function() | |||||
| return MSG_BOOT_INTO_ .. color.highlight(MSG_S()) .. MSG_INGLE_USER .. " " .. color.highlight("[" .. MSG_ENTER() .."]") | |||||
| end, | |||||
| func = function() | |||||
| core.setSingleUser(true) | |||||
| core.boot() | |||||
| end, | |||||
| alias = {"s", "S"}, | |||||
| }, -- end single_user | |||||
| console = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| -- MSG_ONS_ = "ons: " | |||||
| return color.highlight(MSG_C()) .. MSG_ONS_ .. core.getConsoleName() | |||||
| end, | |||||
| func = function() | |||||
| core.nextConsoleChoice() | |||||
| end, | |||||
| alias = {"c", "C"}, | |||||
| }, -- end console | |||||
| prompt = { | |||||
| entry_type = core.MENU_RETURN, | |||||
| name = function() | |||||
| -- MSG_ESC="Esc" MSG_ESC_LOADER_PROMPT ="ape to loader prompt" | |||||
| return color.highlight(MSG_ESC()) .. MSG_ESC_LOADER_PROMPT | |||||
| end, | |||||
| func = function() | |||||
| loader.setenv("autoboot_delay", "NO") | |||||
| end, | |||||
| alias = {core.KEYSTR_ESCAPE}, | |||||
| }, -- end prompt | |||||
| reboot = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| -- MSG_EBOOT ="eboot" | |||||
| return color.highlight(MSG_R()) .. MSG_EBOOT | |||||
| end, | |||||
| func = function() | |||||
| loader.perform("reboot") | |||||
| end, | |||||
| alias = {"r", "R"}, | |||||
| }, -- end reboot | |||||
| kernel_options = { | |||||
| entry_type = core.MENU_CAROUSEL_ENTRY, | |||||
| carousel_id = "kernel", | |||||
| items = core.kernelList, | |||||
| name = function(idx, choice, all_choices) | |||||
| if #all_choices == 0 then | |||||
| return color.highlight(MSG_K()) .. MSG_ERNEL_ | |||||
| -- return "Kernel: " | |||||
| end | |||||
| local is_default = (idx == 1) | |||||
| local kernel_name = "" | |||||
| local name_color | |||||
| if is_default then | |||||
| name_color = color.escapefg(color.GREEN) | |||||
| kernel_name = "default/" | |||||
| else | |||||
| name_color = color.escapefg(color.BLUE) | |||||
| end | |||||
| kernel_name = kernel_name .. name_color .. | |||||
| choice .. color.resetfg() | |||||
| -- MSG_ERNEL_ ="ernel Selection: " | |||||
| return color.highlight(MSG_K()) .. MSG_ERNEL_ .. kernel_name .. " ("..idx.." of "..#all_choices..")" | |||||
| end, | |||||
| func = function(_, choice, _) | |||||
| if loader.getenv("kernelname") ~= nil then | |||||
| loader.perform("unload") | |||||
| end | |||||
| config.selectKernel(choice) | |||||
| end, | |||||
| alias = {"k", "K"}, | |||||
| }, --end kernel_options | |||||
| boot_options = { | |||||
| entry_type = core.MENU_SUBMENU, | |||||
| name = function() | |||||
| -- MSG_BOOT_ = "Boot " | |||||
| return MSG_BOOT_ .. color.highlight(MSG_O()) .. "ptions" | |||||
| end, | |||||
| submenu = menu.boot_options, | |||||
| alias = {"o", "O"}, | |||||
| }, -- end boot_options | |||||
| zpool_checkpoints = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| local rewind = "No" | |||||
| if core.isRewinded() then | |||||
| rewind = "Yes" | |||||
| end | |||||
| return "Rewind ZFS " .. color.highlight(MSG_C()) .. "heckpoint: " .. rewind | |||||
| end, | |||||
| func = function() | |||||
| core.changeRewindCheckpoint() | |||||
| if core.isRewinded() then | |||||
| bootenvSet( | |||||
| core.bootenvDefaultRewinded()) | |||||
| else | |||||
| bootenvSet(core.bootenvDefault()) | |||||
| end | |||||
| config.setCarouselIndex("be_active", 1) | |||||
| end, | |||||
| visible = function() | |||||
| return core.isZFSBoot() and | |||||
| core.isCheckpointed() | |||||
| end, | |||||
| alias = {"c", "C"}, | |||||
| }, -- end zpool_checkpoints | |||||
| boot_envs = { | |||||
| entry_type = core.MENU_SUBMENU, | |||||
| visible = function() | |||||
| return core.isZFSBoot() and | |||||
| #core.bootenvList() > 1 | |||||
| end, | |||||
| name = MSG_BOOT_ .. color.highlight(MSG_E()).."nvironments", | |||||
| submenu = menu.boot_environments, | |||||
| alias = {"e", "E"}, | |||||
| }, -- end boot_envs | |||||
| chainload = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| name = function() | |||||
| return 'Chain' .. color.highlight(MSG_L()).."oad ".. loader.getenv('chain_disk') | |||||
| end, | |||||
| func = function() | |||||
| loader.perform("chain " .. | |||||
| loader.getenv('chain_disk')) | |||||
| end, | |||||
| visible = function() | |||||
| return loader.getenv('chain_disk') ~= nil | |||||
| end, | |||||
| alias = {"l", "L"}, | |||||
| }, -- end chainload | |||||
| vendor = { | |||||
| entry_type = core.MENU_ENTRY, | |||||
| visible = function() | |||||
| return false | |||||
| end | |||||
| }, -- end vendor | |||||
| }, -- end all_entries | |||||
| } -- end menu.welcome | |||||
| menu.default = menu.welcome | menu.default = menu.welcome | ||||
| -- current_alias_table will be used to keep our alias table consistent across | -- current_alias_table will be used to keep our alias table consistent across | ||||
| Context not available. | |||||
| menu.current_alias_table = {} | menu.current_alias_table = {} | ||||
| function menu.draw(menudef) | function menu.draw(menudef) | ||||
| -- Clear the screen, reset the cursor, then draw | -- Clear the screen, reset the cursor, then draw | ||||
| screen.clear() | screen.clear() | ||||
| menu.current_alias_table = drawer.drawscreen(menudef) | menu.current_alias_table = drawer.drawscreen(menudef) | ||||
| drawn_menu = menudef | drawn_menu = menudef | ||||
| screen.defcursor() | screen.defcursor() | ||||
| end | end -- function menu.draw | ||||
| -- 'keypress' allows the caller to indicate that a key has been pressed that we | -- 'keypress' allows the caller to indicate that a key has been pressed that we | ||||
| -- should process as our initial input. | -- should process as our initial input. | ||||
| function menu.process(menudef, keypress) | function menu.process(menudef, keypress) | ||||
| assert(menudef ~= nil) | assert(menudef ~= nil) | ||||
| if drawn_menu ~= menudef then | if drawn_menu ~= menudef then | ||||
| menu.draw(menudef) | menu.draw(menudef) | ||||
| end | end | ||||
| while true do | while true do | ||||
| local key = keypress or io.getchar() | local key = keypress or io.getchar() | ||||
| keypress = nil | keypress = nil | ||||
| -- Special key behaviors | -- Special key behaviors | ||||
| if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and | if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and | ||||
| menudef ~= menu.default then | menudef ~= menu.default then | ||||
| break | break | ||||
| elseif key == core.KEY_ENTER then | elseif key == core.KEY_ENTER then | ||||
| core.boot() | core.boot() | ||||
| -- Should not return. If it does, escape menu handling | -- Should not return. If it does, escape menu handling | ||||
| -- and drop to loader prompt. | -- and drop to loader prompt. | ||||
| return false | return false | ||||
| end | end | ||||
| key = string.char(key) | key = string.char(key) | ||||
| -- check to see if key is an alias | -- check to see if key is an alias | ||||
| local sel_entry = nil | local sel_entry = nil | ||||
| for k, v in pairs(menu.current_alias_table) do | for k, v in pairs(menu.current_alias_table) do | ||||
| if key == k then | if key == k then | ||||
| sel_entry = v | sel_entry = v | ||||
| break | break | ||||
| end | end | ||||
| end | end -- end for | ||||
| -- if we have an alias do the assigned action: | -- if we have an alias do the assigned action: | ||||
| if sel_entry ~= nil then | if sel_entry ~= nil then | ||||
| local handler = menu.handlers[sel_entry.entry_type] | local handler = menu.handlers[sel_entry.entry_type] | ||||
| assert(handler ~= nil) | assert(handler ~= nil) | ||||
| -- The handler's return value indicates if we | -- The handler's return value indicates if we | ||||
| -- need to exit this menu. An omitted or true | -- need to exit this menu. An omitted or true | ||||
| -- return value means to continue. | -- return value means to continue. | ||||
| if handler(menudef, sel_entry) == false then | if handler(menudef, sel_entry) == false then | ||||
| return | return | ||||
| end | end | ||||
| -- If we got an alias key the screen is out of date... | -- If we got an alias key the screen is out of date... | ||||
| -- redraw it. | -- redraw it. | ||||
| menu.draw(menudef) | menu.draw(menudef) | ||||
| end | end | ||||
| end | end -- end while | ||||
| end | |||||
| end -- function menu.process | |||||
| function menu.run() | function menu.run() | ||||
| local autoboot_key | local autoboot_key | ||||
| local delay = loader.getenv("autoboot_delay") | local delay = loader.getenv("autoboot_delay") | ||||
| if delay ~= nil and delay:lower() == "no" then | if delay ~= nil and delay:lower() == "no" then | ||||
| delay = nil | delay = nil | ||||
| else | else | ||||
| delay = tonumber(delay) or 10 | delay = tonumber(delay) or 10 | ||||
| end | end | ||||
| if delay == -1 then | if delay == -1 then | ||||
| core.boot() | core.boot() | ||||
| return | return | ||||
| end | end | ||||
| menu.draw(menu.default) | menu.draw(menu.default) | ||||
| if delay ~= nil then | if delay ~= nil then | ||||
| autoboot_key = menu.autoboot(delay) | autoboot_key = menu.autoboot(delay) | ||||
| -- autoboot_key should return the key pressed. It will only | -- autoboot_key should return the key pressed. It will only | ||||
| -- return nil if we hit the timeout and executed the timeout | -- return nil if we hit the timeout and executed the timeout | ||||
| -- command. Bail out. | -- command. Bail out. | ||||
| if autoboot_key == nil then | if autoboot_key == nil then | ||||
| return | return | ||||
| end | end | ||||
| end | end | ||||
| menu.process(menu.default, autoboot_key) | menu.process(menu.default, autoboot_key) | ||||
| drawn_menu = nil | drawn_menu = nil | ||||
| screen.defcursor() | screen.defcursor() | ||||
| print("Exiting menu!") | print("Exiting menu!") | ||||
| end | end -- function menu.run | ||||
| function menu.autoboot(delay) | function menu.autoboot(delay) | ||||
| local x = loader.getenv("loader_menu_timeout_x") or 4 | local x = loader.getenv("loader_menu_timeout_x") or 4 | ||||
| local y = loader.getenv("loader_menu_timeout_y") or 23 | local y = loader.getenv("loader_menu_timeout_y") or 23 | ||||
| local endtime = loader.time() + delay | local endtime = loader.time() + delay | ||||
| local time | local time | ||||
| local last | local last | ||||
| repeat | repeat | ||||
| time = endtime - loader.time() | time = endtime - loader.time() | ||||
| if last == nil or last ~= time then | if last == nil or last ~= time then | ||||
| last = time | last = time | ||||
| screen.setcursor(x, y) | |||||
| print("Autoboot in " .. time .. | screen.setcursor(x, y) | ||||
| " seconds. [Space] to pause ") | print("Autoboot in " .. time .. " seconds. [" .. color.highlight(color.escapefg(color.RED) .. MSG_SPACE .. color.resetfg()) .. "] to pause ") | ||||
| screen.defcursor() | screen.defcursor() | ||||
| end | end | ||||
| if io.ischar() then | |||||
| local ch = io.getchar() | if io.ischar() then | ||||
| if ch == core.KEY_ENTER then | local ch = io.getchar() | ||||
| break | if ch == core.KEY_ENTER then | ||||
| else | break | ||||
| -- erase autoboot msg | else | ||||
| screen.setcursor(0, y) | -- erase autoboot msg | ||||
| print(string.rep(" ", 80)) | screen.setcursor(0, y) | ||||
| screen.defcursor() | print(string.rep(" ", 80)) | ||||
| return ch | screen.defcursor() | ||||
| end | return ch | ||||
| end | end | ||||
| end | |||||
| loader.delay(50000) | |||||
| until time <= 0 | loader.delay(50000) | ||||
| until time <= 0 | |||||
| local cmd = loader.getenv("menu_timeout_command") or "boot" | |||||
| cli_execute_unparsed(cmd) | local cmd = loader.getenv("menu_timeout_command") or "boot" | ||||
| return nil | cli_execute_unparsed(cmd) | ||||
| end | return nil | ||||
| end -- end function menu.autoboot | |||||
| -- CLI commands | -- CLI commands | ||||
| function cli.menu() | function cli.menu() | ||||
| menu.run() | menu.run() | ||||
| end | end | ||||
| return menu | return menu | ||||
| Context not available. | |||||
I'll let others comment on all the other changes rather than sharing my own thoughts which I know are shared, but this breaks making the message configurable, as done for installer images (which you can see in the fact that your SmartixOS installer says [B]oot into Multi user rather than [B]oot Installer like FreeBSD's.