211
|
1 function s = menu (t, ...) |
4
|
2 |
211
|
3 # usage: menu (title, opt1, ...) |
4
|
4 # |
|
5 # See also: disp, printf, input |
|
6 |
211
|
7 if (nargin < 2) |
|
8 error ("usage: menu (title, opt1, ...)"); |
4
|
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"; |
211
|
31 va_start (); |
4
|
32 for i = 1:nopt |
211
|
33 printf (" [%2d] ", i); |
|
34 disp (va_arg ()); |
4
|
35 endfor |
|
36 printf ("\n"); |
|
37 page_screen_output = save_page_screen_output; |
|
38 s = input ("pick a number, any number: "); |
|
39 if (s < 1 || s > nopt) |
|
40 printf ("\nerror: input out of range\n\n"); |
|
41 else |
|
42 break; |
|
43 endif |
|
44 endwhile |
|
45 |
|
46 page_screen_output = save_page_screen_output; |
|
47 |
|
48 endfunction |