diff scripts/miscellaneous/menu.m @ 4:b4df021f796c

[project @ 1993-08-08 01:26:08 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:26:08 +0000
parents
children 4adbab9c31cd
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/menu.m
@@ -0,0 +1,47 @@
+function s = menu (t,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16)
+
+# usage: menu (title, opt1, opt2, ..., opt16)
+#
+# See also: disp, printf, input
+
+  if (nargin < 2 || nargin > 17)
+    error ("usage: menu (title, opt1, opt2, ..., opt16)");
+  endif
+
+# Force pending output to appear before the menu.
+
+  fflush (stdout);
+
+# Don't send the menu through the pager since doing that can cause
+# major confusion.
+
+  save_page_screen_output = page_screen_output;
+  page_screen_output = "false";
+
+  if (! isempty (t))
+    disp (t);
+    printf ("\n");
+  endif
+
+  nopt = nargin - 1;
+
+  s = 0;
+  while (1)
+    page_screen_output = "false";
+    for i = 1:nopt
+      command = sprintf ("printf (\"  [%2d] \"); disp (x%d)", i, i);
+      eval (command);
+    endfor
+    printf ("\n");
+    page_screen_output = save_page_screen_output;
+    s = input ("pick a number, any number: ");
+    if (s < 1 || s > nopt)
+      printf ("\nerror: input out of range\n\n");
+    else
+      break;
+    endif
+  endwhile
+
+  page_screen_output = save_page_screen_output;
+
+endfunction