Module Name: src
Committed By: martin
Date: Sat Feb 16 18:57:21 UTC 2019
Modified Files:
src/usr.bin/menuc: menu_sys.def menuc.1
Log Message:
Document return values from menu items opt_action functions, add a
new variant: -1 when functions have fundamentally changed the menu
definition on the fly and the processing functions needs to restart
without looking at the old state (or stale cached pointers).
To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/menuc/menu_sys.def
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/menuc/menuc.1
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/menuc/menu_sys.def
diff -u src/usr.bin/menuc/menu_sys.def:1.65 src/usr.bin/menuc/menu_sys.def:1.66
--- src/usr.bin/menuc/menu_sys.def:1.65 Wed Feb 6 20:08:15 2019
+++ src/usr.bin/menuc/menu_sys.def Sat Feb 16 18:57:21 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: menu_sys.def,v 1.65 2019/02/06 20:08:15 martin Exp $ */
+/* $NetBSD: menu_sys.def,v 1.66 2019/02/16 18:57:21 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -688,7 +688,7 @@ void
process_menu(int num, void *arg)
{
int sel = 0;
- int req;
+ int req, rv;
menu_ent *opt;
menudesc *m;
@@ -754,8 +754,13 @@ process_menu(int num, void *arg)
continue;
if (opt->opt_flags & OPT_ENDWIN)
endwin();
- if (opt->opt_action && (*opt->opt_action)(m, arg))
- break;
+ if (opt->opt_action) {
+ rv = (*opt->opt_action)(m, arg);
+ if (rv == -1)
+ continue;
+ else if (rv != 0)
+ break;
+ }
if (opt->opt_menu != -1) {
if (!(opt->opt_flags & OPT_SUB)) {
Index: src/usr.bin/menuc/menuc.1
diff -u src/usr.bin/menuc/menuc.1:1.34 src/usr.bin/menuc/menuc.1:1.35
--- src/usr.bin/menuc/menuc.1:1.34 Fri Jan 4 15:27:19 2019
+++ src/usr.bin/menuc/menuc.1 Sat Feb 16 18:57:21 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: menuc.1,v 1.34 2019/01/04 15:27:19 martin Exp $
+.\" $NetBSD: menuc.1,v 1.35 2019/02/16 18:57:21 martin Exp $
.\"
.\" Copyright 1997 Piermont Information Systems Inc.
.\" All rights reserved.
@@ -539,6 +539,30 @@ is the text for the exit line of the men
If it's null, string
.Dq Exit
is used.
+.Sh MENU ITEM ACTIONS
+When creating dynamic menus, the programer supplies function pointers
+for the menu items
+.Dv opt_action
+member.
+This functions return one of three possible values:
+.Bl -tag -width "-1" -compact
+.It 0
+process sub menu (if set) and continue with the current (or new) menu
+as usual.
+.It 1
+exit the current menu.
+This is equivalen to specifying
+.Dq exit
+in a non-dynamic menu specification.
+.It -1
+do not handle the current item any further and restart handling the (same)
+menu.
+This return value is used when actions modify the menu definition on the
+fly, e.g. adding or removing additional menu items.
+The action may set
+.Dq cur_sel
+to jump to an arbitrary menu item (in the modified menu).
+.El
.Sh MENU ITEM EXPANSION
With the
.Ic enable expansion