4
|
1 function s = menu (t,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16) |
|
2 |
|
3 # usage: menu (title, opt1, opt2, ..., opt16) |
|
4 # |
|
5 # See also: disp, printf, input |
|
6 |
|
7 if (nargin < 2 || nargin > 17) |
|
8 error ("usage: menu (title, opt1, opt2, ..., opt16)"); |
|
9 endif |
|
10 |
|
11 # Force pending output to appear before the menu. |
|
12 |
|
13 fflush (stdout); |
|
14 |
|
15 # Don't send the menu through the pager since doing that can cause |
|
16 # major confusion. |
|
17 |
|
18 save_page_screen_output = page_screen_output; |
|
19 page_screen_output = "false"; |
|
20 |
|
21 if (! isempty (t)) |
|
22 disp (t); |
|
23 printf ("\n"); |
|
24 endif |
|
25 |
|
26 nopt = nargin - 1; |
|
27 |
|
28 s = 0; |
|
29 while (1) |
|
30 page_screen_output = "false"; |
|
31 for i = 1:nopt |
|
32 command = sprintf ("printf (\" [%2d] \"); disp (x%d)", i, i); |
|
33 eval (command); |
|
34 endfor |
|
35 printf ("\n"); |
|
36 page_screen_output = save_page_screen_output; |
|
37 s = input ("pick a number, any number: "); |
|
38 if (s < 1 || s > nopt) |
|
39 printf ("\nerror: input out of range\n\n"); |
|
40 else |
|
41 break; |
|
42 endif |
|
43 endwhile |
|
44 |
|
45 page_screen_output = save_page_screen_output; |
|
46 |
|
47 endfunction |