svn commit: r329645 - head/stand/lua
Kyle Evans
kevans at FreeBSD.org
Tue Feb 20 18:04:09 UTC 2018
Author: kevans
Date: Tue Feb 20 18:04:08 2018
New Revision: 329645
URL: https://svnweb.freebsd.org/changeset/base/329645
Log:
lualoader: Move carousel storage out into config
Carousel storage doesn't need to happen in the menu module, and indeed
storing it there introduces a circular reference between drawer and menu
that only works because of global pollution in loader.lua.
Carousel choices generally map to config entries anyways, making it as good
of place as any to store these. Move {get,set}CarouselIndex functionality
out into config so that drawer and menu may both use it. If we had more
carousel functionality, it might make sense to create a carousel module, but
this is not the case.
Modified:
head/stand/lua/config.lua
head/stand/lua/drawer.lua
head/stand/lua/menu.lua
Modified: head/stand/lua/config.lua
==============================================================================
--- head/stand/lua/config.lua Tue Feb 20 17:46:50 2018 (r329644)
+++ head/stand/lua/config.lua Tue Feb 20 18:04:08 2018 (r329645)
@@ -31,7 +31,10 @@ local config = {};
local modules = {};
-local pattern_table = {
+local pattern_table;
+local carousel_choices = {};
+
+pattern_table = {
[1] = {
str = "^%s*(#.*)",
process = function(k, v) end
@@ -124,6 +127,19 @@ local pattern_table = {
config.env_changed = {};
-- Values to restore env to (nil to unset)
config.env_restore = {};
+
+-- The first item in every carousel is always the default item.
+function config.getCarouselIndex(id)
+ local val = carousel_choices[id];
+ if (val == nil) then
+ return 1;
+ end
+ return val;
+end
+
+function config.setCarouselIndex(id, idx)
+ carousel_choices[id] = idx;
+end
function config.restoreEnv()
for k, v in pairs(config.env_changed) do
Modified: head/stand/lua/drawer.lua
==============================================================================
--- head/stand/lua/drawer.lua Tue Feb 20 17:46:50 2018 (r329644)
+++ head/stand/lua/drawer.lua Tue Feb 20 18:04:08 2018 (r329645)
@@ -28,6 +28,7 @@
--
local color = require("color");
+local config = require("config");
local core = require("core");
local screen = require("screen");
@@ -176,7 +177,7 @@ drawer.menu_name_handlers = {
-- types not specified here is to call and use entry.name().
[core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry)
local carid = entry.carousel_id;
- local caridx = menu.getCarouselIndex(carid);
+ local caridx = config.getCarouselIndex(carid);
local choices = entry.items();
if (#choices < caridx) then
Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua Tue Feb 20 17:46:50 2018 (r329644)
+++ head/stand/lua/menu.lua Tue Feb 20 18:04:08 2018 (r329645)
@@ -39,7 +39,6 @@ local menu = {};
local skip;
local run;
local autoboot;
-local carousel_choices = {};
local OnOff = function(str, b)
if (b) then
@@ -65,12 +64,12 @@ menu.handlers = {
[core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry)
-- carousel (rotating) functionality
local carid = entry.carousel_id;
- local caridx = menu.getCarouselIndex(carid);
+ local caridx = config.getCarouselIndex(carid);
local choices = entry.items();
if (#choices > 0) then
caridx = (caridx % #choices) + 1;
- menu.setCarouselIndex(carid, caridx);
+ config.setCarouselIndex(carid, caridx);
entry.func(caridx, choices[caridx], choices);
end
end,
@@ -326,19 +325,6 @@ menu.welcome = {
},
},
};
-
--- The first item in every carousel is always the default item.
-function menu.getCarouselIndex(id)
- local val = carousel_choices[id];
- if (val == nil) then
- return 1;
- end
- return val;
-end
-
-function menu.setCarouselIndex(id, idx)
- carousel_choices[id] = idx;
-end
function menu.run(m)
More information about the svn-src-all
mailing list