diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-04 03:30:44 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-04 03:30:44 +0000 |
commit | 5bc8f8ca233e4b9a424e65b9803014678682095b (patch) | |
tree | 5d470a5de573a2a5f4cea933a5c7634367aa240e /usr.sbin/bsdconfig/share/dialog.subr | |
parent | 1110d62208360bbc03f7dc79c457de81a9e49f4c (diff) | |
download | FreeBSD-src-5bc8f8ca233e4b9a424e65b9803014678682095b.zip FreeBSD-src-5bc8f8ca233e4b9a424e65b9803014678682095b.tar.gz |
Similar to r251236, r251242, and r251244. Introduce new function-pair to
dialog(1) API in dialog.subr responsible for retrieving menu-choice data
(for the --menu widget).
Add f_dialog_menuitem_store()/f_dialog_menuitem_fetch() for storing and
retrieving the menuitem (not the tag) from a --menu widget result.
The dialog --menu widget returns the `tag' from the tag/item pair of choices
for a menu list. Because the menu list is often local to the function that
is displaying it, the ability to dereference this into the item is not
possible unless you use a global. This changes things so the function (upon
successful return of dialog) dereferences the tag into the item and stores
it for later retrieval using these functions.
NOTE: Tags are dereferenced into items using f_dialog_menutag2item().
Diffstat (limited to 'usr.sbin/bsdconfig/share/dialog.subr')
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 523ef1a..43a78ed 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -1770,6 +1770,44 @@ f_dialog_menutag_fetch() return $SUCCESS } +# f_dialog_menuitem_store [-s] $text +# +# Store the item from a dialog(1) menu (see f_dialog_menutag2item()) to be +# retrieved later by f_dialog_menuitem_fetch(). If the first argument is `-s', +# the text is sanitized before being stored. +# +f_dialog_menuitem_store() +{ + local sanitize= + [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s + local text="$1" + + # Sanitize the menuitem before storing it if desired + [ "$sanitize" ] && f_dialog_data_sanitize text + + setvar DIALOG_MENUITEM_$$ "$text" +} + +# f_dialog_menuitem_fetch [$var_to_set] +# +# Obtain the menuitem chosen by the user from the most recently displayed +# dialog(1) menu (previously stored with f_dialog_menuitem_store() above). If +# $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +f_dialog_menuitem_fetch() +{ + local __var_to_set="$1" __cp + + debug= f_getvar DIALOG_MENUITEM_$$ "${__var_to_set:-__cp}" # get data + setvar DIALOG_MENUITEM_$$ "" # scrub memory in case data was sensitive + + # Return the data on standard-out if desired + [ "$__var_to_set" ] || echo "$__cp" + + return $SUCCESS +} + # f_dialog_default_store [-s] $text # # Store some text to be used later as the --default-item argument to dialog(1) |