245
|
1 # Copyright (C) 1993 John W. Eaton |
|
2 # |
|
3 # This file is part of Octave. |
|
4 # |
|
5 # Octave is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License as published by the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with Octave; see the file COPYING. If not, write to the Free |
|
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
211
|
19 function s = menu (t, ...) |
4
|
20 |
211
|
21 # usage: menu (title, opt1, ...) |
4
|
22 # |
|
23 # See also: disp, printf, input |
|
24 |
211
|
25 if (nargin < 2) |
|
26 error ("usage: menu (title, opt1, ...)"); |
4
|
27 endif |
|
28 |
|
29 # Force pending output to appear before the menu. |
|
30 |
|
31 fflush (stdout); |
|
32 |
|
33 # Don't send the menu through the pager since doing that can cause |
|
34 # major confusion. |
|
35 |
|
36 save_page_screen_output = page_screen_output; |
|
37 page_screen_output = "false"; |
|
38 |
|
39 if (! isempty (t)) |
|
40 disp (t); |
|
41 printf ("\n"); |
|
42 endif |
|
43 |
|
44 nopt = nargin - 1; |
|
45 |
|
46 s = 0; |
|
47 while (1) |
|
48 page_screen_output = "false"; |
211
|
49 va_start (); |
4
|
50 for i = 1:nopt |
211
|
51 printf (" [%2d] ", i); |
|
52 disp (va_arg ()); |
4
|
53 endfor |
|
54 printf ("\n"); |
|
55 page_screen_output = save_page_screen_output; |
|
56 s = input ("pick a number, any number: "); |
|
57 if (s < 1 || s > nopt) |
|
58 printf ("\nerror: input out of range\n\n"); |
|
59 else |
|
60 break; |
|
61 endif |
|
62 endwhile |
|
63 |
|
64 page_screen_output = save_page_screen_output; |
|
65 |
|
66 endfunction |