From owner-svn-src-head@freebsd.org Tue Feb 20 18:04:09 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7EA12F1ACAC; Tue, 20 Feb 2018 18:04:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2958683856; Tue, 20 Feb 2018 18:04:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 244EA5175; Tue, 20 Feb 2018 18:04:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1KI49hw074404; Tue, 20 Feb 2018 18:04:09 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1KI48I3074401; Tue, 20 Feb 2018 18:04:08 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802201804.w1KI48I3074401@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 20 Feb 2018 18:04:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329645 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329645 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Feb 2018 18:04:09 -0000 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)