1 %>@brief Text-based
menu
3 %>@ingroup
string usercomm
6 %> @param options Cell of strings
7 %> @param cancel_label =
'Cancel'. Label to show at last
"zero" option
8 %> @param flag_allow_empty =0 Whether to allow empty option
9 %> @
return option An integer: []; 0-Back/Cancel/etc; 1, 2, ...
10 function option =
menu(title, options, cancel_label, flag_allow_empty)
12 if nargin < 3 || isempty(cancel_label)
13 cancel_label = 'Cancel';
16 if ~exist('flag_allow_empty', 'var')
20 no_options = length(options);
26 fprintf([' ' ch*ones(1, length(title)+8) '\n']);
27 fprintf([' ' ch*ones(1, 3) ' ' title ' ' ch*ones(1, 3) '\n']);
28 fprintf([' ' ch*ones(1, length(title)+8) '\n']);
30 fprintf(' %d - %s\n', i, options{i});
32 fprintf(
' 0 - << (*%s*)\n', cancel_label);
38 fprintf(
'You are messing up');
43 if isempty(option) && flag_allow_empty
47 for i = 1:length(option)
48 if option(i) < 0 || option(i) > no_options
58 fprintf('Invalid option, range is [%d, %d].', 0, no_options);