From owner-svn-src-all@freebsd.org Mon Feb 19 17:40:20 2018 Return-Path: Delivered-To: svn-src-all@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 0AB6DF143F3; Mon, 19 Feb 2018 17:40:20 +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 B550881ACF; Mon, 19 Feb 2018 17:40:19 +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 ABDAC1DA45; Mon, 19 Feb 2018 17:40:19 +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 w1JHeJt6036981; Mon, 19 Feb 2018 17:40:19 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1JHeJif036979; Mon, 19 Feb 2018 17:40:19 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802191740.w1JHeJif036979@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 19 Feb 2018 17:40:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329593 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329593 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Feb 2018 17:40:20 -0000 Author: kevans Date: Mon Feb 19 17:40:19 2018 New Revision: 329593 URL: https://svnweb.freebsd.org/changeset/base/329593 Log: stand/lua: Change boot menu items' names when swapped [Enter] should be moved to the single user menu item when we swap them. Define a non-standard menu entry function "alternate_name" to use for this purpose for ultimate flexibility if we change our minds later. When we're booting single user, make a shallow copy of the menu that we'd normally display and swap the items and their name functions to use alternate_name instead. Toggling single user in the options menu and going back to the main menu will now correctly reflect the current boot setting with the first two menu options and "[Enter]" will always be on the right one. This shallow copy technique has the chance of being quite slow since it's done on every redraw, but in my testing it does not seem to make any obvious difference. shallowCopyTable could likely belong better in a general-purpose utility module, but this (and the key constnats) are the only candidates we have at the moment so we'll drop it into our core stuff for the moment and consider re-organization at a later date. Modified: head/stand/lua/core.lua head/stand/lua/menu.lua Modified: head/stand/lua/core.lua ============================================================================== --- head/stand/lua/core.lua Mon Feb 19 17:09:29 2018 (r329592) +++ head/stand/lua/core.lua Mon Feb 19 17:40:19 2018 (r329593) @@ -217,5 +217,18 @@ function core.isSerialBoot() return false; end +-- This may be a better candidate for a 'utility' module. +function core.shallowCopyTable(tbl) + local new_tbl = {}; + for k, v in pairs(tbl) do + if (type(v) == "table") then + new_tbl[k] = core.shallowCopyTable(v); + else + new_tbl[k] = v; + end + end + return new_tbl; +end + core.setACPI(core.getACPIPresent(false)); return core; Modified: head/stand/lua/menu.lua ============================================================================== --- head/stand/lua/menu.lua Mon Feb 19 17:09:29 2018 (r329592) +++ head/stand/lua/menu.lua Mon Feb 19 17:40:19 2018 (r329593) @@ -137,9 +137,15 @@ menu.welcome = { local menu_entries = menu.welcome.all_entries; -- Swap the first two menu items on single user boot if (core.isSingleUserBoot()) then + -- Shallow copy the table + menu_entries = core.shallowCopyTable(menu_entries); + local multiuser = menu_entries[1]; local singleuser = menu_entries[2]; + multiuser.name = multiuser.alternate_name; + singleuser.name = singleuser.alternate_name; + menu_entries[2] = multiuser; menu_entries[1] = singleuser; end @@ -154,6 +160,11 @@ menu.welcome = { "oot Multi user " .. color.highlight("[Enter]"); end, + -- Not a standard menu entry function! + alternate_name = function() + return color.highlight("B") .. + "oot Multi user"; + end, func = function() core.setSingleUser(false); core.boot(); @@ -167,6 +178,11 @@ menu.welcome = { name = function() return "Boot " .. color.highlight("S") .. "ingle user"; + end, + -- Not a standard menu entry function! + alternate_name = function() + return "Boot " .. color.highlight("S") .. + "ingle user " .. color.highlight("[Enter]"); end, func = function() core.setSingleUser(true);