Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bsdconfig/share/dialog.subr
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
# | # | ||||
: ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} | : ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} | ||||
############################################################ GLOBALS | ############################################################ GLOBALS | ||||
# | # | ||||
# Default name of dialog(1) utility | # Default name of dialog(1) utility | ||||
# NOTE: This is changed to "Xdialog" by the optional `-X' argument | # NOTE: This is changed to "Xdialog" by the optional `-X' argument | ||||
# TUI_UTLITY is used to allow some bsdinstall to use dialog, delete after the | |||||
# replacement process. | |||||
# | # | ||||
DIALOG="dialog" | # DIALOG="bsddialog" | ||||
DIALOG=${TUI_UTILITY:-bsddialog} | |||||
# | # | ||||
# bsddialog does not provide --keep-tite dialog(1) and Xdialog could use it | |||||
# | |||||
if [ ! $DIALOG = "bsddialog" ]; then | |||||
WITH_KEEP_TITE=1 | |||||
fi | |||||
# | |||||
# Default dialog(1) title and backtitle text | # Default dialog(1) title and backtitle text | ||||
# | # | ||||
DIALOG_TITLE="$pgm" | DIALOG_TITLE="$pgm" | ||||
DIALOG_BACKTITLE="bsdconfig" | DIALOG_BACKTITLE="bsdconfig" | ||||
# | # | ||||
# Settings used while interacting with dialog(1) | # Settings used while interacting with dialog(1) | ||||
# | # | ||||
DIALOG_MENU_TAGS="123456789ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz" | DIALOG_MENU_TAGS="123456789ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz" | ||||
# | # | ||||
# Declare that we are fully-compliant with Xdialog(1) by unset'ing all | # Declare that we are fully-compliant with Xdialog(1) by unset'ing all | ||||
# compatibility settings. | # compatibility settings. | ||||
# | # | ||||
unset XDIALOG_HIGH_DIALOG_COMPAT | unset XDIALOG_HIGH_DIALOG_COMPAT | ||||
unset XDIALOG_FORCE_AUTOSIZE | unset XDIALOG_FORCE_AUTOSIZE | ||||
unset XDIALOG_INFOBOX_TIMEOUT | unset XDIALOG_INFOBOX_TIMEOUT | ||||
# | # | ||||
# Exit codes for [X]dialog(1) | # Exit codes | ||||
# | # | ||||
BSDDIALOG_OK=0 | |||||
BSDDIALOG_CANCEL=1 | |||||
BSDDIALOG_HELP=2 | |||||
BSDDIALOG_EXTRA=3 | |||||
BSDDIALOG_ESC=5 | |||||
BSDDIALOG_ERROR=255 | |||||
DIALOG_OK=${SUCCESS:-0} | DIALOG_OK=${SUCCESS:-0} | ||||
DIALOG_CANCEL=${FAILURE:-1} | DIALOG_CANCEL=${FAILURE:-1} | ||||
DIALOG_HELP=2 | DIALOG_HELP=2 | ||||
DIALOG_EXTRA=3 | DIALOG_EXTRA=3 | ||||
if [ $DIALOG = "bsddialog" ]; then | |||||
DIALOG_ITEM_HELP=${BSDDIALOG_HELP} # unused by bsddialog | |||||
DIALOG_ERROR=${BSDDIALOG_ERROR} | |||||
DIALOG_ESC=${BSDDIALOG_ESC} | |||||
else | |||||
DIALOG_ITEM_HELP=4 | DIALOG_ITEM_HELP=4 | ||||
export DIALOG_ERROR=254 # sh(1) can't handle the default of `-1' | export DIALOG_ERROR=254 # sh(1) can't handle the default of `-1' | ||||
DIALOG_ESC=255 | DIALOG_ESC=255 | ||||
fi | |||||
# | # | ||||
# Default behavior is to call f_dialog_init() automatically when loaded. | # Default behavior is to call f_dialog_init() automatically when loaded. | ||||
# | # | ||||
: ${DIALOG_SELF_INITIALIZE=1} | : ${DIALOG_SELF_INITIALIZE=1} | ||||
# | # | ||||
# Default terminal size (used if/when running without a controlling terminal) | # Default terminal size (used if/when running without a controlling terminal) | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | else | ||||
if __max_size=$( $DIALOG --print-maxsize \ | if __max_size=$( $DIALOG --print-maxsize \ | ||||
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) | 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) | ||||
then | then | ||||
f_dprintf "$funcname: %s --print-maxsize = [%s]" \ | f_dprintf "$funcname: %s --print-maxsize = [%s]" \ | ||||
"$DIALOG" "$__max_size" | "$DIALOG" "$__max_size" | ||||
# usually "MaxSize: 24, 80" | # usually "MaxSize: 24, 80" | ||||
__max_size="${__max_size#*: }" | __max_size="${__max_size#*: }" | ||||
f_replaceall "$__max_size" "," "" __max_size | f_replaceall "$__max_size" "," "" __max_size | ||||
if [ $DIALOG = "bsddialog" ] ; then | |||||
f_replaceall "$__max_size" "(" "" __max_size | |||||
f_replaceall "$__max_size" "-" "" __max_size | |||||
f_replaceall "$__max_size" ")" "" __max_size | |||||
fi | |||||
else | else | ||||
f_eval_catch -dk __max_size $funcname stty \ | f_eval_catch -dk __max_size $funcname stty \ | ||||
'stty size' || __max_size= | 'stty size' || __max_size= | ||||
# usually "24 80" | # usually "24 80" | ||||
fi | fi | ||||
: ${__max_size:=$DEFAULT_TERMINAL_SIZE} | : ${__max_size:=$DEFAULT_TERMINAL_SIZE} | ||||
fi | fi | ||||
if [ "$__var_height" ]; then | if [ "$__var_height" ]; then | ||||
▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | |||||
f_dialog_menu_size() | f_dialog_menu_size() | ||||
{ | { | ||||
local __constrain=1 | local __constrain=1 | ||||
[ "$1" = "-n" ] && __constrain= && shift 1 # -n | [ "$1" = "-n" ] && __constrain= && shift 1 # -n | ||||
local __var_height="$1" __var_width="$2" __var_rows="$3" | local __var_height="$1" __var_width="$2" __var_rows="$3" | ||||
local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | ||||
shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | ||||
if [ "$DIALOG" = "bsddialog" ]; then | |||||
# libbsddialog handles autosize with a prompt | |||||
setvar "$__var_height" 0 | |||||
setvar "$__var_width" 0 | |||||
setvar "$__var_rows" 0 | |||||
return | |||||
fi | |||||
# Return unless at least one size aspect has been requested | # Return unless at least one size aspect has been requested | ||||
[ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | ||||
return $FAILURE | return $FAILURE | ||||
# Calculate height/width of infobox (adjusted/constrained below) | # Calculate height/width of infobox (adjusted/constrained below) | ||||
# NOTE: Function name appended to prevent __var_{height,width} values | # NOTE: Function name appended to prevent __var_{height,width} values | ||||
# from becoming local (and thus preventing setvar from working). | # from becoming local (and thus preventing setvar from working). | ||||
local __height_menu_size __width_menu_size | local __height_menu_size __width_menu_size | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
f_dialog_menu_with_help_size() | f_dialog_menu_with_help_size() | ||||
{ | { | ||||
local __constrain=1 | local __constrain=1 | ||||
[ "$1" = "-n" ] && __constrain= && shift 1 # -n | [ "$1" = "-n" ] && __constrain= && shift 1 # -n | ||||
local __var_height="$1" __var_width="$2" __var_rows="$3" | local __var_height="$1" __var_width="$2" __var_rows="$3" | ||||
local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | ||||
shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | ||||
if [ "$DIALOG" = "bsddialog" ]; then | |||||
# libbsddialog handles autosize with a prompt | |||||
setvar "$__var_height" 0 | |||||
setvar "$__var_width" 0 | |||||
setvar "$__var_rows" 0 | |||||
return | |||||
fi | |||||
# Return unless at least one size aspect has been requested | # Return unless at least one size aspect has been requested | ||||
[ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | ||||
return $FAILURE | return $FAILURE | ||||
# Calculate height/width of infobox (adjusted/constrained below) | # Calculate height/width of infobox (adjusted/constrained below) | ||||
# NOTE: Function name appended to prevent __var_{height,width} values | # NOTE: Function name appended to prevent __var_{height,width} values | ||||
# from becoming local (and thus preventing setvar from working). | # from becoming local (and thus preventing setvar from working). | ||||
local __height_menu_with_help_size __width_menu_with_help_size | local __height_menu_with_help_size __width_menu_with_help_size | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
f_dialog_radiolist_size() | f_dialog_radiolist_size() | ||||
{ | { | ||||
local __constrain=1 | local __constrain=1 | ||||
[ "$1" = "-n" ] && __constrain= && shift 1 # -n | [ "$1" = "-n" ] && __constrain= && shift 1 # -n | ||||
local __var_height="$1" __var_width="$2" __var_rows="$3" | local __var_height="$1" __var_width="$2" __var_rows="$3" | ||||
local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | ||||
shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | ||||
if [ "$DIALOG" = "bsddialog" ]; then | |||||
# libbsddialog handles autosize with a prompt | |||||
setvar "$__var_height" 0 | |||||
setvar "$__var_width" 0 | |||||
setvar "$__var_rows" 0 | |||||
return | |||||
fi | |||||
# Return unless at least one size aspect has been requested | # Return unless at least one size aspect has been requested | ||||
[ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | ||||
return $FAILURE | return $FAILURE | ||||
# Calculate height/width of infobox (adjusted/constrained below) | # Calculate height/width of infobox (adjusted/constrained below) | ||||
# NOTE: Function name appended to prevent __var_{height,width} values | # NOTE: Function name appended to prevent __var_{height,width} values | ||||
# from becoming local (and thus preventing setvar from working). | # from becoming local (and thus preventing setvar from working). | ||||
local __height_rlist_size __width_rlist_size | local __height_rlist_size __width_rlist_size | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
f_dialog_radiolist_with_help_size() | f_dialog_radiolist_with_help_size() | ||||
{ | { | ||||
local __constrain=1 | local __constrain=1 | ||||
[ "$1" = "-n" ] && __constrain= && shift 1 # -n | [ "$1" = "-n" ] && __constrain= && shift 1 # -n | ||||
local __var_height="$1" __var_width="$2" __var_rows="$3" | local __var_height="$1" __var_width="$2" __var_rows="$3" | ||||
local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" | ||||
shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline | ||||
if [ "$DIALOG" = "bsddialog" ]; then | |||||
# libbsddialog handles autosize with a prompt | |||||
setvar "$__var_height" 0 | |||||
setvar "$__var_width" 0 | |||||
setvar "$__var_rows" 0 | |||||
return | |||||
fi | |||||
# Return unless at least one size aspect has been requested | # Return unless at least one size aspect has been requested | ||||
[ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || | ||||
return $FAILURE | return $FAILURE | ||||
# Calculate height/width of infobox (adjusted/constrained below) | # Calculate height/width of infobox (adjusted/constrained below) | ||||
# NOTE: Function name appended to prevent __var_{height,width} values | # NOTE: Function name appended to prevent __var_{height,width} values | ||||
# from becoming local (and thus preventing setvar from working). | # from becoming local (and thus preventing setvar from working). | ||||
local __height_rlist_with_help_size __width_rlist_with_help_size | local __height_rlist_with_help_size __width_rlist_with_help_size | ||||
▲ Show 20 Lines • Show All 650 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
local sanitize= | local sanitize= | ||||
[ "$1" = "-s" ] && sanitize=1 && shift 1 # -s | [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s | ||||
local text="$1" | local text="$1" | ||||
# Sanitize the menutag before storing it if desired | # Sanitize the menutag before storing it if desired | ||||
[ "$sanitize" ] && f_dialog_data_sanitize text | [ "$sanitize" ] && f_dialog_data_sanitize text | ||||
# bsddialog quotes an item name if contains a space | |||||
if [ $DIALOG = "bsddialog" ]; then | |||||
# Actually only the first and last quote have to be removed | |||||
f_replaceall "$text" '"' "" text | |||||
fi | |||||
setvar DIALOG_MENU_$$ "$text" | setvar DIALOG_MENU_$$ "$text" | ||||
} | } | ||||
# f_dialog_menutag_fetch [$var_to_set] | # f_dialog_menutag_fetch [$var_to_set] | ||||
# | # | ||||
# Obtain the menutag chosen by the user from the most recently displayed | # Obtain the menutag chosen by the user from the most recently displayed | ||||
# dialog(1) menu (previously stored with f_dialog_menutag_store() above). If | # dialog(1) menu (previously stored with f_dialog_menutag_store() above). If | ||||
# $var_to_set is NULL or missing, output is printed to stdout (which is less | # $var_to_set is NULL or missing, output is printed to stdout (which is less | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | f_dialog_init() | ||||
[ "$USE_XDIALOG" ] && DIALOG=Xdialog USE_DIALOG= | [ "$USE_XDIALOG" ] && DIALOG=Xdialog USE_DIALOG= | ||||
# | # | ||||
# Sanity check, or die gracefully | # Sanity check, or die gracefully | ||||
# | # | ||||
if ! f_have $DIALOG; then | if ! f_have $DIALOG; then | ||||
unset USE_XDIALOG | unset USE_XDIALOG | ||||
local failed_dialog="$DIALOG" | local failed_dialog="$DIALOG" | ||||
DIALOG=dialog | #DIALOG=bsddialog | ||||
DIALOG=${TUI_UTILITY:-bsddialog} | |||||
f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$failed_dialog" | f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$failed_dialog" | ||||
fi | fi | ||||
# | # | ||||
# Read ~/.dialogrc (unless using Xdialog(1)) for properties | # Read ~/.dialogrc (unless using Xdialog(1)) for properties | ||||
# | # | ||||
if [ -f ~/.dialogrc -a ! "$USE_XDIALOG" ]; then | if [ -f ~/.dialogrc -a ! "$USE_XDIALOG" ]; then | ||||
eval "$( | eval "$( | ||||
Show All 15 Lines | f_dialog_init() | ||||
# | # | ||||
if [ "$USE_XDIALOG" ] && | if [ "$USE_XDIALOG" ] && | ||||
[ "$( id -u )" = "0" ] && | [ "$( id -u )" = "0" ] && | ||||
[ "$SUDO_USER" -a "$DISPLAY" ] | [ "$SUDO_USER" -a "$DISPLAY" ] | ||||
then | then | ||||
if ! f_have xauth; then | if ! f_have xauth; then | ||||
# Die gracefully, as we [likely] can't use Xdialog(1) | # Die gracefully, as we [likely] can't use Xdialog(1) | ||||
unset USE_XDIALOG | unset USE_XDIALOG | ||||
DIALOG=dialog | #DIALOG=bsddialog | ||||
DIALOG=${TUI_UTILITY:-bsddialog} | |||||
f_die 1 "$msg_no_such_file_or_directory" "$pgm" "xauth" | f_die 1 "$msg_no_such_file_or_directory" "$pgm" "xauth" | ||||
fi | fi | ||||
HOSTNAME=$( hostname ) | HOSTNAME=$( hostname ) | ||||
local displaynum="${DISPLAY#*:}" | local displaynum="${DISPLAY#*:}" | ||||
eval xauth -if \~$SUDO_USER/.Xauthority extract - \ | eval xauth -if \~$SUDO_USER/.Xauthority extract - \ | ||||
\"\$HOSTNAME/unix:\$displaynum\" \ | \"\$HOSTNAME/unix:\$displaynum\" \ | ||||
\"\$HOSTNAME:\$displaynum\" | sudo sh -c 'xauth -ivf \ | \"\$HOSTNAME:\$displaynum\" | sudo sh -c 'xauth -ivf \ | ||||
~root/.Xauthority merge - > /dev/null 2>&1' | ~root/.Xauthority merge - > /dev/null 2>&1' | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |