1 ## Copyright (C) 1993-2012 John W. Eaton
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} menu (@var{title}, @var{opt1}, @dots{})
21 ## Print a title string followed by a series of options. Each option will
22 ## be printed along with a number. The return value is the number of the
23 ## option selected by the user. This function is useful for interactive
24 ## programs. There is no limit to the number of options that may be passed
25 ## in, but it may be confusing to present more than will fit easily on one
27 ## @seealso{disp, printf, input}
32 function num = menu (title, varargin)
38 ## Force pending output to appear before the menu.
42 ## Don't send the menu through the pager since doing that can cause
45 page_screen_output (0, "local");
47 if (! isempty (title))
56 printf (" [%2d] ", i);
60 s = input ("pick a number, any number: ", "s");
61 num = sscanf (s, "%d");
62 if (! isscalar (num) || num < 1 || num > nopt)
63 printf ("\nerror: input invalid or out of range\n\n");