Index: stable/12/stand/forth/menu.4th =================================================================== --- stable/12/stand/forth/menu.4th (revision 354009) +++ stable/12/stand/forth/menu.4th (revision 354010) @@ -1,1319 +1,1319 @@ \ Copyright (c) 2003 Scott Long \ Copyright (c) 2003 Aleksander Fafula \ Copyright (c) 2006-2015 Devin Teske \ All rights reserved. \ \ Redistribution and use in source and binary forms, with or without \ modification, are permitted provided that the following conditions \ are met: \ 1. Redistributions of source code must retain the above copyright \ notice, this list of conditions and the following disclaimer. \ 2. Redistributions in binary form must reproduce the above copyright \ notice, this list of conditions and the following disclaimer in the \ documentation and/or other materials provided with the distribution. \ \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF \ SUCH DAMAGE. \ \ $FreeBSD$ marker task-menu.4th \ Frame drawing include /boot/frames.4th vocabulary menu-infrastructure vocabulary menu-namespace vocabulary menu-command-helpers only forth also menu-infrastructure definitions f_double \ Set frames to double (see frames.4th). Replace with \ f_single if you want single frames. 46 constant dot \ ASCII definition of a period (in decimal) 5 constant menu_default_x \ default column position of timeout 10 constant menu_default_y \ default row position of timeout msg 4 constant menu_timeout_default_x \ default column position of timeout 23 constant menu_timeout_default_y \ default row position of timeout msg 10 constant menu_timeout_default \ default timeout (in seconds) \ Customize the following values with care 1 constant menu_start \ Numerical prefix of first menu item dot constant bullet \ Menu bullet (appears after numerical prefix) 5 constant menu_x \ Row position of the menu (from the top) 10 constant menu_y \ Column position of the menu (from left side) \ Menu Appearance variable menuidx \ Menu item stack for number prefixes variable menurow \ Menu item stack for positioning variable menubllt \ Menu item bullet \ Menu Positioning variable menuX \ Menu X offset (columns) variable menuY \ Menu Y offset (rows) \ Menu-item elements variable menurebootadded \ Parsing of kernels into menu-items variable kernidx variable kernlen variable kernmenuidx \ Menu timer [count-down] variables variable menu_timeout_enabled \ timeout state (internal use only) variable menu_time \ variable for tracking the passage of time variable menu_timeout \ determined configurable delay duration variable menu_timeout_x \ column position of timeout message variable menu_timeout_y \ row position of timeout message \ Containers for parsing kernels into menu-items create kerncapbuf 64 allot create kerndefault 64 allot create kernelsbuf 256 allot only forth also menu-namespace definitions \ Menu-item key association/detection variable menukey1 variable menukey2 variable menukey3 variable menukey4 variable menukey5 variable menukey6 variable menukey7 variable menukey8 variable menureboot variable menuacpi variable menuoptions variable menukernel \ Menu initialization status variables variable init_state1 variable init_state2 variable init_state3 variable init_state4 variable init_state5 variable init_state6 variable init_state7 variable init_state8 \ Boolean option status variables variable toggle_state1 variable toggle_state2 variable toggle_state3 variable toggle_state4 variable toggle_state5 variable toggle_state6 variable toggle_state7 variable toggle_state8 \ Array option status variables variable cycle_state1 variable cycle_state2 variable cycle_state3 variable cycle_state4 variable cycle_state5 variable cycle_state6 variable cycle_state7 variable cycle_state8 \ Containers for storing the initial caption text create init_text1 64 allot create init_text2 64 allot create init_text3 64 allot create init_text4 64 allot create init_text5 64 allot create init_text6 64 allot create init_text7 64 allot create init_text8 64 allot only forth definitions : arch-i386? ( -- BOOL ) \ Returns TRUE (-1) on i386, FALSE (0) otherwise. s" arch-i386" environment? dup if drop then ; : acpipresent? ( -- flag ) \ Returns TRUE if ACPI is present, FALSE otherwise s" hint.acpi.0.rsdp" getenv dup -1 = if drop false exit then 2drop true ; : acpienabled? ( -- flag ) \ Returns TRUE if ACPI is enabled, FALSE otherwise s" hint.acpi.0.disabled" getenv dup -1 <> if s" 0" compare 0<> if false exit then else drop then true ; : +c! ( N C-ADDR/U K -- C-ADDR/U ) 3 pick 3 pick ( n c-addr/u k -- n c-addr/u k n c-addr ) rot + c! ( n c-addr/u k n c-addr -- n c-addr/u ) rot drop ( n c-addr/u -- c-addr/u ) ; only forth also menu-namespace definitions \ Forth variables : namespace ( C-ADDR/U N -- ) also menu-namespace +c! evaluate previous ; : menukeyN ( N -- ADDR ) s" menukeyN" 7 namespace ; : init_stateN ( N -- ADDR ) s" init_stateN" 10 namespace ; : toggle_stateN ( N -- ADDR ) s" toggle_stateN" 12 namespace ; : cycle_stateN ( N -- ADDR ) s" cycle_stateN" 11 namespace ; : init_textN ( N -- C-ADDR ) s" init_textN" 9 namespace ; \ Environment variables : kernel[x] ( N -- C-ADDR/U ) s" kernel[x]" 7 +c! ; : menu_init[x] ( N -- C-ADDR/U ) s" menu_init[x]" 10 +c! ; : menu_command[x] ( N -- C-ADDR/U ) s" menu_command[x]" 13 +c! ; : menu_caption[x] ( N -- C-ADDR/U ) s" menu_caption[x]" 13 +c! ; : ansi_caption[x] ( N -- C-ADDR/U ) s" ansi_caption[x]" 13 +c! ; : menu_keycode[x] ( N -- C-ADDR/U ) s" menu_keycode[x]" 13 +c! ; : toggled_text[x] ( N -- C-ADDR/U ) s" toggled_text[x]" 13 +c! ; : toggled_ansi[x] ( N -- C-ADDR/U ) s" toggled_ansi[x]" 13 +c! ; : menu_caption[x][y] ( N M -- C-ADDR/U ) s" menu_caption[x][y]" 16 +c! 13 +c! ; : ansi_caption[x][y] ( N M -- C-ADDR/U ) s" ansi_caption[x][y]" 16 +c! 13 +c! ; also menu-infrastructure definitions \ This function prints a menu item at menuX (row) and menuY (column), returns \ the incremental decimal ASCII value associated with the menu item, and \ increments the cursor position to the next row for the creation of the next \ menu item. This function is called by the menu-create function. You need not \ call it directly. \ : printmenuitem ( menu_item_str -- ascii_keycode ) loader_color? if [char] ^ escc! then menurow dup @ 1+ swap ! ( increment menurow ) menuidx dup @ 1+ swap ! ( increment menuidx ) \ Calculate the menuitem row position menurow @ menuY @ + \ Position the cursor at the menuitem position dup menuX @ swap at-xy \ Print the value of menuidx loader_color? dup ( -- bool bool ) if b then menuidx @ . if me then \ Move the cursor forward 1 column dup menuX @ 1+ swap at-xy menubllt @ emit \ Print the menu bullet using the emit function \ Move the cursor to the 3rd column from the current position \ to allow for a space between the numerical prefix and the \ text caption menuX @ 3 + swap at-xy \ Print the menu caption (we expect a string to be on the stack \ prior to invoking this function) type \ Here we will add the ASCII decimal of the numerical prefix \ to the stack (decimal ASCII for `1' is 49) as a "return value" menuidx @ 48 + ; \ This function prints the appropriate menuitem basename to the stack if an \ ACPI option is to be presented to the user, otherwise returns -1. Used \ internally by menu-create, you need not (nor should you) call this directly. \ : acpimenuitem ( -- C-Addr/U | -1 ) arch-i386? if acpipresent? if acpienabled? if loader_color? if s" toggled_ansi[x]" else s" toggled_text[x]" then else loader_color? if s" ansi_caption[x]" else s" menu_caption[x]" then then else menuidx dup @ 1+ swap ! ( increment menuidx ) -1 then else -1 then ; : delim? ( C -- BOOL ) dup 32 = ( c -- c bool ) \ [sp] space over 9 = or ( c bool -- c bool ) \ [ht] horizontal tab over 10 = or ( c bool -- c bool ) \ [nl] newline over 13 = or ( c bool -- c bool ) \ [cr] carriage return over [char] , = or ( c bool -- c bool ) \ comma swap drop ( c bool -- bool ) \ return boolean ; \ This function parses $kernels into variables that are used by the menu to \ display which kernel to boot when the [overloaded] `boot' word is interpreted. \ Used internally by menu-create, you need not (nor should you) call this \ directly. \ : parse-kernels ( N -- ) \ kernidx kernidx ! ( n -- ) \ store provided `x' value [char] 0 kernmenuidx ! \ initialize `y' value for menu_caption[x][y] \ Attempt to get a list of kernels, fall back to sensible default s" kernels" getenv dup -1 = if drop ( cruft ) s" kernel kernel.old" then ( -- c-addr/u ) \ Check to see if the user has altered $kernel by comparing it against \ $kernel[N] where N is kernel_state (the actively displayed kernel). s" kernel_state" evaluate @ 48 + s" kernel[N]" 7 +c! getenv dup -1 <> if s" kernel" getenv dup -1 = if drop ( cruft ) s" " then 2swap 2over compare 0= if 2drop FALSE ( skip below conditional ) else \ User has changed $kernel TRUE ( slurp in new value ) then else \ We haven't yet parsed $kernels into $kernel[N] drop ( getenv cruft ) s" kernel" getenv dup -1 = if drop ( cruft ) s" " then TRUE ( slurp in initial value ) then ( c-addr/u -- c-addr/u c-addr/u,-1 | 0 ) if \ slurp new value into kerndefault kerndefault 1+ 0 2swap strcat swap 1- c! then \ Clear out existing parsed-kernels kernidx @ [char] 0 begin dup kernel[x] unsetenv 2dup menu_caption[x][y] unsetenv 2dup ansi_caption[x][y] unsetenv 1+ dup [char] 8 > until 2drop \ Step through the string until we find the end begin 0 kernlen ! \ initialize length of value \ Skip leading whitespace and/or comma delimiters begin dup 0<> if over c@ delim? ( c-addr/u -- c-addr/u bool ) else false ( c-addr/u -- c-addr/u bool ) then while 1- swap 1+ swap ( c-addr/u -- c-addr'/u' ) repeat ( c-addr/u -- c-addr'/u' ) dup 0= if \ end of string while eating whitespace 2drop ( c-addr/u -- ) kernmenuidx @ [char] 0 <> if \ found at least one exit \ all done then \ No entries in $kernels; use $kernel instead s" kernel" getenv dup -1 = if drop ( cruft ) s" " then ( -- c-addr/u ) dup kernlen ! \ store entire value length as kernlen else \ We're still within $kernels parsing toward the end; \ find delimiter/end to determine kernlen 2dup ( c-addr/u -- c-addr/u c-addr/u ) begin dup 0<> while over c@ delim? if drop 0 ( break ) \ found delimiter else kernlen @ 1+ kernlen ! \ incrememnt 1- swap 1+ swap \ c-addr++ u-- then repeat 2drop ( c-addr/u c-addr'/u' -- c-addr/u ) \ If this is the first entry, compare it to $kernel \ If different, then insert $kernel beforehand kernmenuidx @ [char] 0 = if over kernlen @ kerndefault count compare if kernelsbuf 0 kerndefault count strcat s" ," strcat 2swap strcat kerndefault count swap drop kernlen ! then then then ( c-addr/u -- c-addr'/u' ) \ At this point, we should have something on the stack to store \ as the next kernel menu option; start assembling variables over kernlen @ ( c-addr/u -- c-addr/u c-addr/u2 ) \ Assign first to kernel[x] 2dup kernmenuidx @ kernel[x] setenv \ Assign second to menu_caption[x][y] kerncapbuf 0 s" [K]ernel: " strcat 2over strcat kernidx @ kernmenuidx @ menu_caption[x][y] setenv \ Assign third to ansi_caption[x][y] - kerncapbuf 0 s" @[1mK@[37mernel: " [char] @ escc! strcat + kerncapbuf 0 s" @[1mK@[mernel: " [char] @ escc! strcat kernmenuidx @ [char] 0 = if s" default/@[32m" else s" @[34;1m" then [char] @ escc! strcat 2over strcat - s" @[37m" [char] @ escc! strcat + s" @[m" [char] @ escc! strcat kernidx @ kernmenuidx @ ansi_caption[x][y] setenv 2drop ( c-addr/u c-addr/u2 -- c-addr/u ) kernmenuidx @ 1+ dup kernmenuidx ! [char] 8 > if 2drop ( c-addr/u -- ) exit then kernlen @ - swap kernlen @ + swap ( c-addr/u -- c-addr'/u' ) again ; \ This function goes through the kernels that were discovered by the \ parse-kernels function [above], adding " (# of #)" text to the end of each \ caption. \ : tag-kernels ( -- ) kernidx @ ( -- x ) dup 0= if exit then [char] 0 s" (Y of Z)" ( x -- x y c-addr/u ) kernmenuidx @ -rot 7 +c! \ Replace 'Z' with number of kernels parsed begin 2 pick 1+ -rot 2 +c! \ Replace 'Y' with current ASCII num 2over menu_caption[x][y] getenv dup -1 <> if 2dup + 1- c@ [char] ) = if 2drop \ Already tagged else kerncapbuf 0 2swap strcat 2over strcat 5 pick 5 pick menu_caption[x][y] setenv then else drop ( getenv cruft ) then 2over ansi_caption[x][y] getenv dup -1 <> if 2dup + 1- c@ [char] ) = if 2drop \ Already tagged else kerncapbuf 0 2swap strcat 2over strcat 5 pick 5 pick ansi_caption[x][y] setenv then else drop ( getenv cruft ) then rot 1+ dup [char] 8 > if -rot 2drop TRUE ( break ) else -rot FALSE then until 2drop ( x y -- ) ; \ This function creates the list of menu items. This function is called by the \ menu-display function. You need not call it directly. \ : menu-create ( -- ) \ Print the frame caption at (x,y) s" loader_menu_title" getenv dup -1 = if drop s" Welcome to FreeBSD" then TRUE ( use default alignment ) s" loader_menu_title_align" getenv dup -1 <> if 2dup s" left" compare-insensitive 0= if ( 1 ) 2drop ( c-addr/u ) drop ( bool ) menuX @ menuY @ 1- FALSE ( don't use default alignment ) else ( 1 ) 2dup s" right" compare-insensitive 0= if ( 2 ) 2drop ( c-addr/u ) drop ( bool ) menuX @ 42 + 4 - over - menuY @ 1- FALSE ( don't use default alignment ) else ( 2 ) 2drop ( c-addr/u ) then ( 1 ) then else drop ( getenv cruft ) then if ( use default center alignement? ) menuX @ 19 + over 2 / - menuY @ 1- then at-xy type \ If $menu_init is set, evaluate it (allowing for whole menus to be \ constructed dynamically -- as this function could conceivably set \ the remaining environment variables to construct the menu entirely). \ s" menu_init" getenv dup -1 <> if evaluate else drop then \ Print our menu options with respective key/variable associations. \ `printmenuitem' ends by adding the decimal ASCII value for the \ numerical prefix to the stack. We store the value left on the stack \ to the key binding variable for later testing against a character \ captured by the `getkey' function. \ Note that any menu item beyond 9 will have a numerical prefix on the \ screen consisting of the first digit (ie. 1 for the tenth menu item) \ and the key required to activate that menu item will be the decimal \ ASCII of 48 plus the menu item (ie. 58 for the tenth item, aka. `:') \ which is misleading and not desirable. \ \ Thus, we do not allow more than 8 configurable items on the menu \ (with "Reboot" as the optional ninth and highest numbered item). \ \ Initialize the ACPI option status. \ 0 menuacpi ! s" menu_acpi" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) menuacpi ! arch-i386? if acpipresent? if \ \ Set menu toggle state to active state \ (required by generic toggle_menuitem) \ acpienabled? menuacpi @ toggle_stateN ! then then else drop then then \ \ Initialize kernel captions after parsing $kernels \ 0 menukernel ! s" menu_kernel" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) dup menukernel ! dup parse-kernels tag-kernels \ Get the current cycle state (entry to use) s" kernel_state" evaluate @ 48 + ( n -- n y ) \ If state is invalid, reset dup kernmenuidx @ 1- > if drop [char] 0 ( n y -- n 48 ) 0 s" kernel_state" evaluate ! over s" init_kernel" evaluate drop then \ Set the current non-ANSI caption 2dup swap dup ( n y -- n y y n n ) s" set menu_caption[x]=$menu_caption[x][y]" 17 +c! 34 +c! 37 +c! evaluate ( n y y n n c-addr/u -- n y ) \ Set the current ANSI caption 2dup swap dup ( n y -- n y y n n ) s" set ansi_caption[x]=$ansi_caption[x][y]" 17 +c! 34 +c! 37 +c! evaluate ( n y y n n c-addr/u -- n y ) \ Initialize cycle state from stored value 48 - ( n y -- n k ) s" init_cyclestate" evaluate ( n k -- n ) \ Set $kernel to $kernel[y] s" activate_kernel" evaluate ( n -- n ) then drop then \ \ Initialize the menu_options visual separator. \ 0 menuoptions ! s" menu_options" getenv -1 <> if c@ dup 48 > over 57 < and if ( '1' <= c1 <= '8' ) menuoptions ! else drop then then \ Initialize "Reboot" menu state variable (prevents double-entry) false menurebootadded ! menu_start 1- menuidx ! \ Initialize the starting index for the menu 0 menurow ! \ Initialize the starting position for the menu 49 \ Iterator start (loop range 49 to 56; ASCII '1' to '8') begin \ If the "Options:" separator, print it. dup menuoptions @ = if \ Optionally add a reboot option to the menu s" menu_reboot" getenv -1 <> if drop s" Reboot" printmenuitem menureboot ! true menurebootadded ! then menuX @ menurow @ 2 + menurow ! menurow @ menuY @ + at-xy s" menu_optionstext" getenv dup -1 <> if type else drop ." Options:" then then \ If this is the ACPI menu option, act accordingly. dup menuacpi @ = if dup acpimenuitem ( n -- n n c-addr/u | n n -1 ) dup -1 <> if 13 +c! ( n n c-addr/u -- n c-addr/u ) \ replace 'x' with n else swap drop ( n n -1 -- n -1 ) over menu_command[x] unsetenv then else \ make sure we have not already initialized this item dup init_stateN dup @ 0= if 1 swap ! \ If this menuitem has an initializer, run it dup menu_init[x] getenv dup -1 <> if evaluate else drop then else drop then dup loader_color? if ansi_caption[x] else menu_caption[x] then then dup -1 <> if \ test for environment variable getenv dup -1 <> if printmenuitem ( c-addr/u -- n ) dup menukeyN ! else drop then else drop then 1+ dup 56 > \ add 1 to iterator, continue if less than 57 until drop \ iterator \ Optionally add a reboot option to the menu menurebootadded @ true <> if s" menu_reboot" getenv -1 <> if drop \ no need for the value s" Reboot" \ menu caption (required by printmenuitem) printmenuitem menureboot ! else 0 menureboot ! then then ; \ Takes a single integer on the stack and updates the timeout display. The \ integer must be between 0 and 9 (we will only update a single digit in the \ source message). \ : menu-timeout-update ( N -- ) \ Enforce minimum/maximum dup 9 > if drop 9 then dup 0 < if drop 0 then s" Autoboot in N seconds. [Space] to pause" ( n -- n c-addr/u ) 2 pick 0> if rot 48 + -rot ( n c-addr/u -- n' c-addr/u ) \ convert to ASCII 12 +c! ( n' c-addr/u -- c-addr/u ) \ replace 'N' above menu_timeout_x @ menu_timeout_y @ at-xy \ position cursor type ( c-addr/u -- ) \ print message else menu_timeout_x @ menu_timeout_y @ at-xy \ position cursor spaces ( n c-addr/u -- n c-addr ) \ erase message 2drop ( n c-addr -- ) then 0 25 at-xy ( position cursor back at bottom-left ) ; \ This function blocks program flow (loops forever) until a key is pressed. \ The key that was pressed is added to the top of the stack in the form of its \ decimal ASCII representation. This function is called by the menu-display \ function. You need not call it directly. \ : getkey ( -- ascii_keycode ) begin \ loop forever menu_timeout_enabled @ 1 = if ( -- ) seconds ( get current time: -- N ) dup menu_time @ <> if ( has time elapsed?: N N N -- N ) \ At least 1 second has elapsed since last loop \ so we will decrement our "timeout" (really a \ counter, insuring that we do not proceed too \ fast) and update our timeout display. menu_time ! ( update time record: N -- ) menu_timeout @ ( "time" remaining: -- N ) dup 0> if ( greater than 0?: N N 0 -- N ) 1- ( decrement counter: N -- N ) dup menu_timeout ! ( re-assign: N N Addr -- N ) then ( -- N ) dup 0= swap 0< or if ( N <= 0?: N N -- ) \ halt the timer 0 menu_timeout ! ( 0 Addr -- ) 0 menu_timeout_enabled ! ( 0 Addr -- ) then \ update the timer display ( N -- ) menu_timeout @ menu-timeout-update menu_timeout @ 0= if \ We've reached the end of the timeout \ (user did not cancel by pressing ANY \ key) s" menu_timeout_command" getenv dup -1 = if drop \ clean-up else evaluate then then else ( -- N ) \ No [detectable] time has elapsed (in seconds) drop ( N -- ) then ( -- ) then key? if \ Was a key pressed? (see loader(8)) \ An actual key was pressed (if the timeout is running, \ kill it regardless of which key was pressed) menu_timeout @ 0<> if 0 menu_timeout ! 0 menu_timeout_enabled ! \ clear screen of timeout message 0 menu-timeout-update then \ get the key that was pressed and exit (if we \ get a non-zero ASCII code) key dup 0<> if exit else drop then then 50 ms \ sleep for 50 milliseconds (see loader(8)) again ; : menu-erase ( -- ) \ Erases menu and resets positioning variable to position 1. \ Clear the screen area associated with the interactive menu menuX @ menuY @ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 1+ 2dup at-xy 38 spaces 2drop \ Reset the starting index and position for the menu menu_start 1- menuidx ! 0 menurow ! ; only forth also menu-infrastructure also menu-namespace also menu-command-helpers definitions : toggle_menuitem ( N -- N ) \ toggles caption text and internal menuitem state \ ASCII numeral equal to user-selected menu item must be on the stack. \ We do not modify the stack, so the ASCII numeral is left on top. dup init_textN c@ 0= if \ NOTE: no need to check toggle_stateN since the first time we \ are called, we will populate init_textN. Further, we don't \ need to test whether menu_caption[x] (ansi_caption[x] when \ loader_color?=1) is available since we would not have been \ called if the caption was NULL. \ base name of environment variable dup ( n -- n n ) \ key pressed loader_color? if ansi_caption[x] else menu_caption[x] then getenv dup -1 <> if 2 pick ( n c-addr/u -- n c-addr/u n ) init_textN ( n c-addr/u n -- n c-addr/u c-addr ) \ now we have the buffer c-addr on top \ ( followed by c-addr/u of current caption ) \ Copy the current caption into our buffer 2dup c! -rot \ store strlen at first byte begin rot 1+ \ bring alt addr to top and increment -rot -rot \ bring buffer addr to top 2dup c@ swap c! \ copy current character 1+ \ increment buffer addr rot 1- \ bring buffer len to top and decrement dup 0= \ exit loop if buffer len is zero until 2drop \ buffer len/addr drop \ alt addr else drop then then \ Now we are certain to have init_textN populated with the initial \ value of menu_caption[x] (ansi_caption[x] with loader_color enabled). \ We can now use init_textN as the untoggled caption and \ toggled_text[x] (toggled_ansi[x] with loader_color enabled) as the \ toggled caption and store the appropriate value into menu_caption[x] \ (again, ansi_caption[x] with loader_color enabled). Last, we'll \ negate the toggled state so that we reverse the flow on subsequent \ calls. dup toggle_stateN @ 0= if \ state is OFF, toggle to ON dup ( n -- n n ) \ key pressed loader_color? if toggled_ansi[x] else toggled_text[x] then getenv dup -1 <> if \ Assign toggled text to menu caption 2 pick ( n c-addr/u -- n c-addr/u n ) \ key pressed loader_color? if ansi_caption[x] else menu_caption[x] then setenv else \ No toggled text, keep the same caption drop ( n -1 -- n ) \ getenv cruft then true \ new value of toggle state var (to be stored later) else \ state is ON, toggle to OFF dup init_textN count ( n -- n c-addr/u ) \ Assign init_textN text to menu caption 2 pick ( n c-addr/u -- n c-addr/u n ) \ key pressed loader_color? if ansi_caption[x] else menu_caption[x] then setenv false \ new value of toggle state var (to be stored below) then \ now we'll store the new toggle state (on top of stack) over toggle_stateN ! ; : cycle_menuitem ( N -- N ) \ cycles through array of choices for a menuitem \ ASCII numeral equal to user-selected menu item must be on the stack. \ We do not modify the stack, so the ASCII numeral is left on top. dup cycle_stateN dup @ 1+ \ get value and increment \ Before assigning the (incremented) value back to the pointer, \ let's test for the existence of this particular array element. \ If the element exists, we'll store index value and move on. \ Otherwise, we'll loop around to zero and store that. dup 48 + ( n addr k -- n addr k k' ) \ duplicate array index and convert to ASCII numeral 3 pick swap ( n addr k k' -- n addr k n k' ) \ (n,k') as (x,y) loader_color? if ansi_caption[x][y] else menu_caption[x][y] then ( n addr k n k' -- n addr k c-addr/u ) \ Now test for the existence of our incremented array index in the \ form of $menu_caption[x][y] ($ansi_caption[x][y] with loader_color \ enabled) as set in loader.rc(5), et. al. getenv dup -1 = if \ No caption set for this array index. Loop back to zero. drop ( n addr k -1 -- n addr k ) \ getenv cruft drop 0 ( n addr k -- n addr 0 ) \ new value to store later 2 pick [char] 0 ( n addr 0 -- n addr 0 n 48 ) \ (n,48) as (x,y) loader_color? if ansi_caption[x][y] else menu_caption[x][y] then ( n addr 0 n 48 -- n addr 0 c-addr/u ) getenv dup -1 = if \ Highly unlikely to occur, but to ensure things move \ along smoothly, allocate a temporary NULL string drop ( cruft ) s" " then then \ At this point, we should have the following on the stack (in order, \ from bottom to top): \ \ n - Ascii numeral representing the menu choice (inherited) \ addr - address of our internal cycle_stateN variable \ k - zero-based number we intend to store to the above \ c-addr/u - string value we intend to store to menu_caption[x] \ (or ansi_caption[x] with loader_color enabled) \ \ Let's perform what we need to with the above. \ Assign array value text to menu caption 4 pick ( n addr k c-addr/u -- n addr k c-addr/u n ) loader_color? if ansi_caption[x] else menu_caption[x] then setenv swap ! ( n addr k -- n ) \ update array state variable ; only forth definitions also menu-infrastructure \ Erase and redraw the menu. Useful if you change a caption and want to \ update the menu to reflect the new value. \ : menu-redraw ( -- ) menu-erase menu-create ; \ This function initializes the menu. Call this from your `loader.rc' file \ before calling any other menu-related functions. \ : menu-init ( -- ) menu_start 1- menuidx ! \ Initialize the starting index for the menu 0 menurow ! \ Initialize the starting position for the menu \ Assign configuration values s" loader_menu_y" getenv dup -1 = if drop \ no custom row position menu_default_y else \ make sure custom position is a number ?number 0= if menu_default_y \ or use default then then menuY ! s" loader_menu_x" getenv dup -1 = if drop \ no custom column position menu_default_x else \ make sure custom position is a number ?number 0= if menu_default_x \ or use default then then menuX ! \ Interpret a custom frame type for the menu TRUE ( draw a box? default yes, but might be altered below ) s" loader_menu_frame" getenv dup -1 = if ( 1 ) drop \ no custom frame type else ( 1 ) 2dup s" single" compare-insensitive 0= if ( 2 ) f_single ( see frames.4th ) else ( 2 ) 2dup s" double" compare-insensitive 0= if ( 3 ) f_double ( see frames.4th ) else ( 3 ) s" none" compare-insensitive 0= if ( 4 ) drop FALSE \ don't draw a box ( 4 ) then ( 3 ) then ( 2 ) then ( 1 ) then if 42 13 menuX @ 3 - menuY @ 1- box \ Draw frame (w,h,x,y) then 0 25 at-xy \ Move cursor to the bottom for output ; also menu-namespace \ Main function. Call this from your `loader.rc' file. \ : menu-display ( -- ) 0 menu_timeout_enabled ! \ start with automatic timeout disabled \ check indication that automatic execution after delay is requested s" menu_timeout_command" getenv -1 <> if ( Addr C -1 -- | Addr ) drop ( just testing existence right now: Addr -- ) \ initialize state variables seconds menu_time ! ( store the time we started ) 1 menu_timeout_enabled ! ( enable automatic timeout ) \ read custom time-duration (if set) s" autoboot_delay" getenv dup -1 = if drop \ no custom duration (remove dup'd bunk -1) menu_timeout_default \ use default setting else 2dup ?number 0= if ( if not a number ) \ disable timeout if "NO", else use default s" NO" compare-insensitive 0= if 0 menu_timeout_enabled ! 0 ( assigned to menu_timeout below ) else menu_timeout_default then else -rot 2drop \ boot immediately if less than zero dup 0< if drop menu-create 0 25 at-xy 0 boot then then then menu_timeout ! ( store value on stack from above ) menu_timeout_enabled @ 1 = if \ read custom column position (if set) s" loader_menu_timeout_x" getenv dup -1 = if drop \ no custom column position menu_timeout_default_x \ use default setting else \ make sure custom position is a number ?number 0= if menu_timeout_default_x \ or use default then then menu_timeout_x ! ( store value on stack from above ) \ read custom row position (if set) s" loader_menu_timeout_y" getenv dup -1 = if drop \ no custom row position menu_timeout_default_y \ use default setting else \ make sure custom position is a number ?number 0= if menu_timeout_default_y \ or use default then then menu_timeout_y ! ( store value on stack from above ) then then menu-create begin \ Loop forever 0 25 at-xy \ Move cursor to the bottom for output getkey \ Block here, waiting for a key to be pressed dup -1 = if drop exit \ Caught abort (abnormal return) then \ Boot if the user pressed Enter/Ctrl-M (13) or \ Ctrl-Enter/Ctrl-J (10) dup over 13 = swap 10 = or if drop ( no longer needed ) s" boot" evaluate exit ( pedantic; never reached ) then dup menureboot @ = if 0 reboot then \ Evaluate the decimal ASCII value against known menu item \ key associations and act accordingly 49 \ Iterator start (loop range 49 to 56; ASCII '1' to '8') begin dup menukeyN @ rot tuck = if \ Adjust for missing ACPI menuitem on non-i386 arch-i386? true <> menuacpi @ 0<> and if menuacpi @ over 2dup < -rot = or over 58 < and if ( key >= menuacpi && key < 58: N -- N ) 1+ then then \ Test for the environment variable dup menu_command[x] getenv dup -1 <> if \ Execute the stored procedure evaluate \ We expect there to be a non-zero \ value left on the stack after \ executing the stored procedure. \ If so, continue to run, else exit. 0= if drop \ key pressed drop \ loop iterator exit else swap \ need iterator on top then then \ Re-adjust for missing ACPI menuitem arch-i386? true <> menuacpi @ 0<> and if swap menuacpi @ 1+ over 2dup < -rot = or over 59 < and if 1- then swap then else swap \ need iterator on top then \ \ Check for menu keycode shortcut(s) \ dup menu_keycode[x] getenv dup -1 = if drop else ?number 0<> if rot tuck = if swap dup menu_command[x] getenv dup -1 <> if evaluate 0= if 2drop exit then else drop then else swap then then then 1+ dup 56 > \ increment iterator \ continue if less than 57 until drop \ loop iterator drop \ key pressed again \ Non-operational key was pressed; repeat ; \ This function unsets all the possible environment variables associated with \ creating the interactive menu. \ : menu-unset ( -- ) 49 \ Iterator start (loop range 49 to 56; ASCII '1' to '8') begin dup menu_init[x] unsetenv \ menu initializer dup menu_command[x] unsetenv \ menu command dup menu_caption[x] unsetenv \ menu caption dup ansi_caption[x] unsetenv \ ANSI caption dup menu_keycode[x] unsetenv \ menu keycode dup toggled_text[x] unsetenv \ toggle_menuitem caption dup toggled_ansi[x] unsetenv \ toggle_menuitem ANSI caption 48 \ Iterator start (inner range 48 to 57; ASCII '0' to '9') begin \ cycle_menuitem caption and ANSI caption 2dup menu_caption[x][y] unsetenv 2dup ansi_caption[x][y] unsetenv 1+ dup 57 > until drop \ inner iterator 0 over menukeyN ! \ used by menu-create, menu-display 0 over init_stateN ! \ used by menu-create 0 over toggle_stateN ! \ used by toggle_menuitem 0 over init_textN c! \ used by toggle_menuitem 0 over cycle_stateN ! \ used by cycle_menuitem 1+ dup 56 > \ increment, continue if less than 57 until drop \ iterator s" menu_timeout_command" unsetenv \ menu timeout command s" menu_reboot" unsetenv \ Reboot menu option flag s" menu_acpi" unsetenv \ ACPI menu option flag s" menu_kernel" unsetenv \ Kernel menu option flag s" menu_options" unsetenv \ Options separator flag s" menu_optionstext" unsetenv \ separator display text s" menu_init" unsetenv \ menu initializer 0 menureboot ! 0 menuacpi ! 0 menuoptions ! ; only forth definitions also menu-infrastructure \ This function both unsets menu variables and visually erases the menu area \ in-preparation for another menu. \ : menu-clear ( -- ) menu-unset menu-erase ; bullet menubllt ! also menu-namespace \ Initialize our menu initialization state variables 0 init_state1 ! 0 init_state2 ! 0 init_state3 ! 0 init_state4 ! 0 init_state5 ! 0 init_state6 ! 0 init_state7 ! 0 init_state8 ! \ Initialize our boolean state variables 0 toggle_state1 ! 0 toggle_state2 ! 0 toggle_state3 ! 0 toggle_state4 ! 0 toggle_state5 ! 0 toggle_state6 ! 0 toggle_state7 ! 0 toggle_state8 ! \ Initialize our array state variables 0 cycle_state1 ! 0 cycle_state2 ! 0 cycle_state3 ! 0 cycle_state4 ! 0 cycle_state5 ! 0 cycle_state6 ! 0 cycle_state7 ! 0 cycle_state8 ! \ Initialize string containers 0 init_text1 c! 0 init_text2 c! 0 init_text3 c! 0 init_text4 c! 0 init_text5 c! 0 init_text6 c! 0 init_text7 c! 0 init_text8 c! only forth definitions Index: stable/12/stand/forth/menu.rc =================================================================== --- stable/12/stand/forth/menu.rc (revision 354009) +++ stable/12/stand/forth/menu.rc (revision 354010) @@ -1,202 +1,202 @@ \ Menu.rc \ $FreeBSD$ \ \ You should not edit this file! Put any overrides in menu.rc.local \ instead as this file can be replaced during system updates. \ \ Load required Forth modules include /boot/version.4th include /boot/brand.4th include /boot/menu.4th include /boot/menu-commands.4th include /boot/shortcuts.4th \ Screen prep clear \ clear the screen (see `screen.4th') print_version \ print version string (bottom-right; see `version.4th') draw-beastie \ draw freebsd mascot (on right; see `beastie.4th') draw-brand \ draw the FreeBSD title (top-left; see `brand.4th') menu-init \ initialize the menu area (see `menu.4th') \ Initialize main menu constructs (see `menu.4th') \ NOTE: To use `non-ansi' variants, add `loader_color=0' to loader.conf(5) \ NOTE: ANSI variants can use `^' in place of literal `Esc' (ASCII 27) \ \ MAIN MENU \ set menuset_name1="main" set mainmenu_init[1]="init_boot" set mainmenu_caption[1]="Boot Multi User [Enter]" set maintoggled_text[1]="Boot [S]ingle User [Enter]" set mainmenu_command[1]="boot" set mainansi_caption[1]="^[1mB^[moot Multi User ^[1m[Enter]^[m" set maintoggled_ansi[1]="Boot ^[1mS^[mingle User ^[1m[Enter]^[m" \ keycode set by init_boot set mainmenu_init[2]="init_altboot" set mainmenu_caption[2]="Boot [S]ingle User" set maintoggled_text[2]="Boot [M]ulti User" set mainmenu_command[2]="altboot" set mainansi_caption[2]="Boot ^[1mS^[mingle User" set maintoggled_ansi[2]="Boot ^[1mM^[multi User" \ keycode set by init_altboot set mainmenu_caption[3]="[Esc]ape to loader prompt" set mainmenu_command[3]="goto_prompt" set mainmenu_keycode[3]=27 set mainansi_caption[3]="^[1mEsc^[mape to loader prompt" \ Enable built-in "Reboot" trailing menuitem \ NOTE: appears before menu_options if configured \ set mainmenu_reboot \ Enable "Options:" separator. When set to a numerical value (1-8), a visual \ separator is inserted before that menuitem number. \ set mainmenu_options=5 set mainmenu_kernel=5 set mainmenu_command[5]="cycle_kernel" set mainmenu_keycode[5]=107 set mainmenu_caption[6]="Configure Boot [O]ptions..." set mainmenu_command[6]="2 goto_menu" set mainmenu_keycode[6]=111 set mainansi_caption[6]="Configure Boot ^[1mO^[mptions..." s" currdev" getenv dup 0> [if] drop 4 s" zfs:" compare 0= [if] set mainmenu_caption[7]="Select Boot [E]nvironment..." set mainmenu_command[7]="3 goto_menu" set mainmenu_keycode[7]=101 - set mainansi_caption[7]="Select Boot ^[1mE^[37mnvironment..." + set mainansi_caption[7]="Select Boot ^[1mE^[mnvironment..." s" chain_disk" getenv? [if] set mainmenu_caption[8]="Chain[L]oad ${chain_disk}" set mainmenu_command[8]="chain ${chain_disk}" set mainmenu_keycode[8]=108 set mainansi_caption[8]="Chain^[1mL^[moad ${chain_disk}" [then] [else] s" chain_disk" getenv? [if] set mainmenu_caption[7]="Chain[L]oad ${chain_disk}" set mainmenu_command[7]="chain ${chain_disk}" set mainmenu_keycode[7]=108 set mainansi_caption[7]="Chain^[1mL^[moad ${chain_disk}" [then] [then] [else] drop [then] \ \ BOOT OPTIONS MENU \ set menuset_name2="options" set optionsmenu_caption[1]="Back to Main Menu [Backspace]" set optionsmenu_command[1]="1 goto_menu" set optionsmenu_keycode[1]=8 set optionsansi_caption[1]="Back to Main Menu ^[1m[Backspace]^[m" set optionsmenu_caption[2]="Load System [D]efaults" set optionsmenu_command[2]="set_default_boot_options" set optionsmenu_keycode[2]=100 set optionsansi_caption[2]="Load System ^[1mD^[mefaults" set optionsmenu_options=3 set optionsmenu_optionstext="Boot Options:" set optionsmenu_acpi=3 set optionsmenu_caption[3]="[A]CPI Support off" set optionstoggled_text[3]="[A]CPI Support On" set optionsmenu_command[3]="toggle_acpi" set optionsmenu_keycode[3]=97 set optionsansi_caption[3]="^[1mA^[mCPI Support ^[34;1mOff^[m" set optionstoggled_ansi[3]="^[1mA^[mCPI Support ^[32;7mOn^[m" set optionsmenu_init[4]="init_safemode" set optionsmenu_caption[4]="Safe [M]ode... off" set optionstoggled_text[4]="Safe [M]ode... On" set optionsmenu_command[4]="toggle_safemode" set optionsmenu_keycode[4]=109 set optionsansi_caption[4]="Safe ^[1mM^[mode... ^[34;1mOff^[m" set optionstoggled_ansi[4]="Safe ^[1mM^[mode... ^[32;7mOn^[m" set optionsmenu_init[5]="init_singleuser" set optionsmenu_caption[5]="[S]ingle User. off" set optionstoggled_text[5]="[S]ingle User. On" set optionsmenu_command[5]="toggle_singleuser" set optionsmenu_keycode[5]=115 set optionsansi_caption[5]="^[1mS^[mingle User. ^[34;1mOff^[m" set optionstoggled_ansi[5]="^[1mS^[mingle User. ^[32;7mOn^[m" set optionsmenu_init[6]="init_verbose" set optionsmenu_caption[6]="[V]erbose..... off" set optionstoggled_text[6]="[V]erbose..... On" set optionsmenu_command[6]="toggle_verbose" set optionsmenu_keycode[6]=118 set optionsansi_caption[6]="^[1mV^[merbose..... ^[34;1mOff^[m" set optionstoggled_ansi[6]="^[1mV^[merbose..... ^[32;7mOn^[m" \ \ BOOT ENVIRONMENT MENU \ set menuset_name3="bootenv" set bemenu_current="Active: " set beansi_current="^[1m${bemenu_current}^[m" set bemenu_bootfs="bootfs: " set beansi_bootfs="^[1m${bemenu_bootfs}^[m" set bemenu_page="[P]age: " set beansi_page="^[1mP^[mage: " set bemenu_pageof=" of " set beansi_pageof="${bemenu_pageof}" set zfs_be_currpage=1 set bootenvmenu_init="init_bootenv" set bootenvmenu_command[1]="be_draw_screen 1 goto_menu" set bootenvmenu_keycode[1]=8 set bootenvmenu_command[2]="set_bootenv" set bootenvmenu_keycode[2]=97 set bootenv_root[2]="${zfs_be_active}" set bootenvmenu_command[3]="set_be_page" set bootenvmenu_keycode[3]=112 set bootenvmenu_options=4 set bootenvmenu_optionstext="Boot Environments:" \ Enable automatic booting (add ``autoboot_delay=N'' to loader.conf(5) to \ customize the timeout; default is 10-seconds) \ set menu_timeout_command="boot" \ Include optional elements defined in a local file \ try-include /boot/menu.rc.local \ Initialize boot environment variables \ s" reloadbe" sfind ( xt|0 bool ) [if] s" bootenv_autolist" getenv dup -1 = [if] drop s" execute" evaluate \ Use evaluate to avoid passing \ reloadbe an optional parameter [else] s" YES" compare-insensitive 0= [if] s" execute" evaluate [then] [then] [else] drop ( xt=0 ) [then] \ Display the main menu (see `menu.4th') set menuset_initial=1 menuset-loadinitial menu-display Index: stable/12/stand/lua/color.lua =================================================================== --- stable/12/stand/lua/color.lua (revision 354009) +++ stable/12/stand/lua/color.lua (revision 354010) @@ -1,116 +1,116 @@ -- -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD -- -- Copyright (c) 2015 Pedro Souza -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -- SUCH DAMAGE. -- -- $FreeBSD$ -- local core = require("core") local color = {} -- Module exports color.BLACK = 0 color.RED = 1 color.GREEN = 2 color.YELLOW = 3 color.BLUE = 4 color.MAGENTA = 5 color.CYAN = 6 color.WHITE = 7 -color.DEFAULT = 0 +color.DEFAULT = 9 color.BRIGHT = 1 color.DIM = 2 function color.isEnabled() local c = loader.getenv("loader_color") if c ~= nil then return c:lower() ~= "no" and c ~= "0" end return not core.isSerialBoot() end color.disabled = not color.isEnabled() function color.escapefg(color_value) if color.disabled then return color_value end return core.KEYSTR_CSI .. "3" .. color_value .. "m" end function color.resetfg() if color.disabled then return '' end - return color.escapefg(color.WHITE) + return color.escapefg(color.DEFAULT) end function color.escapebg(color_value) if color.disabled then return color_value end return core.KEYSTR_CSI .. "4" .. color_value .. "m" end function color.resetbg() if color.disabled then return '' end - return color.escapebg(color.BLACK) + return color.escapebg(color.DEFAULT) end function color.escape(fg_color, bg_color, attribute) if color.disabled then return "" end if attribute == nil then attribute = "" else attribute = attribute .. ";" end return core.KEYSTR_CSI .. attribute .. "3" .. fg_color .. ";4" .. bg_color .. "m" end function color.default() if color.disabled then return "" end - return color.escape(color.WHITE, color.BLACK, color.DEFAULT) + return color.escape(color.DEFAULT, color.DEFAULT) end function color.highlight(str) if color.disabled then return str end -- We need to reset attributes as well as color scheme here, just in -- case the terminal defaults don't match what we're expecting. return core.KEYSTR_CSI .. "1m" .. str .. core.KEYSTR_CSI .. "22m" end return color Index: stable/12/stand/lua/logo-beastie.lua =================================================================== --- stable/12/stand/lua/logo-beastie.lua (revision 354009) +++ stable/12/stand/lua/logo-beastie.lua (revision 354010) @@ -1,59 +1,59 @@ -- -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD -- -- Copyright (c) 2018 Kyle Evans -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -- SUCH DAMAGE. -- -- $FreeBSD$ -- local drawer = require("drawer") local beastie_color = { " \027[31m, ,", " /( )`", " \\ \\___ / |", " /- \027[37m_\027[31m `-/ '", " (\027[37m/\\/ \\\027[31m \\ /\\", " \027[37m/ / |\027[31m ` \\", " \027[34mO O \027[37m) \027[31m/ |", " \027[37m`-^--'\027[31m`< '", " (_.) _ ) /", " `.___/` /", " `-----' /", " \027[33m<----.\027[31m __ / __ \\", " \027[33m<----|====\027[31mO)))\027[33m==\027[31m) \\) /\027[33m====|", " \027[33m<----'\027[31m `--' `.__,' \\", " | |", " \\ / /\\", " \027[36m______\027[31m( (_ / \\______/", " \027[36m,' ,-----' |", -" `--{__________)\027[37m" +" `--{__________)\027[m" } drawer.addLogo("beastie", { requires_color = true, graphic = beastie_color, }) return true Index: stable/12/stand/lua/logo-orb.lua =================================================================== --- stable/12/stand/lua/logo-orb.lua (revision 354009) +++ stable/12/stand/lua/logo-orb.lua (revision 354010) @@ -1,56 +1,56 @@ -- -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD -- -- Copyright (c) 2018 Kyle Evans -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -- SUCH DAMAGE. -- -- $FreeBSD$ -- local drawer = require("drawer") local orb_color = { " \027[31m``` \027[31;1m`\027[31m", " s` `.....---...\027[31;1m....--.``` -/\027[31m", " +o .--` \027[31;1m/y:` +.\027[31m", " yo`:. \027[31;1m:o `+-\027[31m", " y/ \027[31;1m-/` -o/\027[31m", " .- \027[31;1m::/sy+:.\027[31m", " / \027[31;1m`-- /\027[31m", " `: \027[31;1m:`\027[31m", " `: \027[31;1m:`\027[31m", " / \027[31;1m/\027[31m", " .- \027[31;1m-.\027[31m", " -- \027[31;1m-.\027[31m", " `:` \027[31;1m`:`", " \027[31;1m.-- `--.", -" .---.....----.\027[37m" +" .---.....----.\027[m" } drawer.addLogo("orb", { requires_color = true, graphic = orb_color, shift = {x = 2, y = 4}, }) return true Index: stable/12/stand/lua/menu.lua =================================================================== --- stable/12/stand/lua/menu.lua (revision 354009) +++ stable/12/stand/lua/menu.lua (revision 354010) @@ -1,501 +1,501 @@ -- -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD -- -- Copyright (c) 2015 Pedro Souza -- Copyright (C) 2018 Kyle Evans -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions -- are met: -- 1. Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -- SUCH DAMAGE. -- -- $FreeBSD$ -- local cli = require("cli") local core = require("core") local color = require("color") local config = require("config") local screen = require("screen") local drawer = require("drawer") local menu = {} local drawn_menu local return_menu_entry = { entry_type = core.MENU_RETURN, name = "Back to main menu" .. color.highlight(" [Backspace]"), } local function OnOff(str, value) if value then return str .. color.escapefg(color.GREEN) .. "On" .. - color.escapefg(color.WHITE) + color.resetfg() else return str .. color.escapefg(color.RED) .. "off" .. - color.escapefg(color.WHITE) + color.resetfg() end end local function bootenvSet(env) loader.setenv("vfs.root.mountfrom", env) loader.setenv("currdev", env .. ":") config.reload() end -- Module exports menu.handlers = { -- Menu handlers take the current menu and selected entry as parameters, -- and should return a boolean indicating whether execution should -- continue or not. The return value may be omitted if this entry should -- have no bearing on whether we continue or not, indicating that we -- should just continue after execution. [core.MENU_ENTRY] = function(_, entry) -- run function entry.func() end, [core.MENU_CAROUSEL_ENTRY] = function(_, entry) -- carousel (rotating) functionality local carid = entry.carousel_id local caridx = config.getCarouselIndex(carid) local choices = entry.items if type(choices) == "function" then choices = choices() end if #choices > 0 then caridx = (caridx % #choices) + 1 config.setCarouselIndex(carid, caridx) entry.func(caridx, choices[caridx], choices) end end, [core.MENU_SUBMENU] = function(_, entry) menu.process(entry.submenu) end, [core.MENU_RETURN] = function(_, entry) -- allow entry to have a function/side effect if entry.func ~= nil then entry.func() end return false end, } -- loader menu tree is rooted at menu.welcome menu.boot_environments = { entries = { -- return to welcome menu return_menu_entry, { entry_type = core.MENU_CAROUSEL_ENTRY, carousel_id = "be_active", items = core.bootenvList, name = function(idx, choice, all_choices) if #all_choices == 0 then return "Active: " end local is_default = (idx == 1) local bootenv_name = "" local name_color if is_default then name_color = color.escapefg(color.GREEN) else name_color = color.escapefg(color.BLUE) end bootenv_name = bootenv_name .. name_color .. choice .. color.resetfg() return color.highlight("A").."ctive: " .. bootenv_name .. " (" .. idx .. " of " .. #all_choices .. ")" end, func = function(_, choice, _) bootenvSet(choice) end, alias = {"a", "A"}, }, { entry_type = core.MENU_ENTRY, name = function() return color.highlight("b") .. "ootfs: " .. core.bootenvDefault() end, func = function() -- Reset active boot environment to the default config.setCarouselIndex("be_active", 1) bootenvSet(core.bootenvDefault()) end, alias = {"b", "B"}, }, }, } menu.boot_options = { entries = { -- return to welcome menu return_menu_entry, -- load defaults { entry_type = core.MENU_ENTRY, name = "Load System " .. color.highlight("D") .. "efaults", func = core.setDefaults, alias = {"d", "D"}, }, { entry_type = core.MENU_SEPARATOR, }, { entry_type = core.MENU_SEPARATOR, name = "Boot Options:", }, -- acpi { entry_type = core.MENU_ENTRY, visible = core.isSystem386, name = function() return OnOff(color.highlight("A") .. "CPI :", core.acpi) end, func = core.setACPI, alias = {"a", "A"}, }, -- safe mode { entry_type = core.MENU_ENTRY, name = function() return OnOff("Safe " .. color.highlight("M") .. "ode :", core.sm) end, func = core.setSafeMode, alias = {"m", "M"}, }, -- single user { entry_type = core.MENU_ENTRY, name = function() return OnOff(color.highlight("S") .. "ingle user:", core.su) end, func = core.setSingleUser, alias = {"s", "S"}, }, -- verbose boot { entry_type = core.MENU_ENTRY, name = function() return OnOff(color.highlight("V") .. "erbose :", core.verbose) end, func = core.setVerbose, alias = {"v", "V"}, }, }, } menu.welcome = { entries = function() local menu_entries = menu.welcome.all_entries -- Swap the first two menu items on single user boot if core.isSingleUserBoot() then -- We'll cache the swapped menu, for performance if menu.welcome.swapped_menu ~= nil then return menu.welcome.swapped_menu end -- Shallow copy the table menu_entries = core.deepCopyTable(menu_entries) -- Swap the first two menu entries menu_entries[1], menu_entries[2] = menu_entries[2], menu_entries[1] -- Then set their names to their alternate names menu_entries[1].name, menu_entries[2].name = menu_entries[1].alternate_name, menu_entries[2].alternate_name menu.welcome.swapped_menu = menu_entries end return menu_entries end, all_entries = { -- boot multi user { entry_type = core.MENU_ENTRY, name = color.highlight("B") .. "oot Multi user " .. color.highlight("[Enter]"), -- Not a standard menu entry function! alternate_name = color.highlight("B") .. "oot Multi user", func = function() core.setSingleUser(false) core.boot() end, alias = {"b", "B"}, }, -- boot single user { entry_type = core.MENU_ENTRY, name = "Boot " .. color.highlight("S") .. "ingle user", -- Not a standard menu entry function! alternate_name = "Boot " .. color.highlight("S") .. "ingle user " .. color.highlight("[Enter]"), func = function() core.setSingleUser(true) core.boot() end, alias = {"s", "S"}, }, -- escape to interpreter { entry_type = core.MENU_RETURN, name = color.highlight("Esc") .. "ape to loader prompt", func = function() loader.setenv("autoboot_delay", "NO") end, alias = {core.KEYSTR_ESCAPE}, }, -- reboot { entry_type = core.MENU_ENTRY, name = color.highlight("R") .. "eboot", func = function() loader.perform("reboot") end, alias = {"r", "R"}, }, { entry_type = core.MENU_SEPARATOR, }, { entry_type = core.MENU_SEPARATOR, name = "Options:", }, -- kernel options { entry_type = core.MENU_CAROUSEL_ENTRY, carousel_id = "kernel", items = core.kernelList, name = function(idx, choice, all_choices) if #all_choices == 0 then return "Kernel: " end local is_default = (idx == 1) local kernel_name = "" local name_color if is_default then name_color = color.escapefg(color.GREEN) kernel_name = "default/" else name_color = color.escapefg(color.BLUE) end kernel_name = kernel_name .. name_color .. choice .. color.resetfg() return color.highlight("K") .. "ernel: " .. kernel_name .. " (" .. idx .. " of " .. #all_choices .. ")" end, func = function(_, choice, _) if loader.getenv("kernelname") ~= nil then loader.perform("unload") end config.selectKernel(choice) end, alias = {"k", "K"}, }, -- boot options { entry_type = core.MENU_SUBMENU, name = "Boot " .. color.highlight("O") .. "ptions", submenu = menu.boot_options, alias = {"o", "O"}, }, -- boot environments { entry_type = core.MENU_SUBMENU, visible = function() return core.isZFSBoot() and #core.bootenvList() > 1 end, name = "Boot " .. color.highlight("E") .. "nvironments", submenu = menu.boot_environments, alias = {"e", "E"}, }, -- chainload { entry_type = core.MENU_ENTRY, name = function() return 'Chain' .. color.highlight("L") .. "oad " .. loader.getenv('chain_disk') end, func = function() loader.perform("chain " .. loader.getenv('chain_disk')) end, visible = function() return loader.getenv('chain_disk') ~= nil end, alias = {"l", "L"}, }, }, } menu.default = menu.welcome -- current_alias_table will be used to keep our alias table consistent across -- screen redraws, instead of relying on whatever triggered the redraw to update -- the local alias_table in menu.process. menu.current_alias_table = {} function menu.draw(menudef) -- Clear the screen, reset the cursor, then draw screen.clear() menu.current_alias_table = drawer.drawscreen(menudef) drawn_menu = menudef screen.defcursor() end -- 'keypress' allows the caller to indicate that a key has been pressed that we -- should process as our initial input. function menu.process(menudef, keypress) assert(menudef ~= nil) if drawn_menu ~= menudef then menu.draw(menudef) end while true do local key = keypress or io.getchar() keypress = nil -- Special key behaviors if (key == core.KEY_BACKSPACE or key == core.KEY_DELETE) and menudef ~= menu.default then break elseif key == core.KEY_ENTER then core.boot() -- Should not return. If it does, escape menu handling -- and drop to loader prompt. return false end key = string.char(key) -- check to see if key is an alias local sel_entry = nil for k, v in pairs(menu.current_alias_table) do if key == k then sel_entry = v break end end -- if we have an alias do the assigned action: if sel_entry ~= nil then local handler = menu.handlers[sel_entry.entry_type] assert(handler ~= nil) -- The handler's return value indicates if we -- need to exit this menu. An omitted or true -- return value means to continue. if handler(menudef, sel_entry) == false then return end -- If we got an alias key the screen is out of date... -- redraw it. menu.draw(menudef) end end end function menu.run() local autoboot_key local delay = loader.getenv("autoboot_delay") if delay ~= nil and delay:lower() == "no" then delay = nil else delay = tonumber(delay) or 10 end if delay == -1 then core.boot() return end menu.draw(menu.default) if delay ~= nil then autoboot_key = menu.autoboot(delay) -- autoboot_key should return the key pressed. It will only -- return nil if we hit the timeout and executed the timeout -- command. Bail out. if autoboot_key == nil then return end end menu.process(menu.default, autoboot_key) drawn_menu = nil screen.defcursor() print("Exiting menu!") end function menu.autoboot(delay) local x = loader.getenv("loader_menu_timeout_x") or 4 local y = loader.getenv("loader_menu_timeout_y") or 23 local endtime = loader.time() + delay local time local last repeat time = endtime - loader.time() if last == nil or last ~= time then last = time screen.setcursor(x, y) print("Autoboot in " .. time .. " seconds, hit [Enter] to boot" .. " or any other key to stop ") screen.defcursor() end if io.ischar() then local ch = io.getchar() if ch == core.KEY_ENTER then break else -- erase autoboot msg screen.setcursor(0, y) print(string.rep(" ", 80)) screen.defcursor() return ch end end loader.delay(50000) until time <= 0 local cmd = loader.getenv("menu_timeout_command") or "boot" cli_execute_unparsed(cmd) return nil end -- CLI commands function cli.menu() menu.run() end return menu Index: stable/12 =================================================================== --- stable/12 (revision 354009) +++ stable/12 (revision 354010) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r352599,352601