From owner-svn-src-head@freebsd.org Sun Feb 25 04:11: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 D9A81F003A6; Sun, 25 Feb 2018 04:11:08 +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 8FC8F6817B; Sun, 25 Feb 2018 04:11:08 +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 71EB32F77A; Sun, 25 Feb 2018 04:11:08 +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 w1P4B8RR018457; Sun, 25 Feb 2018 04:11:08 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1P4B83s018456; Sun, 25 Feb 2018 04:11:08 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802250411.w1P4B83s018456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sun, 25 Feb 2018 04:11:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329946 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329946 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: Sun, 25 Feb 2018 04:11:09 -0000 Author: kevans Date: Sun Feb 25 04:11:08 2018 New Revision: 329946 URL: https://svnweb.freebsd.org/changeset/base/329946 Log: lualoader: Clean up menu handling a little bit This is driven by an urge to separate out the bits that really only need to happen when the menu system starts up. Key points: - menu.process now does the bulk of menu handling. It retains autoboot handling for dubious reasons, and it no longer accepts a 'nil' menu to process as 'the default'. Its return value is insignificant. - The MENU_SUBMENU handler now returns nothing. If menu.process has exited, then we continue processing menu items on the parent menu as expected. - menu.run is now the entry point of the menu system. It checks whether the menu should be skipped, processes the default menu, then returns. Modified: head/stand/lua/menu.lua Modified: head/stand/lua/menu.lua ============================================================================== --- head/stand/lua/menu.lua Sun Feb 25 03:33:25 2018 (r329945) +++ head/stand/lua/menu.lua Sun Feb 25 04:11:08 2018 (r329946) @@ -81,7 +81,7 @@ menu.handlers = { end, [core.MENU_SUBMENU] = function(_, entry) -- recurse - return menu.run(entry.submenu) + menu.process(entry.submenu) end, [core.MENU_RETURN] = function(_, entry) -- allow entry to have a function/side effect @@ -342,29 +342,24 @@ menu.welcome = { menu.default = menu.welcome -function menu.run(m) - - if menu.skip() then - core.autoboot() - return false - end - - if m == nil then - m = menu.default - end - +function menu.process(m) + assert(m ~= nil) -- redraw screen screen.clear() screen.defcursor() local alias_table = drawer.drawscreen(m) - -- Might return nil, that's ok + -- autoboot processing likely belongs better in menu.run, but we want + -- to draw the menu once before we do any autoboot prompting. We also + -- collect the alias table from the drawer, which generates the table + -- based on all of the 'alias' entries along with effective line numbers + -- that each entry is drawn at. This makes it cleaner to handle here, + -- for the time being. local autoboot_key; if m == menu.default then autoboot_key = menu.autoboot() end - local cont = true - while cont do + while true do local key = autoboot_key or io.getchar() autoboot_key = nil @@ -391,12 +386,11 @@ function menu.run(m) -- Get menu handler local handler = menu.handlers[sel_entry.entry_type] if handler ~= nil then - -- The handler's return value indicates whether - -- we need to exit this menu. An omitted return - -- value means "continue" by default. - cont = handler(m, sel_entry) - if cont == nil then - cont = true + -- The handler's return value indicates if we + -- need to exit this menu. An omitted or true + -- return value means to continue. + if handler(m, sel_entry) == false then + return end end -- if we got an alias key the screen is out of date: @@ -405,14 +399,18 @@ function menu.run(m) alias_table = drawer.drawscreen(m) end end +end - if m == menu.default then - screen.defcursor() - print("Exiting menu!") - return false +function menu.run() + if menu.skip() then + core.autoboot() + return end - return true + menu.process(menu.default) + + screen.defcursor() + print("Exiting menu!") end function menu.skip()