xref: /freebsd/stand/lua/menu.lua.8 (revision f520b4afd25338872e8e73b0d259820fe83a1438)
1*f520b4afSKyle Evans.\"
2*f520b4afSKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*f520b4afSKyle Evans.\"
4*f520b4afSKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
5*f520b4afSKyle Evans.\" All rights reserved.
6*f520b4afSKyle Evans.\"
7*f520b4afSKyle Evans.\" Redistribution and use in source and binary forms, with or without
8*f520b4afSKyle Evans.\" modification, are permitted provided that the following conditions
9*f520b4afSKyle Evans.\" are met:
10*f520b4afSKyle Evans.\" 1. Redistributions of source code must retain the above copyright
11*f520b4afSKyle Evans.\"    notice, this list of conditions and the following disclaimer.
12*f520b4afSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright
13*f520b4afSKyle Evans.\"    notice, this list of conditions and the following disclaimer in the
14*f520b4afSKyle Evans.\"    documentation and/or other materials provided with the distribution.
15*f520b4afSKyle Evans.\"
16*f520b4afSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*f520b4afSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*f520b4afSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*f520b4afSKyle Evans.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*f520b4afSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*f520b4afSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*f520b4afSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*f520b4afSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*f520b4afSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*f520b4afSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*f520b4afSKyle Evans.\" SUCH DAMAGE.
27*f520b4afSKyle Evans.\"
28*f520b4afSKyle Evans.\" $FreeBSD$
29*f520b4afSKyle Evans.\"
30*f520b4afSKyle Evans.Dd February 23, 2018
31*f520b4afSKyle Evans.Dt MENU.LUA 8
32*f520b4afSKyle Evans.Os
33*f520b4afSKyle Evans.Sh NAME
34*f520b4afSKyle Evans.Nm menu.lua
35*f520b4afSKyle Evans.Nd FreeBSD dynamic menu boot module
36*f520b4afSKyle Evans.Sh DESCRIPTION
37*f520b4afSKyle Evans.Nm
38*f520b4afSKyle Evanscontains the main functionality required to build a dynamic menu system.
39*f520b4afSKyle EvansIt also contains definitions for the built-in menus, some of which are
40*f520b4afSKyle Evansinfluenced by
41*f520b4afSKyle Evans.Xr loader 8
42*f520b4afSKyle Evansenvironment variables.
43*f520b4afSKyle Evans.Pp
44*f520b4afSKyle EvansBefore hooking into the functionality provided by
45*f520b4afSKyle Evans.Nm ,
46*f520b4afSKyle Evansit must be included with a statement such as the following:
47*f520b4afSKyle Evans.Pp
48*f520b4afSKyle Evans.Dl local menu = require("menu")
49*f520b4afSKyle Evans.Ss MENU DEFINITIONS
50*f520b4afSKyle EvansMenus are represented in
51*f520b4afSKyle Evans.Nm
52*f520b4afSKyle Evansas a table.
53*f520b4afSKyle EvansThat table
54*f520b4afSKyle Evans.Sy must
55*f520b4afSKyle Evanscontain an
56*f520b4afSKyle Evans.Va entries
57*f520b4afSKyle Evanskey.
58*f520b4afSKyle Evans.Pp
59*f520b4afSKyle EvansIf the value of the
60*f520b4afSKyle Evans.Va entries
61*f520b4afSKyle Evanskey is itself a table, then each value in this table defines a single entry in
62*f520b4afSKyle Evansthis menu.
63*f520b4afSKyle EvansSee
64*f520b4afSKyle Evans.Sx MENU ITEM DEFINITIONS
65*f520b4afSKyle Evansfor the structure of each entry.
66*f520b4afSKyle Evans.Pp
67*f520b4afSKyle Evans.Va entries
68*f520b4afSKyle Evansmay also be a function.
69*f520b4afSKyle EvansThis function must return a table, each value of which defines a single entry
70*f520b4afSKyle Evansin this menu.
71*f520b4afSKyle EvansSee
72*f520b4afSKyle Evans.Sx MENU ITEM DEFINITIONS .
73*f520b4afSKyle Evans.Ss MENU ITEM DEFINITIONS
74*f520b4afSKyle EvansThe following keys may be defined for a menu item:
75*f520b4afSKyle Evans.Bl -tag -width disable-module_module -offset indent
76*f520b4afSKyle Evans.It Ic entry_type
77*f520b4afSKyle EvansThe type of this menu entry.
78*f520b4afSKyle EvansSee
79*f520b4afSKyle Evans.Sx MENU ITEM TYPES .
80*f520b4afSKyle Evans.It Ic carousel_id
81*f520b4afSKyle EvansA unique string id for this carousel.
82*f520b4afSKyle EvansA carousel is a menu entry that rotates through a selection of items.
83*f520b4afSKyle EvansUsed for storage of the carousel's current setting.
84*f520b4afSKyle Evans.It Ic visible
85*f520b4afSKyle EvansA lambda that returns
86*f520b4afSKyle Evans.Dv true
87*f520b4afSKyle Evansif this menu item should be visible and
88*f520b4afSKyle Evans.Dv false
89*f520b4afSKyle Evansif it should not be visible.
90*f520b4afSKyle Evans.It Ic items
91*f520b4afSKyle EvansA table (or a lambda that returns a table) of the possible choices for this
92*f520b4afSKyle Evanscarousel.
93*f520b4afSKyle Evans.It Ic name
94*f520b4afSKyle EvansA string (or a lambda that returns a string) containing the current name of this
95*f520b4afSKyle Evansitem.
96*f520b4afSKyle Evans.It Ic func
97*f520b4afSKyle EvansThe function executed when this entry is selected.
98*f520b4afSKyle EvansEvery type except for
99*f520b4afSKyle Evans.Ic core.MENU_SEPARATOR
100*f520b4afSKyle Evansmay have a
101*f520b4afSKyle Evans.Ic func .
102*f520b4afSKyle Evans.It Ic submenu
103*f520b4afSKyle EvansThe submenu menu definition to draw when this entry is selected.
104*f520b4afSKyle Evans.It Ic alias
105*f520b4afSKyle EvansA table of case-sensitive aliases for this menu entry.
106*f520b4afSKyle EvansAll menu entries that can be selected may have any number of
107*f520b4afSKyle Evans.Ic alias
108*f520b4afSKyle Evansentries.
109*f520b4afSKyle Evans.El
110*f520b4afSKyle Evans.Pp
111*f520b4afSKyle Evans.Ic entry_type
112*f520b4afSKyle Evansis the only required key for every entry type.
113*f520b4afSKyle Evans.Ic name
114*f520b4afSKyle Evansis required for all entry types except for
115*f520b4afSKyle Evans.Ic core.MENU_SEPARATOR .
116*f520b4afSKyle Evans.Ss MENU ITEM TYPES
117*f520b4afSKyle EvansThe menu item type constants are defined in
118*f520b4afSKyle Evans.Xr core.lua 8 .
119*f520b4afSKyle EvansThe following types are available:
120*f520b4afSKyle Evans.Bl -tag -width core.MENU_CAROUSEL_ENTRY -offset indent
121*f520b4afSKyle Evans.It Ic core.MENU_RETURN
122*f520b4afSKyle EvansReturn to the parent menu.
123*f520b4afSKyle EvansIf the current menu is the default menu,
124*f520b4afSKyle Evans.Nm
125*f520b4afSKyle Evanswill exit the menu and begin the autoboot sequence (if applicable).
126*f520b4afSKyle EvansThis type of menu entry may execute
127*f520b4afSKyle Evans.Ic func ,
128*f520b4afSKyle Evanswhen selected, and has a
129*f520b4afSKyle Evans.Ic name .
130*f520b4afSKyle Evans.It Ic core.MENU_ENTRY
131*f520b4afSKyle EvansA normal menu entry that executes
132*f520b4afSKyle Evans.Ic func
133*f520b4afSKyle Evanswhen selected, and has a
134*f520b4afSKyle Evans.Ic name .
135*f520b4afSKyle Evans.It Ic core.MENU_SEPARATOR
136*f520b4afSKyle EvansA menu entry that serves as a separator.
137*f520b4afSKyle EvansIt may have a
138*f520b4afSKyle Evans.Ic name .
139*f520b4afSKyle Evans.It Ic core.MENU_SUBMENU
140*f520b4afSKyle EvansA menu entry that opens
141*f520b4afSKyle Evans.Ic submenu
142*f520b4afSKyle Evanswhen selected.
143*f520b4afSKyle EvansIt may have a
144*f520b4afSKyle Evans.Ic name .
145*f520b4afSKyle Evans.It Ic core.MENU_CAROUSEL_ENTRY
146*f520b4afSKyle EvansA menu entry that rotates through
147*f520b4afSKyle Evans.Ic items
148*f520b4afSKyle Evanslike a carousel.
149*f520b4afSKyle Evans.Ic func
150*f520b4afSKyle Evansis executed when selected, and the callback is passed the choice index, name of
151*f520b4afSKyle Evansthe current choice, and the table of choices.
152*f520b4afSKyle Evans.El
153*f520b4afSKyle Evans.Ss EXPORTED MENUS
154*f520b4afSKyle EvansThe following menus are exported by
155*f520b4afSKyle Evans.Nm :
156*f520b4afSKyle Evans.Bl -tag -width menu.boot_environments -offset indent
157*f520b4afSKyle Evans.It Ic menu.default
158*f520b4afSKyle EvansThe default menu to draw.
159*f520b4afSKyle EvansSet to
160*f520b4afSKyle Evans.Ic menu.welcome
161*f520b4afSKyle Evansby default.
162*f520b4afSKyle Evans.It Ic menu.welcome
163*f520b4afSKyle EvansThe welcome menu.
164*f520b4afSKyle EvansContains single and multi user boot options, as well as entries to access other
165*f520b4afSKyle Evansmenus.
166*f520b4afSKyle Evans.It Ic menu.boot_options
167*f520b4afSKyle EvansThe "Boot Options" menu.
168*f520b4afSKyle Evans.It Ic menu.boot_environments
169*f520b4afSKyle EvansThe "Boot Environments" menu.
170*f520b4afSKyle EvansThis menu is only visible if the system is booted on a ZFS partition and more
171*f520b4afSKyle Evansthan one boot environment was detected at boot.
172*f520b4afSKyle Evans.El
173*f520b4afSKyle Evans.Sh EXAMPLES
174*f520b4afSKyle EvansTo replace the default boot menu with a simple boot menu:
175*f520b4afSKyle Evans.Pp
176*f520b4afSKyle Evans.Bd -literal -offset indent -compact
177*f520b4afSKyle Evanslocal core = require("core")
178*f520b4afSKyle Evanslocal menu = require("menu")
179*f520b4afSKyle Evans
180*f520b4afSKyle Evansmenu.default = {
181*f520b4afSKyle Evans	entries = {
182*f520b4afSKyle Evans		{
183*f520b4afSKyle Evans			entry_type = core.MENU_ENTRY,
184*f520b4afSKyle Evans			name = "Boot",
185*f520b4afSKyle Evans			func = core.boot,
186*f520b4afSKyle Evans		},
187*f520b4afSKyle Evans		{
188*f520b4afSKyle Evans			entry_type = core.MENU_CAROUSEL_ENTRY,
189*f520b4afSKyle Evans			carousel_id = "unique_boot_entry_name",
190*f520b4afSKyle Evans			items = {"NO", "YES"},
191*f520b4afSKyle Evans			name = function(_, choice, _)
192*f520b4afSKyle Evans				return "Option: " .. choice
193*f520b4afSKyle Evans			end,
194*f520b4afSKyle Evans			func = function(_, _, _)
195*f520b4afSKyle Evans				loader.setenv("some_envvar", "some_value")
196*f520b4afSKyle Evans			end,
197*f520b4afSKyle Evans		},
198*f520b4afSKyle Evans	},
199*f520b4afSKyle Evans}
200*f520b4afSKyle Evans.Ed
201*f520b4afSKyle Evans.Pp
202*f520b4afSKyle EvansTo add another option to the welcome menu:
203*f520b4afSKyle Evans.Pp
204*f520b4afSKyle Evans.Bd -literal -offset indent -compact
205*f520b4afSKyle Evanslocal core = require("core")
206*f520b4afSKyle Evanslocal menu = require("menu")
207*f520b4afSKyle Evans
208*f520b4afSKyle Evanslocal welcome_entries = menu.welcome.all_entries
209*f520b4afSKyle Evanswelcome_entries[#welcome_entries + 1] = {
210*f520b4afSKyle Evans	entry_type = core.MENU_CAROUSEL_ENTRY,
211*f520b4afSKyle Evans	carousel_id = "unique_boot_entry_name",
212*f520b4afSKyle Evans	items = {"NO", "YES"},
213*f520b4afSKyle Evans	name = function(_, choice, _)
214*f520b4afSKyle Evans		return "Option: " .. choice
215*f520b4afSKyle Evans	end,
216*f520b4afSKyle Evans	func = function(_, _, _)
217*f520b4afSKyle Evans		loader.setenv("some_envvar", "some_value")
218*f520b4afSKyle Evans	end,
219*f520b4afSKyle Evans}
220*f520b4afSKyle Evans.Ed
221*f520b4afSKyle Evans.Sh SEE ALSO
222*f520b4afSKyle Evans.Xr loader.conf 5 ,
223*f520b4afSKyle Evans.Xr core.lua 8 ,
224*f520b4afSKyle Evans.Xr loader 8
225*f520b4afSKyle Evans.Sh HISTORY
226*f520b4afSKyle EvansThe
227*f520b4afSKyle Evans.Nm
228*f520b4afSKyle Evansfile first appeared in
229*f520b4afSKyle Evans.Fx 12.0 .
230*f520b4afSKyle Evans.Sh AUTHORS
231*f520b4afSKyle EvansThe
232*f520b4afSKyle Evans.Nm
233*f520b4afSKyle Evansfile was originally written by
234*f520b4afSKyle Evans.An Pedro Souza Aq Mt pedrosouza@FreeBSD.org .
235*f520b4afSKyle EvansLater work and this manual page was done by
236*f520b4afSKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org .
237