diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-02 09:02:12 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-02 09:02:12 +0000 |
commit | 373aa5232d0043556e802e93d9f70bec70f121c7 (patch) | |
tree | 826a3cea2f1f978a5386dfa3b219f0c60dccae42 /usr.sbin/bsdconfig/share/dialog.subr | |
parent | 5b05f067655217732e94ad77b1c57a3cb7a3945e (diff) | |
download | FreeBSD-src-373aa5232d0043556e802e93d9f70bec70f121c7.zip FreeBSD-src-373aa5232d0043556e802e93d9f70bec70f121c7.tar.gz |
Improve the dialog(1) API in dialog.subr by adding f_dialog_default_store()
and f_dialog_default_fetch(). Operating similar to functions introduced by
SVN r251236 and r251242, these functions operate as a pair for helping track
the default-item data (for the --menu, --checklist, and --radiolist
widgets).
This replaces the direct usage of a global to store the data with an
abstract method for readability and to centralize the code.
Diffstat (limited to 'usr.sbin/bsdconfig/share/dialog.subr')
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 2b65d31..2c81333 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -1757,6 +1757,45 @@ f_dialog_menutag_fetch() return $SUCCESS } +# f_dialog_default_store [-s] $text +# +# Store some text to be used later as the --default-item argument to dialog(1) +# (or Xdialog(1)) for --menu, --checklist, and --radiolist widgets. Retrieve +# the text later with f_dialog_menutag_fetch(). If the first argument is `-s', +# the text is sanitized before being stored. +# +f_dialog_default_store() +{ + local sanitize= + [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s + local text="$1" + + # Sanitize the defaulitem before storing it if desired + [ "$sanitize" ] && f_dialog_data_sanitize text + + setvar DEFAULTITEM_$$ "$text" +} + +# f_dialog_default_fetch [$var_to_set] +# +# Obtain text to be used with the --default-item argument of dialog(1) (or +# Xdialog(1)) (previously stored with f_dialog_default_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_default_fetch() +{ + local __var_to_set="$1" __cp + + debug= f_getvar DEFAULTITEM_$$ "${__var_to_set:-__cp}" # get the data + setvar DEFAULTITEM_$$ "" # scrub memory in case data was sensitive + + # Return the data on standard-out if desired + [ "$__var_to_set" ] || echo "$__cp" + + return $SUCCESS +} + # f_dialog_menutag2item $tag_chosen $tag1 $item1 $tag2 $item2 ... # # To use the `--menu' option of dialog(1) you must pass an ordered list of |