stand/lua: Create/use some MENU_ constants where applicable

This commit is contained in:
Kyle Evans 2018-02-16 14:57:42 +00:00
parent ada26c4a88
commit a7cf056239
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329368
3 changed files with 33 additions and 25 deletions

View File

@ -29,10 +29,16 @@
local core = {};
-- Commonly appearing constants
core.KEY_ENTER = 13;
core.KEY_BACKSPACE = 127;
core.KEY_ENTER = 13;
core.KEY_BACKSPACE = 127;
core.KEYSTR_ESCAPE = "\027";
core.KEYSTR_ESCAPE = "\027";
core.MENU_RETURN = "return";
core.MENU_ENTRY = "entry";
core.MENU_SEPARATOR = "separator";
core.MENU_SUBMENU = "submenu";
core.MENU_CAROUSEL_ENTRY = "carousel_entry";
function core.setVerbose(b)
if (b == nil) then
@ -119,6 +125,7 @@ function core.kernelList()
local k = loader.getenv("kernel");
local v = loader.getenv("kernels") or "";
v = "kernel;kernel.GENERIC"
local kernels = {};
local i = 0;
if k ~= nil then

View File

@ -29,6 +29,7 @@
local drawer = {};
local color = require("color");
local core = require("core");
local screen = require("screen");
drawer.brand_position = {x = 2, y = 1};
@ -166,12 +167,12 @@ function drawer.drawmenu(m)
local alias_table = {};
local entry_num = 0;
for line_num, e in ipairs(m) do
if (e.entry_type ~= "separator") then
if (e.entry_type ~= core.MENU_SEPARATOR) then
entry_num = entry_num + 1;
screen.setcursor(x, y + line_num);
local name = "";
if (e.entry_type == "carousel_entry") then
if (e.entry_type == core.MENU_CAROUSEL_ENTRY) then
local carid = e.carousel_id;
local caridx = menu.getCarouselIndex(carid);
local choices = e.items();

View File

@ -50,7 +50,7 @@ local welcome;
menu.boot_options = {
-- return to welcome menu
{
entry_type = "return",
entry_type = core.MENU_RETURN,
name = function()
return "Back to main menu"..color.highlight(" [Backspace]");
end
@ -58,7 +58,7 @@ menu.boot_options = {
-- load defaults
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return "Load System "..color.highlight("D").."efaults";
end,
@ -69,14 +69,14 @@ menu.boot_options = {
},
{
entry_type = "separator",
entry_type = core.MENU_SEPARATOR,
name = function()
return "";
end
},
{
entry_type = "separator",
entry_type = core.MENU_SEPARATOR,
name = function()
return "Boot Options:";
end
@ -84,7 +84,7 @@ menu.boot_options = {
-- acpi
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return OnOff(color.highlight("A").."CPI :", core.acpi);
end,
@ -95,7 +95,7 @@ menu.boot_options = {
},
-- safe mode
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return OnOff("Safe "..color.highlight("M").."ode :", core.sm);
end,
@ -106,7 +106,7 @@ menu.boot_options = {
},
-- single user
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return OnOff(color.highlight("S").."ingle user:", core.su);
end,
@ -117,7 +117,7 @@ menu.boot_options = {
},
-- verbose boot
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return OnOff(color.highlight("V").."erbose :", core.verbose);
end,
@ -131,7 +131,7 @@ menu.boot_options = {
menu.welcome = {
-- boot multi user
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return color.highlight("B").."oot Multi user "..color.highlight("[Enter]");
end,
@ -144,7 +144,7 @@ menu.welcome = {
-- boot single user
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return "Boot "..color.highlight("S").."ingle user";
end,
@ -157,7 +157,7 @@ menu.welcome = {
-- escape to interpreter
{
entry_type = "return",
entry_type = core.MENU_RETURN,
name = function()
return color.highlight("Esc").."ape to loader prompt";
end,
@ -166,7 +166,7 @@ menu.welcome = {
-- reboot
{
entry_type = "entry",
entry_type = core.MENU_ENTRY,
name = function()
return color.highlight("R").."eboot";
end,
@ -178,14 +178,14 @@ menu.welcome = {
{
entry_type = "separator",
entry_type = core.MENU_SEPARATOR,
name = function()
return "";
end
},
{
entry_type = "separator",
entry_type = core.MENU_SEPARATOR,
name = function()
return "Options:";
end
@ -193,7 +193,7 @@ menu.welcome = {
-- kernel options
{
entry_type = "carousel_entry",
entry_type = core.MENU_CAROUSEL_ENTRY,
carousel_id = "kernel",
items = core.kernelList,
name = function(idx, choice, all_choices)
@ -218,7 +218,7 @@ menu.welcome = {
-- boot options
{
entry_type = "submenu",
entry_type = core.MENU_SUBMENU,
name = function()
return "Boot "..color.highlight("O").."ptions";
end,
@ -284,10 +284,10 @@ function menu.run(m)
-- if we have an alias do the assigned action:
if(sel_entry ~= nil) then
if (sel_entry.entry_type == "entry") then
if (sel_entry.entry_type == core.MENU_ENTRY) then
-- run function
sel_entry.func();
elseif (sel_entry.entry_type == "carousel_entry") then
elseif (sel_entry.entry_type == core.MENU_CAROUSEL_ENTRY) then
-- carousel (rotating) functionality
local carid = sel_entry.carousel_id;
local caridx = menu.getCarouselIndex(carid);
@ -296,10 +296,10 @@ function menu.run(m)
caridx = (caridx % #choices) + 1;
menu.setCarouselIndex(carid, caridx);
sel_entry.func(choices[caridx]);
elseif (sel_entry.entry_type == "submenu") then
elseif (sel_entry.entry_type == core.MENU_SUBMENU) then
-- recurse
cont = menu.run(sel_entry.submenu());
elseif (sel_entry.entry_type == "return") then
elseif (sel_entry.entry_type == core.MENU_RETURN) then
-- break recurse
cont = false;
end