Merge from vendor branch OPENSSH:
[dragonfly.git] / share / examples / bootforth / menu.4th
1 \ Simple greeting screen, presenting basic options.
2 \ XXX This is far too trivial - I don't have time now to think
3 \ XXX about something more fancy... :-/
4 \ $FreeBSD: src/share/examples/bootforth/menu.4th,v 1.4 1999/08/28 00:19:10 peter Exp $
5 \ $DragonFly: src/share/examples/bootforth/menu.4th,v 1.2 2003/06/17 04:36:57 dillon Exp $
6
7 : title
8         f_single
9         60 11 10 4 box
10         29 4 at-xy 15 fg 7 bg
11         ." Welcome to BootFORTH!"
12         me
13 ;
14
15 : menu
16         2 fg
17         20 7 at-xy 
18         ." 1.  Start FreeBSD /kernel."
19         20 8 at-xy
20         ." 2.  Interact with BootFORTH."
21         20 9 at-xy
22         ." 3.  Reboot."
23         me
24 ;
25
26 : tkey  ( d -- flag | char )
27         seconds +
28         begin 1 while
29             dup seconds u< if
30                 drop
31                 -1
32                 exit
33             then
34             key? if
35                 drop
36                 key
37                 exit
38             then
39         repeat
40 ;
41
42 : prompt
43         14 fg
44         20 11 at-xy
45         ." Enter your option (1,2,3): "
46         10 tkey
47         dup 32 = if
48             drop key
49         then
50         dup 0< if
51             drop 49
52         then
53         dup emit
54         me
55 ;
56
57 : help_text
58         10 18 at-xy ." * Choose 1 if you just want to run FreeBSD."
59         10 19 at-xy ." * Choose 2 if you want to use bootloader facilities."
60         12 20 at-xy ." See '?' for available commands, and 'words' for"
61         12 21 at-xy ." complete list of Forth words."
62         10 22 at-xy ." * Choose 3 in order to warm boot your machine."
63 ;
64
65 : (boot) 0 boot ;
66 : (reboot) 0 reboot ;
67
68 : main_menu
69         begin 1 while
70                 clear
71                 f_double
72                 79 23 1 1 box
73                 title
74                 menu
75                 help_text
76                 prompt
77                 cr cr cr
78                 dup 49 = if
79                         drop
80                         1 25 at-xy cr
81                         ." Loading kernel. Please wait..." cr
82                         ['] (boot) catch abort" Error booting"
83                 then
84                 dup 50 = if
85                         drop
86                         1 25 at-xy cr
87                         exit
88                 then
89                 dup 51 = if
90                         drop
91                         1 25 at-xy cr
92                         ['] (reboot) catch abort" Error rebooting"
93                 then
94                 20 12 at-xy
95                 ." Key " emit ."  is not a valid option!"
96                 20 13 at-xy
97                 ." Press any key to continue..."
98                 key drop
99         repeat
100 ;